Skip to content

Commit 7251b23

Browse files
committed
Update Git commit message script
1 parent 41ae5f7 commit 7251b23

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

git-commit-push-script.sh

Lines changed: 6 additions & 6 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 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")
24+
PROMPT=$(printf "You are an expert software engineer.\n\nYour job is to generate a short, descriptive commit message from the following git diff.\nOnly return the commit message, 72 characters maximum in length. Do not include any other text in the response.\n\nGit diff:\n%s" "$diff")
2525

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

35-
# 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')
35+
# Clean up commit message formatting - remove #, ```, "", '', and 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' | sed 's/\"//g' | sed "s/'//g")
3737

38-
# If the commit message is longer than 72 characters, truncate it
38+
# If the commit message is longer than 72 characters, truncate at the last word boundary
3939
if [ ${#commit_message} -gt 72 ]; then
40-
commit_message=${commit_message:0:72}...
40+
commit_message=$(echo $commit_message | cut -d' ' -f1-18)
4141
fi
4242

4343
# Echo the commit message
4444
echo $commit_message
4545

4646
# Set the GIT_SSH_PASSPHRASE environment variables
47-
export COMMIT_MESSAGE=$commit_message
47+
export COMMIT_MESSAGE="$commit_message"
4848
export TICKET="$ticket"
4949

5050
# Prepare and execute commit command, remove -S to commit without signing

0 commit comments

Comments
 (0)