summaryrefslogtreecommitdiff
path: root/scripts/commit.sh
diff options
context:
space:
mode:
authorallexanderbergmans <allexander.bergmans@student.elisa.be>2026-07-03 16:18:29 +0200
committerallexanderbergmans <allexander.bergmans@student.elisa.be>2026-07-03 16:18:29 +0200
commite0142bd624cc090ee51a26fcdc48ff3451f29564 (patch)
tree54b24c6b03ccb3070d48108f5eebe3e68fd1456e /scripts/commit.sh
parent0952ff21b0fd30639b5c2de45e985d9be5f64e80 (diff)
fix(files): parse commit message correctlymain
Diffstat (limited to 'scripts/commit.sh')
-rw-r--r--scripts/commit.sh25
1 files changed, 18 insertions, 7 deletions
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