Update gp
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 6s
Build-Test-Publish / build (linux/arm64) (push) Successful in 12s

This commit is contained in:
j
2026-03-01 21:54:00 +13:00
parent 4c69941722
commit 7b984f5542

47
gp
View File

@@ -49,8 +49,39 @@ EXAMPLES:
EOF
}
# Function to generate commit message based on changes
generate_commit_message() {
# Function to generate commit message using Claude AI
generate_commit_message_ai() {
# Stage files first so we can get a proper diff
if [ "$ADD_ALL" = true ]; then
git add -A
fi
local diff
diff=$(git diff --cached)
if [ -z "$diff" ]; then
return 1
fi
local msg
msg=$(echo "$diff" | claude --print \
"Write a short git commit message (max 72 chars subject line) summarising these changes. Output ONLY the message, no quotes or prefixes." \
2>/dev/null) || return 1
# Validate: non-empty, single line, reasonable length
if [ -z "$msg" ]; then
return 1
fi
# Take only the first line
msg=$(echo "$msg" | head -1)
if [ ${#msg} -gt 120 ]; then
return 1
fi
echo "$msg"
}
# Function to generate commit message based on heuristics (fallback)
generate_commit_message_fallback() {
# First check if we have staged changes
local has_staged_changes=false
if ! git diff --cached --quiet; then
@@ -204,6 +235,18 @@ generate_commit_message() {
echo "$message"
}
# Function to generate commit message — tries Claude AI first, falls back to heuristics
generate_commit_message() {
if command -v claude &>/dev/null; then
local ai_msg
if ai_msg=$(generate_commit_message_ai); then
echo "$ai_msg"
return 0
fi
fi
generate_commit_message_fallback
}
# Function to check if we're in a git repository and change to repo root
check_git_repo() {
if ! git rev-parse --git-dir >/dev/null 2>&1; then