mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Show "hooks disabled" in title bar of commit message editor
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.
This commit is contained in:
parent
2ee80d7150
commit
b3bffbec4a
6 changed files with 40 additions and 11 deletions
|
@ -6,7 +6,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
@ -43,6 +42,10 @@ type CommitMessageViewModel struct {
|
||||||
// invoked when pressing the switch-to-editor key binding
|
// invoked when pressing the switch-to-editor key binding
|
||||||
onSwitchToEditor func(string) error
|
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
|
// The message typed in before cycling through history
|
||||||
// We store this separately to 'preservedMessage' because 'preservedMessage'
|
// We store this separately to 'preservedMessage' because 'preservedMessage'
|
||||||
// is specifically for committing staged files and we don't want this affected
|
// is specifically for committing staged files and we don't want this affected
|
||||||
|
@ -149,12 +152,16 @@ func (self *CommitMessageContext) SetPanelState(
|
||||||
initialMessage string,
|
initialMessage string,
|
||||||
onConfirm func(string, string) error,
|
onConfirm func(string, string) error,
|
||||||
onSwitchToEditor func(string) error,
|
onSwitchToEditor func(string) error,
|
||||||
|
forceSkipHooks bool,
|
||||||
|
skipHooksPrefix string,
|
||||||
) {
|
) {
|
||||||
self.viewModel.selectedindex = index
|
self.viewModel.selectedindex = index
|
||||||
self.viewModel.preserveMessage = preserveMessage
|
self.viewModel.preserveMessage = preserveMessage
|
||||||
self.viewModel.initialMessage = initialMessage
|
self.viewModel.initialMessage = initialMessage
|
||||||
self.viewModel.onConfirm = onConfirm
|
self.viewModel.onConfirm = onConfirm
|
||||||
self.viewModel.onSwitchToEditor = onSwitchToEditor
|
self.viewModel.onSwitchToEditor = onSwitchToEditor
|
||||||
|
self.viewModel.forceSkipHooks = forceSkipHooks
|
||||||
|
self.viewModel.skipHooksPrefix = skipHooksPrefix
|
||||||
self.GetView().Title = summaryTitle
|
self.GetView().Title = summaryTitle
|
||||||
self.c.Views().CommitDescription.Title = descriptionTitle
|
self.c.Views().CommitDescription.Title = descriptionTitle
|
||||||
|
|
||||||
|
@ -167,16 +174,24 @@ func (self *CommitMessageContext) SetPanelState(
|
||||||
self.c.Views().CommitDescription.Visible = true
|
self.c.Views().CommitDescription.Visible = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitMessageContext) RenderCommitLength() {
|
func (self *CommitMessageContext) RenderSubtitle() {
|
||||||
if self.c.UserConfig().Gui.CommitLength.Show {
|
skipHookPrefix := self.viewModel.skipHooksPrefix
|
||||||
self.c.Views().CommitMessage.Subtitle = getBufferLength(self.c.Views().CommitMessage)
|
subject := self.c.Views().CommitMessage.TextArea.GetContent()
|
||||||
} else {
|
var subtitle string
|
||||||
self.c.Views().CommitMessage.Subtitle = ""
|
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 {
|
func getBufferLength(subject string) string {
|
||||||
return " " + strconv.Itoa(strings.Count(view.TextArea.GetContent(), "")-1) + " "
|
return " " + strconv.Itoa(strings.Count(subject, "")-1) + " "
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitMessageContext) SwitchToEditor(message string) error {
|
func (self *CommitMessageContext) SwitchToEditor(message string) error {
|
||||||
|
|
|
@ -77,7 +77,7 @@ func (self *CommitMessageController) GetOnFocus() func(types.OnFocusOpts) {
|
||||||
|
|
||||||
func (self *CommitMessageController) GetOnFocusLost() func(types.OnFocusLostOpts) {
|
func (self *CommitMessageController) GetOnFocusLost() func(types.OnFocusLostOpts) {
|
||||||
return func(types.OnFocusLostOpts) {
|
return func(types.OnFocusLostOpts) {
|
||||||
self.context().RenderCommitLength()
|
self.context().RenderSubtitle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (self *CommitsHelper) SetMessageAndDescriptionInView(message string) {
|
||||||
|
|
||||||
self.setCommitSummary(summary)
|
self.setCommitSummary(summary)
|
||||||
self.setCommitDescription(description)
|
self.setCommitDescription(description)
|
||||||
self.c.Contexts().CommitMessage.RenderCommitLength()
|
self.c.Contexts().CommitMessage.RenderSubtitle()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitsHelper) JoinCommitMessageAndUnwrappedDescription() string {
|
func (self *CommitsHelper) JoinCommitMessageAndUnwrappedDescription() string {
|
||||||
|
@ -123,6 +123,14 @@ type OpenCommitMessagePanelOpts struct {
|
||||||
OnConfirm func(summary string, description string) error
|
OnConfirm func(summary string, description string) error
|
||||||
OnSwitchToEditor func(string) error
|
OnSwitchToEditor func(string) error
|
||||||
InitialMessage string
|
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) {
|
func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOpts) {
|
||||||
|
@ -140,6 +148,8 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp
|
||||||
opts.InitialMessage,
|
opts.InitialMessage,
|
||||||
onConfirm,
|
onConfirm,
|
||||||
opts.OnSwitchToEditor,
|
opts.OnSwitchToEditor,
|
||||||
|
opts.ForceSkipHooks,
|
||||||
|
opts.SkipHooksPrefix,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.UpdateCommitPanelView(opts.InitialMessage)
|
self.UpdateCommitPanelView(opts.InitialMessage)
|
||||||
|
|
|
@ -95,6 +95,8 @@ func (self *WorkingTreeHelper) HandleCommitPressWithMessage(initialMessage strin
|
||||||
OnSwitchToEditor: func(filepath string) error {
|
OnSwitchToEditor: func(filepath string) error {
|
||||||
return self.switchFromCommitMessagePanelToEditor(filepath, forceSkipHooks)
|
return self.switchFromCommitMessagePanelToEditor(filepath, forceSkipHooks)
|
||||||
},
|
},
|
||||||
|
ForceSkipHooks: forceSkipHooks,
|
||||||
|
SkipHooksPrefix: self.c.UserConfig().Git.SkipHookPrefix,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
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)
|
matched := gui.handleEditorKeypress(v.TextArea, key, ch, mod, false)
|
||||||
v.RenderTextArea()
|
v.RenderTextArea()
|
||||||
gui.c.Contexts().CommitMessage.RenderCommitLength()
|
gui.c.Contexts().CommitMessage.RenderSubtitle()
|
||||||
return matched
|
return matched
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -315,6 +315,7 @@ type TranslationSet struct {
|
||||||
CommitDescriptionTitle string
|
CommitDescriptionTitle string
|
||||||
CommitDescriptionSubTitle string
|
CommitDescriptionSubTitle string
|
||||||
CommitDescriptionFooter string
|
CommitDescriptionFooter string
|
||||||
|
CommitHooksDisabledSubTitle string
|
||||||
LocalBranchesTitle string
|
LocalBranchesTitle string
|
||||||
SearchTitle string
|
SearchTitle string
|
||||||
TagsTitle string
|
TagsTitle string
|
||||||
|
@ -1366,6 +1367,7 @@ func EnglishTranslationSet() *TranslationSet {
|
||||||
CommitDescriptionTitle: "Commit description",
|
CommitDescriptionTitle: "Commit description",
|
||||||
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.commitMenuKeybinding}} to open menu",
|
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.commitMenuKeybinding}} to open menu",
|
||||||
CommitDescriptionFooter: "Press {{.confirmInEditorKeybinding}} to commit",
|
CommitDescriptionFooter: "Press {{.confirmInEditorKeybinding}} to commit",
|
||||||
|
CommitHooksDisabledSubTitle: "(hooks disabled)",
|
||||||
LocalBranchesTitle: "Local branches",
|
LocalBranchesTitle: "Local branches",
|
||||||
SearchTitle: "Search",
|
SearchTitle: "Search",
|
||||||
TagsTitle: "Tags",
|
TagsTitle: "Tags",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue