Skip to content

Commit 7bccf84

Browse files
authored
Show "(hooks disabled)" in title bar of commit message editor (#4467)
- **PR Description** It is shown either when committing with `w`, or when typing the skipHooks prefix if there is one. This should hopefully make it clearer when the hooks are run and when they are not. ``` ╭─Commit summary───────────────────(hooks disabled)─ 7 ─────╮ │WIP foo │ ╰───────────────────────────────────────────────────────────╯ ``` - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [ ] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [x] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents a24189b + b3bffbe commit 7bccf84

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

pkg/gui/context/commit_message_context.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strconv"
77
"strings"
88

9-
"github.com/jesseduffield/gocui"
109
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
1110
"github.com/jesseduffield/lazygit/pkg/gui/types"
1211
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -43,6 +42,10 @@ type CommitMessageViewModel struct {
4342
// invoked when pressing the switch-to-editor key binding
4443
onSwitchToEditor func(string) error
4544

45+
// the following two fields are used for the display of the "hooks disabled" subtitle
46+
forceSkipHooks bool
47+
skipHooksPrefix string
48+
4649
// The message typed in before cycling through history
4750
// We store this separately to 'preservedMessage' because 'preservedMessage'
4851
// is specifically for committing staged files and we don't want this affected
@@ -149,12 +152,16 @@ func (self *CommitMessageContext) SetPanelState(
149152
initialMessage string,
150153
onConfirm func(string, string) error,
151154
onSwitchToEditor func(string) error,
155+
forceSkipHooks bool,
156+
skipHooksPrefix string,
152157
) {
153158
self.viewModel.selectedindex = index
154159
self.viewModel.preserveMessage = preserveMessage
155160
self.viewModel.initialMessage = initialMessage
156161
self.viewModel.onConfirm = onConfirm
157162
self.viewModel.onSwitchToEditor = onSwitchToEditor
163+
self.viewModel.forceSkipHooks = forceSkipHooks
164+
self.viewModel.skipHooksPrefix = skipHooksPrefix
158165
self.GetView().Title = summaryTitle
159166
self.c.Views().CommitDescription.Title = descriptionTitle
160167

@@ -167,16 +174,24 @@ func (self *CommitMessageContext) SetPanelState(
167174
self.c.Views().CommitDescription.Visible = true
168175
}
169176

170-
func (self *CommitMessageContext) RenderCommitLength() {
177+
func (self *CommitMessageContext) RenderSubtitle() {
178+
skipHookPrefix := self.viewModel.skipHooksPrefix
179+
subject := self.c.Views().CommitMessage.TextArea.GetContent()
180+
var subtitle string
181+
if self.viewModel.forceSkipHooks || (skipHookPrefix != "" && strings.HasPrefix(subject, skipHookPrefix)) {
182+
subtitle = self.c.Tr.CommitHooksDisabledSubTitle
183+
}
171184
if self.c.UserConfig().Gui.CommitLength.Show {
172-
self.c.Views().CommitMessage.Subtitle = getBufferLength(self.c.Views().CommitMessage)
173-
} else {
174-
self.c.Views().CommitMessage.Subtitle = ""
185+
if subtitle != "" {
186+
subtitle += "─"
187+
}
188+
subtitle += getBufferLength(subject)
175189
}
190+
self.c.Views().CommitMessage.Subtitle = subtitle
176191
}
177192

178-
func getBufferLength(view *gocui.View) string {
179-
return " " + strconv.Itoa(strings.Count(view.TextArea.GetContent(), "")-1) + " "
193+
func getBufferLength(subject string) string {
194+
return " " + strconv.Itoa(strings.Count(subject, "")-1) + " "
180195
}
181196

182197
func (self *CommitMessageContext) SwitchToEditor(message string) error {

pkg/gui/controllers/commit_message_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (self *CommitMessageController) GetOnFocus() func(types.OnFocusOpts) {
7777

7878
func (self *CommitMessageController) GetOnFocusLost() func(types.OnFocusLostOpts) {
7979
return func(types.OnFocusLostOpts) {
80-
self.context().RenderCommitLength()
80+
self.context().RenderSubtitle()
8181
}
8282
}
8383

pkg/gui/controllers/helpers/commits_helper.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (self *CommitsHelper) SetMessageAndDescriptionInView(message string) {
5050

5151
self.setCommitSummary(summary)
5252
self.setCommitDescription(description)
53-
self.c.Contexts().CommitMessage.RenderCommitLength()
53+
self.c.Contexts().CommitMessage.RenderSubtitle()
5454
}
5555

5656
func (self *CommitsHelper) JoinCommitMessageAndUnwrappedDescription() string {
@@ -123,6 +123,14 @@ type OpenCommitMessagePanelOpts struct {
123123
OnConfirm func(summary string, description string) error
124124
OnSwitchToEditor func(string) error
125125
InitialMessage string
126+
127+
// The following two fields are only for the display of the "(hooks
128+
// disabled)" display in the commit message panel. They have no effect on
129+
// the actual behavior; make sure what you are passing in matches that.
130+
// Leave unassigned if the concept of skipping hooks doesn't make sense for
131+
// what you are doing, e.g. when creating a tag.
132+
ForceSkipHooks bool
133+
SkipHooksPrefix string
126134
}
127135

128136
func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOpts) {
@@ -140,6 +148,8 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp
140148
opts.InitialMessage,
141149
onConfirm,
142150
opts.OnSwitchToEditor,
151+
opts.ForceSkipHooks,
152+
opts.SkipHooksPrefix,
143153
)
144154

145155
self.UpdateCommitPanelView(opts.InitialMessage)

pkg/gui/controllers/helpers/working_tree_helper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ func (self *WorkingTreeHelper) HandleCommitPressWithMessage(initialMessage strin
9595
OnSwitchToEditor: func(filepath string) error {
9696
return self.switchFromCommitMessagePanelToEditor(filepath, forceSkipHooks)
9797
},
98+
ForceSkipHooks: forceSkipHooks,
99+
SkipHooksPrefix: self.c.UserConfig().Git.SkipHookPrefix,
98100
},
99101
)
100102

pkg/gui/editors.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,13 @@ func (gui *Gui) handleEditorKeypress(textArea *gocui.TextArea, key gocui.Key, ch
6161
func (gui *Gui) commitMessageEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool {
6262
matched := gui.handleEditorKeypress(v.TextArea, key, ch, mod, false)
6363
v.RenderTextArea()
64-
gui.c.Contexts().CommitMessage.RenderCommitLength()
64+
gui.c.Contexts().CommitMessage.RenderSubtitle()
6565
return matched
6666
}
6767

6868
func (gui *Gui) commitDescriptionEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool {
6969
matched := gui.handleEditorKeypress(v.TextArea, key, ch, mod, true)
7070
v.RenderTextArea()
71-
gui.c.Contexts().CommitMessage.RenderCommitLength()
7271
return matched
7372
}
7473

pkg/i18n/english.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ type TranslationSet struct {
315315
CommitDescriptionTitle string
316316
CommitDescriptionSubTitle string
317317
CommitDescriptionFooter string
318+
CommitHooksDisabledSubTitle string
318319
LocalBranchesTitle string
319320
SearchTitle string
320321
TagsTitle string
@@ -1366,6 +1367,7 @@ func EnglishTranslationSet() *TranslationSet {
13661367
CommitDescriptionTitle: "Commit description",
13671368
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.commitMenuKeybinding}} to open menu",
13681369
CommitDescriptionFooter: "Press {{.confirmInEditorKeybinding}} to commit",
1370+
CommitHooksDisabledSubTitle: "(hooks disabled)",
13691371
LocalBranchesTitle: "Local branches",
13701372
SearchTitle: "Search",
13711373
TagsTitle: "Tags",

0 commit comments

Comments
 (0)