File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ # Git Hooks
2+
3+ These are scripts executed by Git at specific steps of the version control workflow, depending on their name.
4+
5+ - ` pre-commit ` runs before attempting to commit, and prevents committing to the local master branch.
6+
7+ To install,
8+ ``` bash
9+ $ ./install_hooks.bash
10+ ```
11+
12+ To read more about hooks, read the [ Pro Git chapter] ( https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks ) .
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ set -o errexit
4+
5+ # Grab the directory of _this_ script.
6+ SCRIPTDIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
7+ PROJECTDIR=" $( realpath " ${SCRIPTDIR} " /../..) "
8+
9+ # Try to link each hook into the project's .git/hooks directory.
10+ for hook in $( ls " ${SCRIPTDIR} " /* .hook) ; do
11+ stub=" ${hook% .* } "
12+ dest=" ${PROJECTDIR} /.git/hooks/$( basename ${stub} ) "
13+ ln -sv " ${hook} " " ${dest} "
14+ done
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env sh
2+
3+ # prevent commit to local master branch
4+ # taken from https://gist.github.com/aaronhoffman/ffbfd36928f9336be2436cffe39feaec#file-pre-commit
5+
6+ branch=` git symbolic-ref HEAD`
7+ if [ " $branch " = " refs/heads/master" ]; then
8+ echo " pre-commit hook: Cannot commit to the local master branch."
9+ echo " Please make all your changes in a new feature branch:"
10+ echo " $ git checkout -b my-new-feature-branch"
11+ exit 1
12+ fi
13+
14+ exit 0
You can’t perform that action at this time.
0 commit comments