Skip to content

Commit

Permalink
Add option to delete local and remote tag
Browse files Browse the repository at this point in the history
  • Loading branch information
AnvarU committed Jan 27, 2025
1 parent 40d6800 commit c2d3d84
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 1 deletion.
61 changes: 61 additions & 0 deletions pkg/gui/controllers/tags_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,59 @@ func (self *TagsController) remoteDelete(tag *models.Tag) error {
return nil
}

func (self *TagsController) localAndRemoteDelete(tag *models.Tag) error {
title := utils.ResolvePlaceholderString(
self.c.Tr.SelectRemoteTagUpstream,
map[string]string{
"tagName": tag.Name,
},
)

self.c.Prompt(types.PromptOpts{
Title: title,
InitialContent: "origin",
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRemoteSuggestionsFunc(),
HandleConfirm: func(upstream string) error {
confirmTitle := utils.ResolvePlaceholderString(
self.c.Tr.DeleteTagTitle,
map[string]string{
"tagName": tag.Name,
},
)
confirmPrompt := utils.ResolvePlaceholderString(
self.c.Tr.DeleteLocalAndRemoteTagPrompt,
map[string]string{
"tagName": tag.Name,
"upstream": upstream,
},
)

self.c.Confirm(types.ConfirmOpts{
Title: confirmTitle,
Prompt: confirmPrompt,
HandleConfirm: func() error {
return self.c.WithInlineStatus(tag, types.ItemOperationDeleting, context.TAGS_CONTEXT_KEY, func(task gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.DeleteRemoteTag)
if err := self.c.Git().Remote.DeleteRemoteTag(task, upstream, tag.Name); err != nil {
return err
}

self.c.LogAction(self.c.Tr.Actions.DeleteLocalTag)
if err := self.c.Git().Tag.LocalDelete(tag.Name); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS, types.TAGS}})
})
},
})

return nil
},
})

return nil
}

func (self *TagsController) delete(tag *models.Tag) error {
menuTitle := utils.ResolvePlaceholderString(
self.c.Tr.DeleteTagTitle,
Expand All @@ -201,6 +254,14 @@ func (self *TagsController) delete(tag *models.Tag) error {
return self.remoteDelete(tag)
},
},
{
Label: self.c.Tr.DeleteLocalAndRemoteTag,
Key: 'b',
OpensMenu: true,
OnPress: func() error {
return self.localAndRemoteDelete(tag)
},
},
}

return self.c.Menu(types.CreateMenuOptions{
Expand Down
4 changes: 4 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,10 @@ type TranslationSet struct {
DeleteTagTitle string
DeleteLocalTag string
DeleteRemoteTag string
DeleteLocalAndRemoteTag string
SelectRemoteTagUpstream string
DeleteRemoteTagPrompt string
DeleteLocalAndRemoteTagPrompt string
RemoteTagDeletedMessage string
PushTagTitle string
PushTag string
Expand Down Expand Up @@ -1534,9 +1536,11 @@ func EnglishTranslationSet() *TranslationSet {
DeleteTagTitle: "Delete tag '{{.tagName}}'?",
DeleteLocalTag: "Delete local tag",
DeleteRemoteTag: "Delete remote tag",
DeleteLocalAndRemoteTag: "Delete local and remote tag",
RemoteTagDeletedMessage: "Remote tag deleted",
SelectRemoteTagUpstream: "Remote from which to remove tag '{{.tagName}}':",
DeleteRemoteTagPrompt: "Are you sure you want to delete the remote tag '{{.tagName}}' from '{{.upstream}}'?",
DeleteLocalAndRemoteTagPrompt: "Are you sure you want to delete both '{{.tagName}}' from your machine and from '{{.upstream}}'?",
PushTagTitle: "Remote to push tag '{{.tagName}}' to:",
// Using 'push tag' rather than just 'push' to disambiguate from a global push
PushTag: "Push tag",
Expand Down
63 changes: 62 additions & 1 deletion pkg/integration/tests/tag/crud_annotated.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,68 @@ var CrudAnnotated = NewIntegrationTest(NewIntegrationTestArgs{
// confirm content is cleared on next tag create
t.ExpectPopup().CommitMessagePanel().
Title(Equals("Tag name")).
InitialText(Equals(""))
InitialText(Equals("")).
Close()
}).

// Delete both local and remote tag new-tag-2

Press(keys.Universal.New).
Tap(func() {
t.ExpectPopup().CommitMessagePanel().
Title(Equals("Tag name")).
Type("new-tag-2").
SwitchToDescription().
Title(Equals("Tag description")).
Type("message 2").
SwitchToSummary().
Confirm()
}).
Lines(
MatchesRegexp(`new-tag-2.*message 2`).IsSelected(),
).
Press(keys.Universal.Push).
Tap(func() {
t.ExpectPopup().Prompt().
Title(Equals("Remote to push tag 'new-tag-2' to:")).
InitialText(Equals("origin")).
SuggestionLines(
Contains("origin"),
).
Confirm()
}).
Press(keys.Universal.Remove).
Tap(func() {
t.ExpectPopup().
Menu().
Title(Equals("Delete tag 'new-tag-2'?")).
Select(Contains("Delete local and remote tag")).
Confirm()
}).
Tap(func() {
t.ExpectPopup().Prompt().
Title(Equals("Remote from which to remove tag 'new-tag-2':")).
InitialText(Equals("origin")).
SuggestionLines(
Contains("origin"),
).
Confirm()
}).
Tap(func() {
t.ExpectPopup().
Confirmation().
Title(Equals("Delete tag 'new-tag-2'?")).
Content(Equals("Are you sure you want to delete both 'new-tag-2' from your machine and from 'origin'?")).
Confirm()
}).
IsEmpty().
Press(keys.Universal.New).
Tap(func() {
// confirm content is cleared on next tag create
t.ExpectPopup().CommitMessagePanel().
Title(Equals("Tag name")).
InitialText(Equals("")).
Close()
})
},
})
57 changes: 57 additions & 0 deletions pkg/integration/tests/tag/crud_lightweight.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,63 @@ var CrudLightweight = NewIntegrationTest(NewIntegrationTestArgs{
Select(Contains("Delete local tag")).
Confirm()
}).
IsEmpty().

// Delete both local and remote tag new-tag-2

Press(keys.Universal.New).
Tap(func() {
t.ExpectPopup().CommitMessagePanel().
Title(Equals("Tag name")).
Type("new-tag-2").
Confirm()
}).
Lines(
MatchesRegexp(`new-tag-2.*initial commit`).IsSelected(),
).
PressEnter().
Tap(func() {
// view the commits of the tag
t.Views().SubCommits().IsFocused().
Lines(
Contains("initial commit"),
).
PressEscape()
}).
Press(keys.Universal.Push).
Tap(func() {
t.ExpectPopup().Prompt().
Title(Equals("Remote to push tag 'new-tag-2' to:")).
InitialText(Equals("origin")).
SuggestionLines(
Contains("origin"),
).
Confirm()
}).
Press(keys.Universal.Remove).
Tap(func() {
t.ExpectPopup().
Menu().
Title(Equals("Delete tag 'new-tag-2'?")).
Select(Contains("Delete local and remote tag")).
Confirm()
}).
Tap(func() {
t.ExpectPopup().Prompt().
Title(Equals("Remote from which to remove tag 'new-tag-2':")).
InitialText(Equals("origin")).
SuggestionLines(
Contains("origin"),
).
Confirm()
}).
Tap(func() {
t.ExpectPopup().
Confirmation().
Title(Equals("Delete tag 'new-tag-2'?")).
Content(Equals("Are you sure you want to delete both 'new-tag-2' from your machine and from 'origin'?")).
Confirm()
}).
IsEmpty()
},
})

0 comments on commit c2d3d84

Please sign in to comment.