Hooking the Test into Git: Requirements
Learn how to hook into local Git and get to know the requirements to run the script.
Hooking into local Git
Hooking into the local Git commit process is done by putting the script we want to run in the right directory with the right name. When Git initializes a repository, it creates a subdirectory called .git
in which it tracks our changes. Within that directory, a subdirectory called hooks
has several files named <step>.sample
for various steps in the Git process. The only two that are of interest here are:
- Pre-commit, which runs when we commit
- Pre-push, which runs when we push to a remote repository, usually GitHub or Bitbucket
Requirements to run the script
On a Windows computer, nothing special is needed to prepare the script to run. On Unix-like platforms, that is, Linux, BSD, and Mac, an executable script must have two properties: correct permissions and the shebang line. Every file belongs to both a user and a group. It also has permissions indicating who can read it, modify it (including deletion), and execute it. We can view these permissions with ls -l
at the command line. Below are various typical lines.
Get hands-on with 1200+ tech skills courses.