#!/bin/sh # # --- Command line refname="$1" oldrev="$2" newrev="$3" # --- Safety check if [ -z "$GIT_DIR" ]; then echo "Don't run this script from the command line." >&2 echo " (if you want, you could supply GIT_DIR then run" >&2 echo " $0 )" >&2 exit 1 fi if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then echo "usage: $0 " >&2 exit 1 fi # Get the full path of the repository repository=$(readlink -f "$GIT_DIR") ## ## Custom Configuration Options ## ## Allow non-fast-forward commits on branches (except 'master') ## To enable: ## git config hooks.allowbranchnonfastforward true allow_branch_nonfastforward=$(git config --bool hooks.allowbranchnonfastforward) ## Allow non-fast-forward commits on the master branch ## This should be 'false' by default, and only enabled under special ## circumstances. ## To enable: ## git config hooks.allowmasternonfastforward true allow_master_nonfastforward=$(git config --bool hooks.allowmasternonfastforward) ## When a master-branch is updated with non-fast-forward commit, ## notify this email address (e.g address@hidden) address@hidden # --- Check types # if $newrev is 0000...0000, it's a commit to delete a ref. zero="0000000000000000000000000000000000000000" if [ "$newrev" = "$zero" ]; then newrev_type=delete else newrev_type=$(git cat-file -t $newrev) fi case "$refname","$newrev_type" in refs/tags/*,commit) # un-annotated tag ;; refs/tags/*,delete) # delete tag ;; refs/tags/*,tag) # annotated tag ;; refs/heads/*,commit) # commit to a branch # 'revlist' should be empty on a fast-forward commit revlist=$(git rev-list "$newrev".."$oldrev") branch=${refname##refs/heads/} # Non-fast-forard commit? if test -n "$revlist" ; then # non-fast-forward to the master branch? if test "x$branch" = "xmaster" ; then if test "x$allow_master_nonfastforward" != "xtrue" ; then echo \ "*** Rejected: non-fast-forward on the master branch are disabled in Savannah. See http://savannah.gnu.org/maintenance/XXXXXXX for details." exit 1 fi # A non-fast-forward commit is allowed for the master # branch of this repository. # To regulate funkiness, send an email notification. echo "This is an automated message. The master branch of '$repository' is being modified with a non-fast-forward commit. time: $(date -uR) old-revision: $oldrev new-revision: $newrev" \ | mail -s 'Master branch update: $repository' \ "$master_update_notification" else # non-fast-foward to a non-master branch? if test "x$allow_branch_nonfastforward" != "xtrue" ; then echo \ "*** Rejected: non-fast-forward commits on non-master branches are disabled for this repository. See http://savannah.gnu.org/maintenance/XXXXXXX for details." exit 1 fi fi fi ;; refs/heads/*,delete) # delete branch ;; refs/remotes/*,commit) # tracking branch ;; refs/remotes/*,delete) # delete tracking branch ;; *) # Anything else (is there anything else?) echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 exit 1 ;; esac # --- Finished exit 0