post-merge.git-hook 1.4 KB

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