post-merge.git-hook (1441B)
1 #!/bin/sh 2 3 # This is post-merge git hook script to check for changes in: 4 # * git hook scripts 5 # * helper scripts for using git efficiently. 6 # If any changes are detected, a diff of them is printed. 7 # 8 # To install this script, copy it to .git/hooks/post-merge in local copy of 9 # tor git repo and make sure it has permission to execute. 10 11 git_toplevel=$(git rev-parse --show-toplevel) 12 13 check_for_diffs() { 14 installed="$git_toplevel/.git/hooks/$1" 15 latest="$git_toplevel/scripts/git/$1.git-hook" 16 17 if [ -e "$installed" ] 18 then 19 if ! cmp "$installed" "$latest" >/dev/null 2>&1 20 then 21 echo "ATTENTION: $1 hook has changed:" 22 echo "===============================" 23 diff -u "$installed" "$latest" 24 fi 25 fi 26 } 27 28 check_for_script_update() { 29 fullpath="$1" 30 31 if ! git diff ORIG_HEAD HEAD --exit-code -- "$fullpath" >/dev/null 32 then 33 echo "ATTENTION: $1 has changed:" 34 git --no-pager diff ORIG_HEAD HEAD -- "$fullpath" 35 fi 36 } 37 38 cur_branch=$(git rev-parse --abbrev-ref HEAD) 39 if [ "$cur_branch" != "main" ]; then 40 echo "post-merge: Not a main branch. Skipping." 41 exit 0 42 fi 43 44 check_for_diffs "pre-push" 45 check_for_diffs "pre-commit" 46 check_for_diffs "post-merge" 47 48 for file in "$git_toplevel"/scripts/git/* ; do 49 check_for_script_update "$file" 50 done 51