SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
c981f27 verified
Raw
History Blame Contribute Delete
2.38 kB
#!/usr/bin/env zsh
# Git integration action handlers
# Action handler: Directly commit changes with AI-generated message
# Usage: :commit [additional context]
# Note: This action clears the buffer after execution
function _forge_action_commit() {
local additional_context="$1"
local commit_message
# Generate AI commit message
echo
# Force color output even when not connected to TTY
# FORCE_COLOR: for indicatif spinner colors
# CLICOLOR_FORCE: for colored crate text colors
# Build commit command with optional additional context
if [[ -n "$additional_context" ]]; then
commit_message=$(FORCE_COLOR=true CLICOLOR_FORCE=1 $_FORGE_BIN commit --max-diff "$_FORGE_MAX_COMMIT_DIFF" $additional_context)
else
commit_message=$(FORCE_COLOR=true CLICOLOR_FORCE=1 $_FORGE_BIN commit --max-diff "$_FORGE_MAX_COMMIT_DIFF")
fi
_forge_reset
}
# Action handler: Previews AI-generated commit message
# Usage: :commit-preview [additional context]
function _forge_action_commit_preview() {
local additional_context="$1"
local commit_message
# Generate AI commit message
echo
# Force color output even when not connected to TTY
# FORCE_COLOR: for indicatif spinner colors
# CLICOLOR_FORCE: for colored crate text colors
# Build commit command with optional additional context
if [[ -n "$additional_context" ]]; then
commit_message=$(FORCE_COLOR=true CLICOLOR_FORCE=1 $_FORGE_BIN commit --preview --max-diff "$_FORGE_MAX_COMMIT_DIFF" $additional_context)
else
commit_message=$(FORCE_COLOR=true CLICOLOR_FORCE=1 $_FORGE_BIN commit --preview --max-diff "$_FORGE_MAX_COMMIT_DIFF")
fi
# Proceed only if command succeeded
if [[ -n "$commit_message" ]]; then
# Check if there are staged changes to determine commit strategy
if git diff --staged --quiet; then
# No staged changes: commit all tracked changes with -a flag
BUFFER="git commit -am ${(qq)commit_message}"
else
# Staged changes exist: commit only what's staged
BUFFER="git commit -m ${(qq)commit_message}"
fi
# Move cursor to end of buffer for immediate execution
CURSOR=${#BUFFER}
# Refresh display to show the new command
zle reset-prompt
else
_forge_reset
fi
}