diff --git a/pkg/commands/git_commands/remote.go b/pkg/commands/git_commands/remote.go index ca361067976..82a9d6a46bc 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() @@ -60,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/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 00000000000..3255fac5346 --- /dev/null +++ b/pkg/integration/tests/branch/delete_remote_branch_when_tag_with_same_name_exists.go @@ -0,0 +1,48 @@ +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() + + t.Views().RemoteBranches(). + Lines( + Contains("master").IsSelected(), + ) + }, +}) diff --git a/pkg/integration/tests/tag/delete_local_and_remote.go b/pkg/integration/tests/tag/delete_local_and_remote.go index 35b9bc25de1..4e9917b13e0 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") }) 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 00000000000..6f2a034006d --- /dev/null +++ b/pkg/integration/tests/tag/delete_remote_tag_when_branch_with_same_name_exists.go @@ -0,0 +1,52 @@ +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() + + t.ExpectToast(Equals("Remote tag deleted")) + + t.Shell().AssertRemoteTagNotFound("origin", "xyz") + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index d619ccc75b2..14072d866db 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,