Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions pkg/gui/context/commit_message_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

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

func (self *CommitMessageContext) RenderCommitLength() {
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 {
self.c.Views().CommitMessage.Subtitle = getBufferLength(self.c.Views().CommitMessage)
} else {
self.c.Views().CommitMessage.Subtitle = ""
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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/commit_message_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/gui/controllers/helpers/commits_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -140,6 +148,8 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp
opts.InitialMessage,
onConfirm,
opts.OnSwitchToEditor,
opts.ForceSkipHooks,
opts.SkipHooksPrefix,
)

self.UpdateCommitPanelView(opts.InitialMessage)
Expand Down
2 changes: 2 additions & 0 deletions pkg/gui/controllers/helpers/working_tree_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)

Expand Down
3 changes: 1 addition & 2 deletions pkg/gui/editors.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ 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
}

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

Expand Down
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ type TranslationSet struct {
CommitDescriptionTitle string
CommitDescriptionSubTitle string
CommitDescriptionFooter string
CommitHooksDisabledSubTitle string
LocalBranchesTitle string
SearchTitle string
TagsTitle string
Expand Down Expand Up @@ -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",
Expand Down