summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorFrancisco Miamoto <francisco@dorayaki.co>2021-09-11 20:29:52 -0300
committerJesse Duffield <jessedduffield@gmail.com>2021-12-26 17:08:31 +1100
commit3e58797096af0fc56a473b9c651c75f84dbeeecd (patch)
treea812949d753ff1271209a15efb3826edbfd5d8b9 /pkg
parentb1d6ccddfb7ebcfc44cbfa315d27961b98d48951 (diff)
show tag menu for creation on tags tab
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/tags.go2
-rw-r--r--pkg/gui/commits_panel.go47
-rw-r--r--pkg/gui/tags_panel.go25
3 files changed, 38 insertions, 36 deletions
diff --git a/pkg/commands/tags.go b/pkg/commands/tags.go
index ae819fbec..bb04d38e6 100644
--- a/pkg/commands/tags.go
+++ b/pkg/commands/tags.go
@@ -9,7 +9,7 @@ func (c *GitCommand) CreateLightweightTag(tagName string, commitSha string) erro
}
func (c *GitCommand) CreateAnnotatedTag(tagName, commitSha, msg string) error {
- return c.RunCommand("git tag %s %s -m '%s'", tagName, commitSha, msg)
+ return c.RunCommand("git tag %s %s -m %s", tagName, commitSha, c.OSCommand.Quote(msg))
}
func (c *GitCommand) DeleteTag(tagName string) error {
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index ce2ca9a92..edda92f5d 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -584,29 +584,52 @@ func (gui *Gui) handleTagCommit() error {
return nil
}
+ return gui.createTagMenu(commit.Sha)
+}
+
+func (gui *Gui) createTagMenu(commitSha string) error {
items := []*menuItem{
- {displayString: gui.Tr.LightweightTag, onPress: func() error {
- return gui.handleCreateLightweightTag(commit.Sha)
- }},
- {displayString: gui.Tr.AnnotatedTag, onPress: func() error {
- return gui.handleCreateAnnotatedTag(commit.Sha)
- }},
+ {
+ displayString: gui.Tr.LightweightTag,
+ onPress: func() error {
+ return gui.handleCreateLightweightTag(commitSha)
+ }},
+ {
+ displayString: gui.Tr.AnnotatedTag,
+ onPress: func() error {
+ return gui.handleCreateAnnotatedTag(commitSha)
+ }},
}
return gui.createMenu(gui.Tr.TagMenuTitle, items, createMenuOptions{showCancel: false})
}
+func (gui *Gui) afterTagCreate(tagName string) error {
+ return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{COMMITS, TAGS}, then: func() {
+ // find the index of the tag and set that as the currently selected line
+ for i, tag := range gui.State.Tags {
+ if tag.Name == tagName {
+ gui.State.Panels.Tags.SelectedLineIdx = i
+ if err := gui.State.Contexts.Tags.HandleRender(); err != nil {
+ gui.Log.Error(err)
+ }
+ return
+ }
+ }
+ }})
+}
+
func (gui *Gui) handleCreateAnnotatedTag(commitSha string) error {
return gui.prompt(promptOpts{
title: gui.Tr.TagNameTitle,
- handleConfirm: func(tagname string) error {
+ handleConfirm: func(tagName string) error {
return gui.prompt(promptOpts{
title: gui.Tr.TagMessageTitle,
handleConfirm: func(msg string) error {
- if err := gui.GitCommand.WithSpan(gui.Tr.Spans.CreateAnnotatedTag).CreateAnnotatedTag(tagname, commitSha, msg); err != nil {
+ if err := gui.GitCommand.WithSpan(gui.Tr.Spans.CreateAnnotatedTag).CreateAnnotatedTag(tagName, commitSha, msg); err != nil {
return gui.surfaceError(err)
}
- return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{COMMITS, TAGS}})
+ return gui.afterTagCreate(tagName)
},
})
},
@@ -616,11 +639,11 @@ func (gui *Gui) handleCreateAnnotatedTag(commitSha string) error {
func (gui *Gui) handleCreateLightweightTag(commitSha string) error {
return gui.prompt(promptOpts{
title: gui.Tr.TagNameTitle,
- handleConfirm: func(response string) error {
- if err := gui.GitCommand.WithSpan(gui.Tr.Spans.CreateLightweightTag).CreateLightweightTag(response, commitSha); err != nil {
+ handleConfirm: func(tagName string) error {
+ if err := gui.GitCommand.WithSpan(gui.Tr.Spans.CreateLightweightTag).CreateLightweightTag(tagName, commitSha); err != nil {
return gui.surfaceError(err)
}
- return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{COMMITS, TAGS}})
+ return gui.afterTagCreate(tagName)
},
})
}
diff --git a/pkg/gui/tags_panel.go b/pkg/gui/tags_panel.go
index 7ea810e09..b747c7e1a 100644
--- a/pkg/gui/tags_panel.go
+++ b/pkg/gui/tags_panel.go
@@ -15,29 +15,8 @@ func (gui *Gui) getSelectedTag() *models.Tag {
}
func (gui *Gui) handleCreateTag() error {
- return gui.prompt(promptOpts{
- title: gui.Tr.CreateTagTitle,
- handleConfirm: func(tagName string) error {
- // leaving commit SHA blank so that we're just creating the tag for the current commit
- if err := gui.GitCommand.WithSpan(gui.Tr.Spans.CreateLightweightTag).CreateLightweightTag(tagName, ""); err != nil {
- return gui.surfaceError(err)
- }
- return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{COMMITS, TAGS}, then: func() {
- // find the index of the tag and set that as the currently selected line
- for i, tag := range gui.State.Tags {
- if tag.Name == tagName {
- gui.State.Panels.Tags.SelectedLineIdx = i
- if err := gui.State.Contexts.Tags.HandleRender(); err != nil {
- gui.Log.Error(err)
- }
-
- return
- }
- }
- },
- })
- },
- })
+ // leaving commit SHA blank so that we're just creating the tag for the current commit
+ return gui.createTagMenu("")
}
func (gui *Gui) tagsRenderToMain() error {