Update gp
This commit is contained in:
47
gp
47
gp
@@ -49,8 +49,39 @@ EXAMPLES:
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to generate commit message based on changes
|
# Function to generate commit message using Claude AI
|
||||||
generate_commit_message() {
|
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
|
# First check if we have staged changes
|
||||||
local has_staged_changes=false
|
local has_staged_changes=false
|
||||||
if ! git diff --cached --quiet; then
|
if ! git diff --cached --quiet; then
|
||||||
@@ -204,6 +235,18 @@ generate_commit_message() {
|
|||||||
echo "$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
|
# Function to check if we're in a git repository and change to repo root
|
||||||
check_git_repo() {
|
check_git_repo() {
|
||||||
if ! git rev-parse --git-dir >/dev/null 2>&1; then
|
if ! git rev-parse --git-dir >/dev/null 2>&1; then
|
||||||
|
|||||||
Reference in New Issue
Block a user