diff --git a/ai-commit.sh b/ai-commit.sh new file mode 100644 index 0000000..e1913d8 --- /dev/null +++ b/ai-commit.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -e + +# 1. Stage everything +git add -A + +# 2. Get list of staged files +FILES=$(git diff --cached --name-only) + +if [ -z "$FILES" ]; then + echo "No changes to commit." + exit 0 +fi + +# 3. Loop file by file +for FILE in $FILES; do + # Get diff for this file + DIFF=$(git diff --cached -- "$FILE") + + if [ -z "$DIFF" ]; then + continue + fi + + # Ask Ollama for a commit message describing this file change + MSG=$(echo "$DIFF" | ollama run gemma3 \ + "You are a commit bot. Write a clear, concise Git commit message for changes in file: $FILE. +Only output the commit message, nothing else. +Diff: +$DIFF") + + # Commit just this file with its message + git commit -m "$MSG" -- "$FILE" + + echo "✅ Committed $FILE with message:" + echo "$MSG" +done