
All checks were successful
Build-Test-Publish / build (linux/arm64) (push) Successful in 25s
Build-Test-Publish / build (linux/amd64) (push) Successful in 46s
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
3.5 KiB
3.5 KiB
GP Script Improvements
Original Script Issues
The original gp
script had several limitations and potential issues:
- No error handling - Script could fail silently or in unexpected ways
- Unsafe operations - Always commits and pushes without confirmation
- Poor commit messages - Generated from diff first line, often meaningless
- No flexibility - Hard-coded to push to
main
branch - No dry-run mode - No way to preview what would happen
- Limited functionality - No help, version, or autocomplete support
- Poor user experience - No colored output or informative messages
Improvements Made
1. Safety and Error Handling
- Strict error handling with
set -euo pipefail
- Git repository validation before any operations
- Change detection to avoid empty commits
- User confirmation before committing (unless
--force
used) - Proper error messages with colored output
2. Enhanced Functionality
- Dry-run mode (
--dry-run
/-n
) to preview changes - Custom commit messages - optional argument overrides auto-generation
- Branch selection (
--branch
/-b
) to push to any branch - Add-all option (
--add-all
/-a
) to include untracked files - Force mode (
--force
/-f
) to skip confirmations
3. Smart Commit Message Generation
- File type detection - recognizes source, config, docs, and test files
- Change type analysis - detects additions, modifications, deletions
- Conventional commit style - uses prefixes like
feat:
,docs:
,test:
- Intelligent descriptions - better context than original script
4. User Experience
- Colored output - different colors for info, warnings, errors, success
- Comprehensive help - detailed usage information and examples
- Status display - shows current branch, repository, and changes
- Progress feedback - clear indication of what's happening
5. Integration Features
- Version command - reports script version
- Autocomplete support - bash completion for options
- Standard CLI conventions - follows common command-line patterns
Usage Examples
Basic Usage
gp # Auto-generate commit message and push
gp "Fix parser bug" # Use custom commit message
Advanced Usage
gp --dry-run # Preview what would be committed
gp --add-all # Include untracked files
gp --branch develop # Push to develop branch
gp --force "Emergency fix" # Skip confirmation prompt
Information Commands
gp --help # Show help
gp version # Show version
gp autocomplete # Show completion options
Benefits
- Safer - Prevents accidental commits and pushes
- More flexible - Works with different workflows and branching strategies
- Better commit history - Generates meaningful commit messages
- User-friendly - Clear feedback and error messages
- Professional - Follows CLI best practices and conventions
- Maintainable - Well-structured code with proper error handling
Backward Compatibility
The improved script maintains backward compatibility:
- Running
gp
without arguments still auto-generates a commit message and pushes - The basic workflow is unchanged
- New features are opt-in through command-line flags
Installation
- Replace the original
gp
script withgp_improved
- Ensure it's executable:
chmod +x gp
- The script works from any directory within a git repository