refactor: change commit length limit and change exit codes

This commit is contained in:
Slug-Boi
2025-06-16 17:43:02 +02:00
parent eeb93fb411
commit 9e85fdd1b9
+11 -12
View File
@@ -7,7 +7,6 @@ import (
"strings" "strings"
) )
func HandleEditor() (string, error) { func HandleEditor() (string, error) {
editor := ConfigVar.Settings.Editor editor := ConfigVar.Settings.Editor
if editor == "built-in" { if editor == "built-in" {
@@ -25,7 +24,6 @@ func HandleEditor() (string, error) {
return "", fmt.Errorf("editor %s not found in PATH", editor) return "", fmt.Errorf("editor %s not found in PATH", editor)
} }
output, err := LaunchEditor(editor, "") output, err := LaunchEditor(editor, "")
if err != nil { if err != nil {
return "", fmt.Errorf("failed to launch editor %s: %v", editor, err) return "", fmt.Errorf("failed to launch editor %s: %v", editor, err)
@@ -33,7 +31,7 @@ func HandleEditor() (string, error) {
return output, nil return output, nil
} }
func LaunchEditor(editor string, filepath string) (string,error) { func LaunchEditor(editor string, filepath string) (string, error) {
// Create a temp file or use an existing file // Create a temp file or use an existing file
var tempFile *os.File var tempFile *os.File
var err error var err error
@@ -71,7 +69,6 @@ func LaunchEditor(editor string, filepath string) (string,error) {
return "", fmt.Errorf("error running editor command: %v", err) return "", fmt.Errorf("error running editor command: %v", err)
} }
data, err := os.ReadFile(tempFile.Name()) data, err := os.ReadFile(tempFile.Name())
if err != nil { if err != nil {
return "", fmt.Errorf("error reading temp file: %v", err) return "", fmt.Errorf("error reading temp file: %v", err)
@@ -79,7 +76,8 @@ func LaunchEditor(editor string, filepath string) (string,error) {
message := string(data) message := string(data)
if message == "" { if message == "" {
return "", fmt.Errorf("commit message is empty") fmt.Printf("Error: Commit message is empty. Please provide a commit message.\n")
os.Exit(0)
} }
// Clean up the temp file // Clean up the temp file
@@ -93,15 +91,16 @@ func LaunchEditor(editor string, filepath string) (string,error) {
message = strings.TrimSuffix(message, "\r") message = strings.TrimSuffix(message, "\r")
} }
if strings.TrimSpace(message) == "" { if strings.TrimSpace(message) == "" {
return "", fmt.Errorf("commit message is empty after trimming") fmt.Printf("Error: Commit message is empty. Please provide a commit message.\n")
os.Exit(0)
} }
// If the message is too long, truncate it // If the message is too long, truncate it
if len(message) > 72 { // if len(message) > 72 {
fmt.Printf("Warning: Commit message is too long (%d characters). It will be truncated to 72 characters.\n", len(message)) // fmt.Printf("Warning: Commit message is too long (%d characters). It will be truncated to 72 characters.\n", len(message))
//TODO: Maybe add the rest to the description of the message? // //TODO: Maybe add the rest to the description of the message?
//description := message[72:] // //description := message[72:]
message = message[:72] // message = message[:72]
} // }
return message, nil return message, nil
} }