From e0142bd624cc090ee51a26fcdc48ff3451f29564 Mon Sep 17 00:00:00 2001 From: allexanderbergmans Date: Fri, 3 Jul 2026 16:18:29 +0200 Subject: fix(files): parse commit message correctly --- scripts/commit.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/commit.sh b/scripts/commit.sh index 50ce5fa..6c7597c 100644 --- a/scripts/commit.sh +++ b/scripts/commit.sh @@ -1,23 +1,34 @@ #!/usr/bin/env bash -set -e +set -euo pipefail if git diff --cached --quiet; then echo "No staged changes." exit 1 fi -MSG=$(git diff --cached | ollama run git-commit) +MSG=$( +git diff --cached \ +| ollama run git-commit \ +| sed '/^$/d' \ +| tail -n 1 +) + +COMMIT_RE='^(feat|fix|docs|refactor|build|chore|test|perf|ci|revert)(\([[:alnum:]_-]+\))?: .+$' + +if ! [[ $MSG =~ $COMMIT_RE ]]; then + echo "Invalid commit message:" + echo "$MSG" + exit 1 +fi echo echo "Generated commit message:" -echo "$MSG" +echo " $MSG" echo -read -p "Commit? [Y/n] " CONFIRM +read -rp "Commit? [Y/n] " CONFIRM -if [[ "$CONFIRM" =~ ^[Nn]$ ]]; then - exit 0 -fi +[[ "$CONFIRM" =~ ^[Nn]$ ]] && exit 0 git commit -m "$MSG" \ No newline at end of file -- cgit v1.3