Make add-all default with user confirmation
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 24s
Build-Test-Publish / build (linux/arm64) (push) Successful in 26s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Successful in 7s
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Successful in 8s
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 24s
Build-Test-Publish / build (linux/arm64) (push) Successful in 26s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Successful in 7s
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Successful in 8s
This commit is contained in:
parent
925dc01b03
commit
511979315d
85
gp/gp
85
gp/gp
@ -31,15 +31,17 @@ OPTIONS:
|
||||
-n, --dry-run Show what would be committed without actually doing it
|
||||
-f, --force Skip safety checks (use with caution)
|
||||
-b, --branch Specify branch to push to (default: current branch)
|
||||
-a, --add-all Add all files including untracked (default: only staged + modified)
|
||||
-a, --add-all Add all files including untracked (default)
|
||||
--staged-only Only commit staged changes (don't add untracked files)
|
||||
|
||||
ARGUMENTS:
|
||||
message Optional custom commit message (overrides auto-generation)
|
||||
|
||||
EXAMPLES:
|
||||
gp # Auto-generate commit message and push
|
||||
gp "Fix bug in parser" # Use custom commit message
|
||||
gp # Add all files, auto-generate commit message and push
|
||||
gp "Fix bug in parser" # Add all files with custom commit message
|
||||
gp --dry-run # Preview what would be committed
|
||||
gp --staged-only # Only commit staged changes (don't add untracked)
|
||||
gp -b develop # Push to develop branch instead of current
|
||||
|
||||
EOF
|
||||
@ -189,28 +191,72 @@ check_for_changes() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to show what would be committed
|
||||
show_status() {
|
||||
# Function to show what would be committed and get user confirmation
|
||||
show_status_and_confirm() {
|
||||
print_info "Current branch: $(git branch --show-current)"
|
||||
print_info "Repository: $(git remote get-url origin 2>/dev/null || echo 'No remote')"
|
||||
echo
|
||||
|
||||
if git diff --cached --quiet; then
|
||||
print_info "Staged changes: None"
|
||||
if ! git diff --quiet; then
|
||||
print_info "Modified files (unstaged):"
|
||||
git diff --name-only | sed 's/^/ /'
|
||||
fi
|
||||
else
|
||||
local has_staged_changes=false
|
||||
local has_unstaged_changes=false
|
||||
local has_untracked_files=false
|
||||
|
||||
# Show staged changes
|
||||
if ! git diff --cached --quiet; then
|
||||
print_info "Staged changes:"
|
||||
git diff --cached --name-only | sed 's/^/ /'
|
||||
has_staged_changes=true
|
||||
fi
|
||||
|
||||
# Show unstaged changes
|
||||
if ! git diff --quiet; then
|
||||
if [ "$ADD_ALL" = true ]; then
|
||||
print_info "Modified files (will be added):"
|
||||
else
|
||||
print_info "Modified files (unstaged, will NOT be included):"
|
||||
fi
|
||||
git diff --name-only | sed 's/^/ /'
|
||||
has_unstaged_changes=true
|
||||
fi
|
||||
|
||||
# Show untracked files
|
||||
if [ "$ADD_ALL" = true ]; then
|
||||
local untracked=$(git ls-files --others --exclude-standard)
|
||||
if [ -n "$untracked" ]; then
|
||||
print_info "Untracked files (will be added):"
|
||||
echo "$untracked" | sed 's/^/ /'
|
||||
has_untracked_files=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# Show summary of what will happen
|
||||
echo
|
||||
if [ "$ADD_ALL" = true ]; then
|
||||
if [ "$has_unstaged_changes" = true ] || [ "$has_untracked_files" = true ]; then
|
||||
print_warning "Files will be automatically added before committing"
|
||||
fi
|
||||
if [ "$has_staged_changes" = false ] && [ "$has_unstaged_changes" = false ] && [ "$has_untracked_files" = false ]; then
|
||||
print_info "No changes found to commit"
|
||||
fi
|
||||
else
|
||||
if [ "$has_unstaged_changes" = true ]; then
|
||||
print_warning "Unstaged changes will NOT be included (use -a to include them)"
|
||||
fi
|
||||
if [ "$has_staged_changes" = false ]; then
|
||||
print_info "No staged changes to commit"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Confirmation for file additions (unless forced or dry-run)
|
||||
if [ "$ADD_ALL" = true ] && [ "$FORCE" = false ] && [ "$DRY_RUN" = false ]; then
|
||||
if [ "$has_unstaged_changes" = true ] || [ "$has_untracked_files" = true ]; then
|
||||
echo
|
||||
read -p "Add these files and continue? [y/N] " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_info "Aborted by user"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@ -245,14 +291,14 @@ do_commit_and_push() {
|
||||
autocomplete() {
|
||||
local args=("$@")
|
||||
if [ ${#args[@]} -eq 0 ]; then
|
||||
printf "%s\n" "--help" "--dry-run" "--force" "--add-all" "--branch" "-h" "-n" "-f" "-a" "-b"
|
||||
printf "%s\n" "--help" "--dry-run" "--force" "--add-all" "--staged-only" "--branch" "-h" "-n" "-f" "-a" "-b"
|
||||
fi
|
||||
}
|
||||
|
||||
# Default values
|
||||
DRY_RUN=false
|
||||
FORCE=false
|
||||
ADD_ALL=false
|
||||
ADD_ALL=true # Default to adding all files
|
||||
CUSTOM_MESSAGE=""
|
||||
TARGET_BRANCH=""
|
||||
PUSH_ONLY=false
|
||||
@ -286,7 +332,11 @@ while [[ $# -gt 0 ]]; do
|
||||
shift
|
||||
;;
|
||||
-a|--add-all)
|
||||
ADD_ALL=true
|
||||
ADD_ALL=true # Explicitly set (though it's default)
|
||||
shift
|
||||
;;
|
||||
--staged-only)
|
||||
ADD_ALL=false
|
||||
shift
|
||||
;;
|
||||
-b|--branch)
|
||||
@ -352,9 +402,8 @@ main() {
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Show current status
|
||||
show_status
|
||||
echo
|
||||
# Show current status and get confirmation for file additions
|
||||
show_status_and_confirm
|
||||
|
||||
# Generate or use custom commit message
|
||||
if [ -n "$CUSTOM_MESSAGE" ]; then
|
||||
|
Loading…
x
Reference in New Issue
Block a user