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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ commit
test.txt
AGENTS.md
commit~
commit-msg
30 changes: 30 additions & 0 deletions cmd/cli/createMsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func CreateCommitMsg(Store *store.StoreMethods, dryRun bool, autoCommit bool) {
spinnerGenerating.Success("Commit message generated successfully!")

currentMessage := strings.TrimSpace(commitMsg)
validateCommitMessageLength(currentMessage)
currentStyleLabel := stylePresets[0].Label
var currentStyleOpts *types.GenerationOptions
accepted := false
Expand Down Expand Up @@ -190,6 +191,7 @@ interactionLoop:
spinner.Success("Commit message regenerated!")
attempt = nextAttempt
currentMessage = strings.TrimSpace(updatedMessage)
validateCommitMessageLength(currentMessage)
case actionEditOption:
edited, editErr := editCommitMessage(currentMessage)
if editErr != nil {
Expand All @@ -201,6 +203,7 @@ interactionLoop:
continue
}
currentMessage = strings.TrimSpace(edited)
validateCommitMessageLength(currentMessage)
case actionExitOption:
pterm.Info.Println("Exiting without copying commit message.")
return
Expand Down Expand Up @@ -577,3 +580,30 @@ func maskAPIKey(apiKey string) string {
func estimateTokens(text string) int {
return len(text) / 4
}

// validateCommitMessageLength checks if the commit message exceeds recommended length limits
// and displays appropriate warnings
func validateCommitMessageLength(message string) {
if message == "" {
return
}

lines := strings.Split(message, "\n")
if len(lines) == 0 {
return
}

subjectLine := strings.TrimSpace(lines[0])
subjectLength := len(subjectLine)

// Git recommends subject lines be 50 characters or less, but allows up to 72
const maxRecommendedLength = 50
const maxAllowedLength = 72

if subjectLength > maxAllowedLength {
pterm.Warning.Printf("Commit message subject line is %d characters (exceeds %d character limit)\n", subjectLength, maxAllowedLength)
pterm.Info.Println("Consider shortening the subject line for better readability")
} else if subjectLength > maxRecommendedLength {
pterm.Warning.Printf("Commit message subject line is %d characters (recommended limit is %d)\n", subjectLength, maxRecommendedLength)
}
}
Loading