summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-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