diff --git a/pkg/gui/context/commit_message_context.go b/pkg/gui/context/commit_message_context.go index 531625156..d533e1dea 100644 --- a/pkg/gui/context/commit_message_context.go +++ b/pkg/gui/context/commit_message_context.go @@ -6,7 +6,6 @@ import ( "strconv" "strings" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/gui/keybindings" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" @@ -43,6 +42,10 @@ type CommitMessageViewModel struct { // invoked when pressing the switch-to-editor key binding onSwitchToEditor func(string) error + // the following two fields are used for the display of the "hooks disabled" subtitle + forceSkipHooks bool + skipHooksPrefix string + // The message typed in before cycling through history // We store this separately to 'preservedMessage' because 'preservedMessage' // is specifically for committing staged files and we don't want this affected @@ -149,12 +152,16 @@ func (self *CommitMessageContext) SetPanelState( initialMessage string, onConfirm func(string, string) error, onSwitchToEditor func(string) error, + forceSkipHooks bool, + skipHooksPrefix string, ) { self.viewModel.selectedindex = index self.viewModel.preserveMessage = preserveMessage self.viewModel.initialMessage = initialMessage self.viewModel.onConfirm = onConfirm self.viewModel.onSwitchToEditor = onSwitchToEditor + self.viewModel.forceSkipHooks = forceSkipHooks + self.viewModel.skipHooksPrefix = skipHooksPrefix self.GetView().Title = summaryTitle self.c.Views().CommitDescription.Title = descriptionTitle @@ -167,16 +174,24 @@ func (self *CommitMessageContext) SetPanelState( self.c.Views().CommitDescription.Visible = true } -func (self *CommitMessageContext) RenderCommitLength() { - if self.c.UserConfig().Gui.CommitLength.Show { - self.c.Views().CommitMessage.Subtitle = getBufferLength(self.c.Views().CommitMessage) - } else { - self.c.Views().CommitMessage.Subtitle = "" +func (self *CommitMessageContext) RenderSubtitle() { + skipHookPrefix := self.viewModel.skipHooksPrefix + subject := self.c.Views().CommitMessage.TextArea.GetContent() + var subtitle string + if self.viewModel.forceSkipHooks || (skipHookPrefix != "" && strings.HasPrefix(subject, skipHookPrefix)) { + subtitle = self.c.Tr.CommitHooksDisabledSubTitle } + if self.c.UserConfig().Gui.CommitLength.Show { + if subtitle != "" { + subtitle += "─" + } + subtitle += getBufferLength(subject) + } + self.c.Views().CommitMessage.Subtitle = subtitle } -func getBufferLength(view *gocui.View) string { - return " " + strconv.Itoa(strings.Count(view.TextArea.GetContent(), "")-1) + " " +func getBufferLength(subject string) string { + return " " + strconv.Itoa(strings.Count(subject, "")-1) + " " } func (self *CommitMessageContext) SwitchToEditor(message string) error { diff --git a/pkg/gui/controllers/commit_message_controller.go b/pkg/gui/controllers/commit_message_controller.go index 6f0773801..b72d5d45a 100644 --- a/pkg/gui/controllers/commit_message_controller.go +++ b/pkg/gui/controllers/commit_message_controller.go @@ -77,7 +77,7 @@ func (self *CommitMessageController) GetOnFocus() func(types.OnFocusOpts) { func (self *CommitMessageController) GetOnFocusLost() func(types.OnFocusLostOpts) { return func(types.OnFocusLostOpts) { - self.context().RenderCommitLength() + self.context().RenderSubtitle() } } diff --git a/pkg/gui/controllers/helpers/commits_helper.go b/pkg/gui/controllers/helpers/commits_helper.go index c542b2d67..9d2fcd164 100644 --- a/pkg/gui/controllers/helpers/commits_helper.go +++ b/pkg/gui/controllers/helpers/commits_helper.go @@ -50,7 +50,7 @@ func (self *CommitsHelper) SetMessageAndDescriptionInView(message string) { self.setCommitSummary(summary) self.setCommitDescription(description) - self.c.Contexts().CommitMessage.RenderCommitLength() + self.c.Contexts().CommitMessage.RenderSubtitle() } func (self *CommitsHelper) JoinCommitMessageAndUnwrappedDescription() string { @@ -123,6 +123,14 @@ type OpenCommitMessagePanelOpts struct { OnConfirm func(summary string, description string) error OnSwitchToEditor func(string) error InitialMessage string + + // The following two fields are only for the display of the "(hooks + // disabled)" display in the commit message panel. They have no effect on + // the actual behavior; make sure what you are passing in matches that. + // Leave unassigned if the concept of skipping hooks doesn't make sense for + // what you are doing, e.g. when creating a tag. + ForceSkipHooks bool + SkipHooksPrefix string } func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOpts) { @@ -140,6 +148,8 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp opts.InitialMessage, onConfirm, opts.OnSwitchToEditor, + opts.ForceSkipHooks, + opts.SkipHooksPrefix, ) self.UpdateCommitPanelView(opts.InitialMessage) diff --git a/pkg/gui/controllers/helpers/working_tree_helper.go b/pkg/gui/controllers/helpers/working_tree_helper.go index b5ea1b6bd..a95bdb98e 100644 --- a/pkg/gui/controllers/helpers/working_tree_helper.go +++ b/pkg/gui/controllers/helpers/working_tree_helper.go @@ -95,6 +95,8 @@ func (self *WorkingTreeHelper) HandleCommitPressWithMessage(initialMessage strin OnSwitchToEditor: func(filepath string) error { return self.switchFromCommitMessagePanelToEditor(filepath, forceSkipHooks) }, + ForceSkipHooks: forceSkipHooks, + SkipHooksPrefix: self.c.UserConfig().Git.SkipHookPrefix, }, ) diff --git a/pkg/gui/editors.go b/pkg/gui/editors.go index 10cac7008..a409e64f5 100644 --- a/pkg/gui/editors.go +++ b/pkg/gui/editors.go @@ -61,7 +61,7 @@ func (gui *Gui) handleEditorKeypress(textArea *gocui.TextArea, key gocui.Key, ch func (gui *Gui) commitMessageEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool { matched := gui.handleEditorKeypress(v.TextArea, key, ch, mod, false) v.RenderTextArea() - gui.c.Contexts().CommitMessage.RenderCommitLength() + gui.c.Contexts().CommitMessage.RenderSubtitle() return matched } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 5aa70426d..e91149b72 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -315,6 +315,7 @@ type TranslationSet struct { CommitDescriptionTitle string CommitDescriptionSubTitle string CommitDescriptionFooter string + CommitHooksDisabledSubTitle string LocalBranchesTitle string SearchTitle string TagsTitle string @@ -1366,6 +1367,7 @@ func EnglishTranslationSet() *TranslationSet { CommitDescriptionTitle: "Commit description", CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.commitMenuKeybinding}} to open menu", CommitDescriptionFooter: "Press {{.confirmInEditorKeybinding}} to commit", + CommitHooksDisabledSubTitle: "(hooks disabled)", LocalBranchesTitle: "Local branches", SearchTitle: "Search", TagsTitle: "Tags",