Skip to content

Instantly share code, notes, and snippets.

@basilfx
Last active August 29, 2015 14:24
Show Gist options
  • Save basilfx/70c6a10b263476d793ca to your computer and use it in GitHub Desktop.
Save basilfx/70c6a10b263476d793ca to your computer and use it in GitHub Desktop.
Git Check Before Add
#!/usr/bin/env python
import sys
def main():
"""
Main entry point.
"""
if "commit -am" in " ".join(sys.argv).lower():
sys.stdout.write("Confirm add-then-commit [yN]: ")
if sys.stdin.read(1).lower() != "y":
return 1
# E.g. `python git-check-add.py`
if __name__ == "__main__":
sys.exit(main())

Installation

Add this to your .bashrc or similar:

# Add function to catch arguments.
check_git() { 
    python git-check-before-add.py $* && git $*
}

# Replace git command
alias git=check_git

# Restore autocomplete
compdef git_check=git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment