diff --git a/internal/git/cmdgit/git.go b/internal/git/cmdgit/git.go index a4bbd0cd..18151701 100644 --- a/internal/git/cmdgit/git.go +++ b/internal/git/cmdgit/git.go @@ -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("\trefs/heads/%s\n", branchName)), nil } // Push the committed changes to the remote diff --git a/tests/table_test.go b/tests/table_test.go index d6462911..975b0936 100644 --- a/tests/table_test.go +++ b/tests/table_test.go @@ -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", "test@example.com", + "--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 {