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
|
-n, --dry-run Show what would be committed without actually doing it
|
||||||
-f, --force Skip safety checks (use with caution)
|
-f, --force Skip safety checks (use with caution)
|
||||||
-b, --branch Specify branch to push to (default: current branch)
|
-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:
|
ARGUMENTS:
|
||||||
message Optional custom commit message (overrides auto-generation)
|
message Optional custom commit message (overrides auto-generation)
|
||||||
|
|
||||||
EXAMPLES:
|
EXAMPLES:
|
||||||
gp # Auto-generate commit message and push
|
gp # Add all files, auto-generate commit message and push
|
||||||
gp "Fix bug in parser" # Use custom commit message
|
gp "Fix bug in parser" # Add all files with custom commit message
|
||||||
gp --dry-run # Preview what would be committed
|
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
|
gp -b develop # Push to develop branch instead of current
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
@ -189,28 +191,72 @@ check_for_changes() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to show what would be committed
|
# Function to show what would be committed and get user confirmation
|
||||||
show_status() {
|
show_status_and_confirm() {
|
||||||
print_info "Current branch: $(git branch --show-current)"
|
print_info "Current branch: $(git branch --show-current)"
|
||||||
print_info "Repository: $(git remote get-url origin 2>/dev/null || echo 'No remote')"
|
print_info "Repository: $(git remote get-url origin 2>/dev/null || echo 'No remote')"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
if git diff --cached --quiet; then
|
local has_staged_changes=false
|
||||||
print_info "Staged changes: None"
|
local has_unstaged_changes=false
|
||||||
if ! git diff --quiet; then
|
local has_untracked_files=false
|
||||||
print_info "Modified files (unstaged):"
|
|
||||||
git diff --name-only | sed 's/^/ /'
|
# Show staged changes
|
||||||
fi
|
if ! git diff --cached --quiet; then
|
||||||
else
|
|
||||||
print_info "Staged changes:"
|
print_info "Staged changes:"
|
||||||
git diff --cached --name-only | sed 's/^/ /'
|
git diff --cached --name-only | sed 's/^/ /'
|
||||||
|
has_staged_changes=true
|
||||||
fi
|
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
|
if [ "$ADD_ALL" = true ]; then
|
||||||
local untracked=$(git ls-files --others --exclude-standard)
|
local untracked=$(git ls-files --others --exclude-standard)
|
||||||
if [ -n "$untracked" ]; then
|
if [ -n "$untracked" ]; then
|
||||||
print_info "Untracked files (will be added):"
|
print_info "Untracked files (will be added):"
|
||||||
echo "$untracked" | sed 's/^/ /'
|
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
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -245,14 +291,14 @@ do_commit_and_push() {
|
|||||||
autocomplete() {
|
autocomplete() {
|
||||||
local args=("$@")
|
local args=("$@")
|
||||||
if [ ${#args[@]} -eq 0 ]; then
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Default values
|
# Default values
|
||||||
DRY_RUN=false
|
DRY_RUN=false
|
||||||
FORCE=false
|
FORCE=false
|
||||||
ADD_ALL=false
|
ADD_ALL=true # Default to adding all files
|
||||||
CUSTOM_MESSAGE=""
|
CUSTOM_MESSAGE=""
|
||||||
TARGET_BRANCH=""
|
TARGET_BRANCH=""
|
||||||
PUSH_ONLY=false
|
PUSH_ONLY=false
|
||||||
@ -286,7 +332,11 @@ while [[ $# -gt 0 ]]; do
|
|||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-a|--add-all)
|
-a|--add-all)
|
||||||
ADD_ALL=true
|
ADD_ALL=true # Explicitly set (though it's default)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--staged-only)
|
||||||
|
ADD_ALL=false
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-b|--branch)
|
-b|--branch)
|
||||||
@ -352,9 +402,8 @@ main() {
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Show current status
|
# Show current status and get confirmation for file additions
|
||||||
show_status
|
show_status_and_confirm
|
||||||
echo
|
|
||||||
|
|
||||||
# Generate or use custom commit message
|
# Generate or use custom commit message
|
||||||
if [ -n "$CUSTOM_MESSAGE" ]; then
|
if [ -n "$CUSTOM_MESSAGE" ]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user