Skip to content

bakedb/commit-script-generator

Repository files navigation

Git Commit Script Generator

A Python script that generates customized bash scripts for automated git commits with various configuration options.

Note: This script is designed for UNIX (Linux, macOS, BSD, etc.) systems. It may not work as expected (if at all) on Windows.

Features

  • Flexible change tracking: Track all changes, staged changes only, or custom files/patterns
  • Commit message customization: Add prefixes and suffixes to commit messages
  • Multiple repository support: Push to one or more repositories
  • Pre/post command execution: Run custom commands before and after git operations
  • Branch management: Optionally switch to specific branches before pushing
  • Error handling: Robust error checking and colored output
  • Backup creation: Automatically backs up existing scripts

Usage

Generate a Custom Script

Run the generator and follow the interactive prompts:

python generate_commit_script.py

The generator will ask for:

  1. Script name: Name of the generated bash script (default: auto_commit.sh)
  2. Change tracking: What changes to track
    • All changes (git add .)
    • Staged changes only
    • Custom files/patterns
  3. Commit message formatting: Optional prefix and suffix
  4. Target branch: Branch to push to (optional)
  5. Push repositories: List of repositories to push to
  6. Pre-commands: Commands to run before committing
  7. Post-commands: Commands to run after pushing

Use the Generated Script

Once generated, use your script like this:

./auto_commit.sh "Your commit message here"

Example Configurations

Basic Usage

Generate a simple script that commits all changes and pushes to origin:

# Generator inputs:
# Script name: auto_commit.sh
# Track changes: All changes
# Commit prefix: [feat]
# Push repositories: origin

# Usage:
./auto_commit.sh "Add new feature"
# Results in commit message: [feat] Add new feature

Advanced Usage with Pre/Post Commands

# Generator inputs:
# Script name: deploy.sh
# Track changes: Custom files (*.py, *.js)
# Commit prefix: [deploy]
# Commit suffix: - automated
# Target branch: main
# Push repositories: origin, backup
# Pre-commands: npm test, python -m pytest
# Post-commands: npm run build, docker-compose up -d

# Usage:
./deploy.sh "Update application"
# Results in commit message: [deploy] Update application - automated

Custom File Patterns

# Generator inputs:
# Track changes: Custom files
# Files to track:
#   src/*.py
#   docs/*.md
#   requirements.txt

# Generated script will only commit these specific files

Generated Script Features

The generated bash scripts include:

  • Error handling: Exit on any error with descriptive messages
  • Colored output: Info, success, and error messages with colors
  • Git repository validation: Check if running in a git repository
  • Change detection: Skip commit if no changes exist
  • Parameter validation: Require commit message as parameter
  • Executable permissions: Automatically made executable

File Structure

Commit Script Generator/
├── generate_commit_script.py  # Main generator script
├── README.md                  # This documentation
└── auto_commit.sh            # Generated script (example)

Requirements

  • Python 3.6+
  • Git
  • Bash shell

Customization Options

Change Tracking Modes

  1. All changes: git add . - Tracks all modified and new files
  2. Staged only: Uses already staged files, no git add commands
  3. Custom: Specific files/patterns you define

Commit Message Format

  • Prefix: Text added before the commit message
  • Suffix: Text added after the commit message
  • Example: With prefix [feat] and suffix - automated, message "Fix bug" becomes [feat] Fix bug - automated

Repository Pushing

  • Single or multiple repositories
  • Branch-specific pushing
  • Current branch or specified branch

Command Execution

  • Pre-commands: Run before git operations (e.g., tests, linting)
  • Post-commands: Run after successful push (e.g., deployment, notifications)
  • Commands are executed with error checking

Troubleshooting

Script Permission Denied

chmod +x your_script_name.sh

Git Repository Not Found

Ensure you're running the script in a directory with a .git folder.

Pre/Post Commands Fail

Commands are executed with set -e, so any failing command will stop the script. Make sure your commands are properly formatted and accessible.

Examples

Development Workflow Script

# Generator configuration for development:
# - Track: All changes
# - Prefix: [dev]
# - Pre-commands: npm run lint, npm test
# - Post-commands: npm run dev

./dev_commit.sh "Implement user authentication"

Deployment Script

# Generator configuration for deployment:
# - Track: Custom files (dist/, package.json)
# - Prefix: [deploy]
# - Branch: production
# - Pre-commands: npm run build
# - Post-commands: pm2 reload all

./deploy.sh "Version 1.2.0"

Documentation Update Script

# Generator configuration for docs:
# - Track: Custom files (*.md, docs/**)
# - Prefix: [docs]
# - Push repositories: origin, docs-fork

./docs_commit.sh "Update API documentation"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published