From 0a139b6891ef536cc1b7b080081ff39dc22c8b57 Mon Sep 17 00:00:00 2001 From: Gustav Utterheim Date: Sat, 25 Nov 2023 12:45:26 +0100 Subject: [PATCH] fix: cmdgit should match full branch name --- internal/git/cmdgit/git.go | 2 +- tests/table_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/internal/git/cmdgit/git.go b/internal/git/cmdgit/git.go index a4bbd0cd..1a84cae1 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("refs/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..51b43916 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-longer", false) + assert.Equal(t, "i like apple", readTestFile(t, vcMock.Repositories[0].Path)) + }, + }, + { name: "reviewers", vcCreate: func(t *testing.T) *vcmock.VersionController {