From 19a44545999e323bd7475b902531ab99d2f19002 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 27 Nov 2025 19:32:22 +0100 Subject: [PATCH 1/4] Cleanup: remove unnecessary keypress Seems to be a copy/paste error from another test. --- pkg/integration/tests/tag/delete_local_and_remote.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/integration/tests/tag/delete_local_and_remote.go b/pkg/integration/tests/tag/delete_local_and_remote.go index 35b9bc25d..4e9917b13 100644 --- a/pkg/integration/tests/tag/delete_local_and_remote.go +++ b/pkg/integration/tests/tag/delete_local_and_remote.go @@ -67,7 +67,6 @@ var DeleteLocalAndRemote = NewIntegrationTest(NewIntegrationTestArgs{ Confirm() }). IsEmpty(). - Press(keys.Universal.New). Tap(func() { t.Shell().AssertRemoteTagNotFound("origin", "new-tag") }) From 4d4b143cc783dd79629af30650c9de54a4cb2835 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 27 Nov 2025 19:44:26 +0100 Subject: [PATCH 2/4] Add tests demonstrating the problem Trying to delete a remote tag when a remote branch with the same name exists results in an error, and vice versa. --- ...e_branch_when_tag_with_same_name_exists.go | 54 +++++++++++++++++ ...e_tag_when_branch_with_same_name_exists.go | 58 +++++++++++++++++++ pkg/integration/tests/test_list.go | 2 + 3 files changed, 114 insertions(+) create mode 100644 pkg/integration/tests/branch/delete_remote_branch_when_tag_with_same_name_exists.go create mode 100644 pkg/integration/tests/tag/delete_remote_tag_when_branch_with_same_name_exists.go diff --git a/pkg/integration/tests/branch/delete_remote_branch_when_tag_with_same_name_exists.go b/pkg/integration/tests/branch/delete_remote_branch_when_tag_with_same_name_exists.go new file mode 100644 index 000000000..5f4171f7d --- /dev/null +++ b/pkg/integration/tests/branch/delete_remote_branch_when_tag_with_same_name_exists.go @@ -0,0 +1,54 @@ +package branch + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var DeleteRemoteBranchWhenTagWithSameNameExists = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Delete a remote branch when a remote tag with the same name exists", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("initial commit") + shell.CloneIntoRemote("origin") + shell.CreateLightweightTag("xyz", "HEAD") + shell.PushBranch("origin", "HEAD:refs/tags/xyz") // abusing PushBranch to push a tag + shell.PushBranch("origin", "HEAD:refs/heads/xyz") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Remotes(). + Focus(). + Lines( + Contains("origin").IsSelected(), + ). + PressEnter() + + t.Views().RemoteBranches(). + IsFocused(). + Lines( + Contains("master").IsSelected(), + Contains("xyz"), + ). + SelectNextItem(). + Press(keys.Universal.Remove) + + t.ExpectPopup(). + Confirmation(). + Title(Equals("Delete branch 'xyz'?")). + Content(Equals("Are you sure you want to delete the remote branch 'xyz' from 'origin'?")). + Confirm() + + /* EXPECTED: + t.Views().RemoteBranches(). + Lines( + Contains("master").IsSelected(), + ) + ACTUAL: */ + t.ExpectPopup().Alert(). + Title(Equals("Error")). + Content(Contains("error: dst refspec xyz matches more than one")). + Confirm() + }, +}) diff --git a/pkg/integration/tests/tag/delete_remote_tag_when_branch_with_same_name_exists.go b/pkg/integration/tests/tag/delete_remote_tag_when_branch_with_same_name_exists.go new file mode 100644 index 000000000..2c3ff828e --- /dev/null +++ b/pkg/integration/tests/tag/delete_remote_tag_when_branch_with_same_name_exists.go @@ -0,0 +1,58 @@ +package tag + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var DeleteRemoteTagWhenBranchWithSameNameExists = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Delete a remote tag when a remote branch with the same name exists", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("initial commit") + shell.CloneIntoRemote("origin") + shell.CreateLightweightTag("xyz", "HEAD") + shell.PushBranch("origin", "HEAD:refs/tags/xyz") // abusing PushBranch to push a tag + shell.PushBranch("origin", "HEAD:refs/heads/xyz") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Tags(). + Focus(). + Lines( + Contains("xyz").IsSelected(), + ). + Press(keys.Universal.Remove) + + t.ExpectPopup(). + Menu(). + Title(Equals("Delete tag 'xyz'?")). + Select(Contains("Delete remote tag")). + Confirm() + + t.ExpectPopup().Prompt(). + Title(Equals("Remote from which to remove tag 'xyz':")). + InitialText(Equals("origin")). + SuggestionLines( + Contains("origin"), + ). + Confirm() + + t.ExpectPopup(). + Confirmation(). + Title(Equals("Delete tag 'xyz'?")). + Content(Equals("Are you sure you want to delete the remote tag 'xyz' from 'origin'?")). + Confirm() + + /* EXPECTED: + t.ExpectToast(Equals("Remote tag deleted")) + + t.Shell().AssertRemoteTagNotFound("origin", "xyz") + ACTUAL: */ + t.ExpectPopup().Alert(). + Title(Equals("Error")). + Content(Contains("error: dst refspec xyz matches more than one")). + Confirm() + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index d619ccc75..14072d866 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -45,6 +45,7 @@ var tests = []*components.IntegrationTest{ branch.CreateTag, branch.Delete, branch.DeleteMultiple, + branch.DeleteRemoteBranchWhenTagWithSameNameExists, branch.DeleteRemoteBranchWithCredentialPrompt, branch.DeleteRemoteBranchWithDifferentName, branch.DeleteWhileFiltering, @@ -430,6 +431,7 @@ var tests = []*components.IntegrationTest{ tag.CrudAnnotated, tag.CrudLightweight, tag.DeleteLocalAndRemote, + tag.DeleteRemoteTagWhenBranchWithSameNameExists, tag.ForceTagAnnotated, tag.ForceTagLightweight, tag.Reset, From 7809823064f41493ebe03e56ba79d08bf185cc71 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 27 Nov 2025 19:48:18 +0100 Subject: [PATCH 3/4] Fix deleting a remote branch when a remote tag with the same name exists --- pkg/commands/git_commands/remote.go | 3 ++- .../delete_remote_branch_when_tag_with_same_name_exists.go | 6 ------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/commands/git_commands/remote.go b/pkg/commands/git_commands/remote.go index ca3610679..650a91c81 100644 --- a/pkg/commands/git_commands/remote.go +++ b/pkg/commands/git_commands/remote.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/jesseduffield/gocui" + "github.com/samber/lo" ) type RemoteCommands struct { @@ -52,7 +53,7 @@ func (self *RemoteCommands) UpdateRemoteUrl(remoteName string, updatedUrl string func (self *RemoteCommands) DeleteRemoteBranch(task gocui.Task, remoteName string, branchNames []string) error { cmdArgs := NewGitCmd("push"). Arg(remoteName, "--delete"). - Arg(branchNames...). + Arg(lo.Map(branchNames, func(b string, _ int) string { return "refs/heads/" + b })...). ToArgv() return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run() diff --git a/pkg/integration/tests/branch/delete_remote_branch_when_tag_with_same_name_exists.go b/pkg/integration/tests/branch/delete_remote_branch_when_tag_with_same_name_exists.go index 5f4171f7d..3255fac53 100644 --- a/pkg/integration/tests/branch/delete_remote_branch_when_tag_with_same_name_exists.go +++ b/pkg/integration/tests/branch/delete_remote_branch_when_tag_with_same_name_exists.go @@ -40,15 +40,9 @@ var DeleteRemoteBranchWhenTagWithSameNameExists = NewIntegrationTest(NewIntegrat Content(Equals("Are you sure you want to delete the remote branch 'xyz' from 'origin'?")). Confirm() - /* EXPECTED: t.Views().RemoteBranches(). Lines( Contains("master").IsSelected(), ) - ACTUAL: */ - t.ExpectPopup().Alert(). - Title(Equals("Error")). - Content(Contains("error: dst refspec xyz matches more than one")). - Confirm() }, }) From 11a6a73be5118f635e5bcba6baf6929e2884a0cd Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 27 Nov 2025 19:52:18 +0100 Subject: [PATCH 4/4] Fix deleting a remote tag when a remote branch with the same name exists --- pkg/commands/git_commands/remote.go | 2 +- .../delete_remote_tag_when_branch_with_same_name_exists.go | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/pkg/commands/git_commands/remote.go b/pkg/commands/git_commands/remote.go index 650a91c81..82a9d6a46 100644 --- a/pkg/commands/git_commands/remote.go +++ b/pkg/commands/git_commands/remote.go @@ -61,7 +61,7 @@ func (self *RemoteCommands) DeleteRemoteBranch(task gocui.Task, remoteName strin func (self *RemoteCommands) DeleteRemoteTag(task gocui.Task, remoteName string, tagName string) error { cmdArgs := NewGitCmd("push"). - Arg(remoteName, "--delete", tagName). + Arg(remoteName, "--delete", "refs/tags/"+tagName). ToArgv() return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run() diff --git a/pkg/integration/tests/tag/delete_remote_tag_when_branch_with_same_name_exists.go b/pkg/integration/tests/tag/delete_remote_tag_when_branch_with_same_name_exists.go index 2c3ff828e..6f2a03400 100644 --- a/pkg/integration/tests/tag/delete_remote_tag_when_branch_with_same_name_exists.go +++ b/pkg/integration/tests/tag/delete_remote_tag_when_branch_with_same_name_exists.go @@ -45,14 +45,8 @@ var DeleteRemoteTagWhenBranchWithSameNameExists = NewIntegrationTest(NewIntegrat Content(Equals("Are you sure you want to delete the remote tag 'xyz' from 'origin'?")). Confirm() - /* EXPECTED: t.ExpectToast(Equals("Remote tag deleted")) t.Shell().AssertRemoteTagNotFound("origin", "xyz") - ACTUAL: */ - t.ExpectPopup().Alert(). - Title(Equals("Error")). - Content(Contains("error: dst refspec xyz matches more than one")). - Confirm() }, })