Repository: jesseduffield/lazygit
File: pkg/gui/commits_panel.go (Go)

Code before:
				return gui.handleCreateAnnotatedTag(commitSha)
			},
		},
	}

	return gui.createMenu(gui.Tr.TagMenuTitle, items, createMenuOptions{showCancel: true})
}

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 {
			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 {
						return gui.surfaceError(err)
					}
					return gui.afterTagCreate(tagName)
				},
			})
		},
	})
}

func (gui *Gui) handleCreateLightweightTag(commitSha string) error {
	return gui.prompt(promptOpts{
		title: gui.Tr.TagNameTitle,
		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.afterTagCreate(tagName)
		},
	})
}

Review comment (suggestion):
I wonder here whether a single-line editor is going to suffice. I assume that people typically use annotated tags for the sake of writing release notes for a release, and that will require more than one line. At any rate I'm happy to release this and see if anybody wants multi-line just so that this code doesn't get stale

Code after:
			displayString: gui.Tr.LcLightweightTag,
			onPress: func() error {
				return gui.handleCreateLightweightTag(commitSha)
			},
		},
		{
			displayString: gui.Tr.LcAnnotatedTag,
			onPress: func() error {
				return gui.handleCreateAnnotatedTag(commitSha)
			},
		},
	}

	return gui.createMenu(gui.Tr.TagMenuTitle, items, createMenuOptions{showCancel: true})
}

func (gui *Gui) afterTagCreate(tagName string) error {
	gui.State.Panels.Tags.SelectedLineIdx = 0 // Set to the top
	return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{COMMITS, TAGS}})
}

func (gui *Gui) handleCreateAnnotatedTag(commitSha string) error {
	return gui.prompt(promptOpts{
		title: gui.Tr.TagNameTitle,
		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 {
						return gui.surfaceError(err)
					}
					return gui.afterTagCreate(tagName)
				},
			})
		},
	})
}

func (gui *Gui) handleCreateLightweightTag(commitSha string) error {
	return gui.prompt(promptOpts{
		title: gui.Tr.TagNameTitle,
		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.afterTagCreate(tagName)
		},
	})
}

func (gui *Gui) handleCheckoutCommit() error {