TL;DR- Put it in PATH and chmod +x
and enjoy on_git_commit_change.py -c -- command to run every time I make new commit
This script is a Python utility designed to monitor changes in a Git repository and execute a specified command whenever a new commit is detected. Here's a brief breakdown of its functionality:
-
Argument Parsing: The script uses the
argparse
library to handle command-line arguments. These include:-f
or--frequency
: Sets the time (in seconds) between each check for new commits.-s
or--silent
: If specified, suppresses logging output.-a
or--after-change
: Runs the command only after a change is detected, by initialising the current commit.-c
or--clear
: Clears the terminal before logging information about a new commit.command
: The command to be executed when a new commit is detected.
-
Commit Monitoring: It continuously monitors the latest commit in the current Git repository using the
git rev-parse HEAD
command to get the latest commit hash. -
Logging: It logs information to the stderr unless the silent mode is activated.
-
Execution Trigger: Upon detecting a new commit (i.e., a change in the commit hash), it conditionally clears the terminal, logs the new commit, and executes the specified command.
-
Loop: The script runs indefinitely, checking for new commits at intervals specified by the
frequency
argument.