Skip to content

Commit f118962

Browse files
authored
Merged to main
2 parents 332a3b9 + c7a3429 commit f118962

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

git-commit-push-script.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ diff=$(git diff --cached)
2121
MODEL="mistral"
2222

2323
# Prepare the prompt
24-
PROMPT=$(printf "You are an expert software engineer.\n\nYour job is to generate a short, commit message from the following git diff.\nNo more than 72 characters total.\nOnly return the commit message. Do not include any other text.\n\nGit diff:\n%s" "$diff")
24+
PROMPT=$(printf "You are an expert software engineer.\n\nYour job is to generate a concise, descriptive commit message from the following git diff.\nThe commit message MUST be 72 characters or less - this is a strict requirement.\nOnly return the commit message itself without quotes, explanations or additional text.\n\nGit diff:\n%s" "$diff")
2525

2626
# Run the model and capture output
2727
COMMIT_MSG=$(echo "$PROMPT" | ollama run "$MODEL")
@@ -33,7 +33,13 @@ if [ -z "$COMMIT_MSG" ]; then
3333
fi
3434

3535
# Clean up commit message formatting - remove #, ```, period . at the end of response
36-
commit_message=$(echo $COMMIT_MSG | sed 's/#//g' | sed 's/```//g' | sed 's/Commit message title://g' | sed 's/Commit message summary://g' | sed 's/\.//g')
36+
commit_message=$(echo "$COMMIT_MSG" | sed 's/#//g' | sed 's/```//g' | sed 's/Commit message title://g' | sed 's/Commit message summary://g' | sed 's/\.//g' | head -n 1)
37+
38+
# If the commit message is longer than 72 characters, truncate it at word boundary
39+
if [ ${#commit_message} -gt 72 ]; then
40+
# Truncate at the last word boundary before 72 characters
41+
commit_message=$(echo "$commit_message" | cut -c 1-72 | sed 's/\s\+[^\s]*$//')
42+
fi
3743

3844
# Echo the commit message
3945
echo $commit_message

0 commit comments

Comments
 (0)