Skip to content

Commit e3ea666

Browse files
authored
Fix deleting a remote tag when a remote branch with the same name exists, or vice versa (#5075)
Nothing to add to the PR title here. Fixes #5072.
2 parents b57be9e + 11a6a73 commit e3ea666

File tree

5 files changed

+105
-3
lines changed

5 files changed

+105
-3
lines changed

pkg/commands/git_commands/remote.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/jesseduffield/gocui"
8+
"github.com/samber/lo"
89
)
910

1011
type RemoteCommands struct {
@@ -52,15 +53,15 @@ func (self *RemoteCommands) UpdateRemoteUrl(remoteName string, updatedUrl string
5253
func (self *RemoteCommands) DeleteRemoteBranch(task gocui.Task, remoteName string, branchNames []string) error {
5354
cmdArgs := NewGitCmd("push").
5455
Arg(remoteName, "--delete").
55-
Arg(branchNames...).
56+
Arg(lo.Map(branchNames, func(b string, _ int) string { return "refs/heads/" + b })...).
5657
ToArgv()
5758

5859
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run()
5960
}
6061

6162
func (self *RemoteCommands) DeleteRemoteTag(task gocui.Task, remoteName string, tagName string) error {
6263
cmdArgs := NewGitCmd("push").
63-
Arg(remoteName, "--delete", tagName).
64+
Arg(remoteName, "--delete", "refs/tags/"+tagName).
6465
ToArgv()
6566

6667
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run()
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package branch
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var DeleteRemoteBranchWhenTagWithSameNameExists = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Delete a remote branch when a remote tag with the same name exists",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.EmptyCommit("initial commit")
15+
shell.CloneIntoRemote("origin")
16+
shell.CreateLightweightTag("xyz", "HEAD")
17+
shell.PushBranch("origin", "HEAD:refs/tags/xyz") // abusing PushBranch to push a tag
18+
shell.PushBranch("origin", "HEAD:refs/heads/xyz")
19+
},
20+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
21+
t.Views().Remotes().
22+
Focus().
23+
Lines(
24+
Contains("origin").IsSelected(),
25+
).
26+
PressEnter()
27+
28+
t.Views().RemoteBranches().
29+
IsFocused().
30+
Lines(
31+
Contains("master").IsSelected(),
32+
Contains("xyz"),
33+
).
34+
SelectNextItem().
35+
Press(keys.Universal.Remove)
36+
37+
t.ExpectPopup().
38+
Confirmation().
39+
Title(Equals("Delete branch 'xyz'?")).
40+
Content(Equals("Are you sure you want to delete the remote branch 'xyz' from 'origin'?")).
41+
Confirm()
42+
43+
t.Views().RemoteBranches().
44+
Lines(
45+
Contains("master").IsSelected(),
46+
)
47+
},
48+
})

pkg/integration/tests/tag/delete_local_and_remote.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ var DeleteLocalAndRemote = NewIntegrationTest(NewIntegrationTestArgs{
6767
Confirm()
6868
}).
6969
IsEmpty().
70-
Press(keys.Universal.New).
7170
Tap(func() {
7271
t.Shell().AssertRemoteTagNotFound("origin", "new-tag")
7372
})
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package tag
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var DeleteRemoteTagWhenBranchWithSameNameExists = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Delete a remote tag when a remote branch with the same name exists",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.EmptyCommit("initial commit")
15+
shell.CloneIntoRemote("origin")
16+
shell.CreateLightweightTag("xyz", "HEAD")
17+
shell.PushBranch("origin", "HEAD:refs/tags/xyz") // abusing PushBranch to push a tag
18+
shell.PushBranch("origin", "HEAD:refs/heads/xyz")
19+
},
20+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
21+
t.Views().Tags().
22+
Focus().
23+
Lines(
24+
Contains("xyz").IsSelected(),
25+
).
26+
Press(keys.Universal.Remove)
27+
28+
t.ExpectPopup().
29+
Menu().
30+
Title(Equals("Delete tag 'xyz'?")).
31+
Select(Contains("Delete remote tag")).
32+
Confirm()
33+
34+
t.ExpectPopup().Prompt().
35+
Title(Equals("Remote from which to remove tag 'xyz':")).
36+
InitialText(Equals("origin")).
37+
SuggestionLines(
38+
Contains("origin"),
39+
).
40+
Confirm()
41+
42+
t.ExpectPopup().
43+
Confirmation().
44+
Title(Equals("Delete tag 'xyz'?")).
45+
Content(Equals("Are you sure you want to delete the remote tag 'xyz' from 'origin'?")).
46+
Confirm()
47+
48+
t.ExpectToast(Equals("Remote tag deleted"))
49+
50+
t.Shell().AssertRemoteTagNotFound("origin", "xyz")
51+
},
52+
})

pkg/integration/tests/test_list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var tests = []*components.IntegrationTest{
4545
branch.CreateTag,
4646
branch.Delete,
4747
branch.DeleteMultiple,
48+
branch.DeleteRemoteBranchWhenTagWithSameNameExists,
4849
branch.DeleteRemoteBranchWithCredentialPrompt,
4950
branch.DeleteRemoteBranchWithDifferentName,
5051
branch.DeleteWhileFiltering,
@@ -430,6 +431,7 @@ var tests = []*components.IntegrationTest{
430431
tag.CrudAnnotated,
431432
tag.CrudLightweight,
432433
tag.DeleteLocalAndRemote,
434+
tag.DeleteRemoteTagWhenBranchWithSameNameExists,
433435
tag.ForceTagAnnotated,
434436
tag.ForceTagLightweight,
435437
tag.Reset,

0 commit comments

Comments
 (0)