Repository: jesseduffield/lazygit
File: pkg/gui/controllers/helpers/tags_helper.go (Go)

Code before:
}

func NewTagsHelper(c *HelperCommon, commitsHelper *CommitsHelper, gpg *GpgHelper) *TagsHelper {
	return &TagsHelper{
		c:             c,
		commitsHelper: commitsHelper,
		gpg:           gpg,
	}
}

func (self *TagsHelper) OpenCreateTagPrompt(ref string, onCreate func()) error {
	doCreateTag := func(tagName string, description string, force bool) error {
		var command oscommands.ICmdObj
		if description != "" || self.c.Git().Config.GetGpgTagSign() {
			self.c.LogAction(self.c.Tr.Actions.CreateAnnotatedTag)
			command = self.c.Git().Tag.CreateAnnotatedObj(tagName, ref, description, force)
		} else {
			self.c.LogAction(self.c.Tr.Actions.CreateLightweightTag)
			command = self.c.Git().Tag.CreateLightweightObj(tagName, ref, force)
		}

		return self.gpg.WithGpgHandling(command, git_commands.TagGpgSign, self.c.Tr.CreatingTag, func() error {
			self.commitsHelper.OnCommitSuccess()
			return nil
		})
	}

	onConfirm := func(tagName string, description string) error {
		if self.c.Git().Tag.HasTag(tagName) {
			prompt := utils.ResolvePlaceholderString(
				self.c.Tr.ForceTagPrompt,
				map[string]string{
					"tagName":    tagName,
					"cancelKey":  self.c.UserConfig().Keybinding.Universal.Return,
					"confirmKey": self.c.UserConfig().Keybinding.Universal.Confirm,
				},
			)
			self.c.Confirm(types.ConfirmOpts{
				Title:  self.c.Tr.ForceTag,
				Prompt: prompt,
				HandleConfirm: func() error {
					return doCreateTag(tagName, description, true)
				},
			})

			return nil
		}

		return doCreateTag(tagName, description, false)
	}


Review comment (suggestion):
We implicitly now refresh on more scopes, since the `WithGpgHandler` calls `Refresh` with no scopes list applied. I'm assuming that refreshes all scopes. Don't think this is a major problem, but let me know if it is !

Code after:
}

func NewTagsHelper(c *HelperCommon, commitsHelper *CommitsHelper, gpg *GpgHelper) *TagsHelper {
	return &TagsHelper{
		c:             c,
		commitsHelper: commitsHelper,
		gpg:           gpg,
	}
}

func (self *TagsHelper) OpenCreateTagPrompt(ref string, onCreate func()) error {
	doCreateTag := func(tagName string, description string, force bool) error {
		var command oscommands.ICmdObj
		if description != "" || self.c.Git().Config.GetGpgTagSign() {
			self.c.LogAction(self.c.Tr.Actions.CreateAnnotatedTag)
			command = self.c.Git().Tag.CreateAnnotatedObj(tagName, ref, description, force)
		} else {
			self.c.LogAction(self.c.Tr.Actions.CreateLightweightTag)
			command = self.c.Git().Tag.CreateLightweightObj(tagName, ref, force)
		}

		return self.gpg.WithGpgHandling(command, git_commands.TagGpgSign, self.c.Tr.CreatingTag, func() error {
			self.commitsHelper.OnCommitSuccess()
			return nil
		}, []types.RefreshableView{types.COMMITS, types.TAGS})
	}

	onConfirm := func(tagName string, description string) error {
		if self.c.Git().Tag.HasTag(tagName) {
			prompt := utils.ResolvePlaceholderString(
				self.c.Tr.ForceTagPrompt,
				map[string]string{
					"tagName":    tagName,
					"cancelKey":  self.c.UserConfig().Keybinding.Universal.Return,
					"confirmKey": self.c.UserConfig().Keybinding.Universal.Confirm,
				},
			)
			self.c.Confirm(types.ConfirmOpts{
				Title:  self.c.Tr.ForceTag,
				Prompt: prompt,
				HandleConfirm: func() error {
					return doCreateTag(tagName, description, true)
				},
			})

			return nil
		}

		return doCreateTag(tagName, description, false)
	}