From 4d4b143cc783dd79629af30650c9de54a4cb2835 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 27 Nov 2025 19:44:26 +0100 Subject: [PATCH] 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,