Created
August 13, 2010 20:51
-
-
Save iangreenleaf/523529 to your computer and use it in GitHub Desktop.
Git unsigned merge hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function error_message { | |
echo -e >&2 \ | |
"---------------------------------------------------------------------------------------------------------" \ | |
"\n$1" \ | |
"\n---------------------------------------------------------------------------------------------------------" | |
} | |
function undo_merge { | |
error_message "Undoing your merge. Please fix the problem and try again." | |
git reset --hard ORIG_HEAD | |
} | |
function only_validate_master { | |
branch=`git branch 2>/dev/null | grep '^*' | cut -f2- -d' '` | |
if [ "$branch" != "master" ]; then | |
exit 0 | |
fi | |
} | |
function only_validate_merge_into_master { | |
only_validate_master | |
# If we are merging from origin/master, don't run | |
if [ -z "`git diff HEAD origin/master`" ]; then | |
exit 0; | |
fi | |
} | |
function check_commit_message_against_regexp { | |
msg=`git log HEAD^..HEAD` | |
if [ -z "`echo "$msg" | grep -i "$1"`" ]; then | |
error_message "$2" | |
exit 1 | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
## .git/hooks/post-merge | |
## | |
## Runs all special post-merge hooks | |
## | |
this_dir="$(dirname "$(test -L "$0" && readlink "$0" || echo "$0")")" | |
source "$this_dir/funcs.sh" | |
"$this_dir/require_signoff" && "$this_dir/require_ticket_number" || undo_merge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
## Checks for commits merged to master without a signoff | |
## | |
this_dir="$(dirname "$(test -L "$0" && readlink "$0" || echo "$0")")" | |
source "$this_dir/funcs.sh" | |
only_validate_merge_into_master | |
check_commit_message_against_regexp '^[[:space:]]*Signed-off-by: ' 'It looks like you just merged an unsigned commit! You might want to fix that before you push.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
## Checks for commits merged to master without a ticket number | |
## | |
this_dir="$(dirname "$(test -L "$0" && readlink "$0" || echo "$0")")" | |
source "$this_dir/funcs.sh" | |
only_validate_merge_into_master | |
check_commit_message_against_regexp 'fixes #[[:digit:]]\{1,5\}' 'It looks like you just merged a commit with no ticket number! You might want to fix that before you push.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment