aboutsummaryrefslogtreecommitdiff
path: root/scripts/git/post-merge.git-hook
blob: eae4f999e79c4ade2caa75575841f80f03ad4ea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh

# This is post-merge git hook script to check for changes in:
# * git hook scripts
# * helper scripts for using git efficiently.
# If any changes are detected, a diff of them is printed.
#
# To install this script, copy it to .git/hooks/post-merge in local copy of
# tor git repo and make sure it has permission to execute.

git_toplevel=$(git rev-parse --show-toplevel)

check_for_diffs() {
        installed="$git_toplevel/.git/hooks/$1"
        latest="$git_toplevel/scripts/git/$1.git-hook"

        if [ -e "$installed" ]
        then
               if ! cmp "$installed" "$latest" >/dev/null 2>&1
               then
                        echo "ATTENTION: $1 hook has changed:"
                        echo "==============================="
                        diff -u "$installed" "$latest"
               fi
        fi
}

check_for_script_update() {
        fullpath="$1"

        if ! git diff ORIG_HEAD HEAD --exit-code -- "$fullpath" >/dev/null
        then
                echo "ATTENTION: $1 has changed:"
                git --no-pager diff ORIG_HEAD HEAD -- "$fullpath"
        fi
}

cur_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$cur_branch" != "master" ]; then
  echo "post-merge: Not a master branch. Skipping."
  exit 0
fi

check_for_diffs "pre-push"
check_for_diffs "pre-commit"
check_for_diffs "post-merge"

for file in "$git_toplevel"/scripts/git/* ; do
        check_for_script_update "$file"
done