Skip to content

Commit

Permalink
fix: cmdgit should match full branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavkj committed Nov 25, 2023
1 parent 391bece commit 6b65c33
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/git/cmdgit/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (g *Git) BranchExist(remoteName, branchName string) (bool, error) {
if err != nil {
return false, err
}
return strings.Contains(stdOut, fmt.Sprintf("refs/heads/%s", branchName)), nil
return strings.Contains(stdOut, fmt.Sprintf("refs/heads/%s\n", branchName)), nil
}

// Push the committed changes to the remote
Expand Down
34 changes: 34 additions & 0 deletions tests/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,40 @@ func TestTable(t *testing.T) {
},
},

{
name: "existing branch with matching start",
vcCreate: func(t *testing.T) *vcmock.VersionController {
repo := createRepo(t, "owner", "should-change", "i like apples")
changeBranch(t, repo.Path, "custom-branch-name-but-with-different-ending", true)
changeTestFile(t, repo.Path, "i like apple", "test change")
changeBranch(t, repo.Path, "master", false)
return &vcmock.VersionController{
Repositories: []vcmock.Repository{
repo,
},
}
},
args: []string{
"run",
"--author-name", "Test Author",
"--author-email", "[email protected]",
"--branch", "custom-branch-name",
"-m", "custom message",
changerBinaryPath,
},
verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) {
require.Len(t, vcMock.PullRequests, 1)
assert.Equal(t, "custom-branch-name", vcMock.PullRequests[0].Head)
assert.Equal(t, "custom message", vcMock.PullRequests[0].Title)

changeBranch(t, vcMock.Repositories[0].Path, "custom-branch-name", false)
assert.Equal(t, "i like bananas", readTestFile(t, vcMock.Repositories[0].Path))

changeBranch(t, vcMock.Repositories[0].Path, "custom-branch-name-but-with-different-ending", false)
assert.Equal(t, "i like apple", readTestFile(t, vcMock.Repositories[0].Path))
},
},

{
name: "reviewers",
vcCreate: func(t *testing.T) *vcmock.VersionController {
Expand Down

0 comments on commit 6b65c33

Please sign in to comment.