Skip to content

Commit 0996f9e

Browse files
committed
Commit message length warning
1 parent c087dca commit 0996f9e

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

docs/Config.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ gui:
4545
- red
4646
commitLength:
4747
show: true
48+
warningThreshold: 0
4849
mouseEvents: true
4950
skipUnstageLineWarning: false
5051
skipStashWarning: false
@@ -530,4 +531,4 @@ notARepository: 'create'
530531
```yaml
531532
# to skip without creating a new repo
532533
notARepository: 'skip'
533-
```
534+
```

pkg/config/user_config.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ type ThemeConfig struct {
6767
}
6868

6969
type CommitLengthConfig struct {
70-
Show bool `yaml:"show"`
70+
Show bool `yaml:"show"`
71+
WarningThreshold int `yaml:"warningThreshold"`
7172
}
7273

7374
type GitConfig struct {
@@ -362,7 +363,10 @@ func GetDefaultConfig() *UserConfig {
362363
CherryPickedCommitFgColor: []string{"blue"},
363364
UnstagedChangesColor: []string{"red"},
364365
},
365-
CommitLength: CommitLengthConfig{Show: true},
366+
CommitLength: CommitLengthConfig{
367+
Show: true,
368+
WarningThreshold: 0,
369+
},
366370
SkipNoStagedFilesWarning: false,
367371
ShowListFooter: true,
368372
ShowCommandLog: true,

pkg/gui/commit_message_panel.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package gui
22

33
import (
4-
"strconv"
4+
"bufio"
55
"strings"
6-
6+
"fmt"
77
"github.com/jesseduffield/gocui"
88
"github.com/jesseduffield/lazygit/pkg/utils"
9+
"github.com/jesseduffield/lazygit/pkg/theme"
910
)
1011

1112
func (gui *Gui) handleCommitMessageFocused() error {
@@ -28,9 +29,27 @@ func (gui *Gui) RenderCommitLength() {
2829
return
2930
}
3031

31-
gui.Views.CommitMessage.Subtitle = getBufferLength(gui.Views.CommitMessage)
32+
commitLength := getBufferLength(gui.Views.CommitMessage)
33+
gui.Views.CommitMessage.Subtitle = fmt.Sprintf(" %d ", commitLength)
34+
gui.checkCommitLengthWarning(commitLength)
3235
}
3336

34-
func getBufferLength(view *gocui.View) string {
35-
return " " + strconv.Itoa(strings.Count(view.TextArea.GetContent(), "")-1) + " "
37+
func getBufferLength(view *gocui.View) int {
38+
return strings.Count(view.TextArea.GetContent(), "") - 1
3639
}
40+
41+
func (gui *Gui) checkCommitLengthWarning(commitLength int) {
42+
if gui.c.UserConfig.Gui.CommitLength.WarningThreshold == 0 {
43+
return
44+
}
45+
46+
scanner := bufio.NewScanner(strings.NewReader(gui.Views.CommitMessage.TextArea.GetContent()))
47+
48+
for scanner.Scan() {
49+
if len(scanner.Text()) > gui.c.UserConfig.Gui.CommitLength.WarningThreshold {
50+
gui.Views.CommitMessage.FgColor = gocui.ColorRed
51+
} else {
52+
gui.Views.CommitMessage.FgColor = theme.GocuiDefaultTextColor
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)