-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.hook
executable file
·67 lines (56 loc) · 1.51 KB
/
update.hook
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
# INSTRUCTIONS:
#
# To install this file: copy it as <git repo>/.git/hooks/update into
# your repository. Before the revision of a branch is set to the new
# commit, every changed file since the actual revision of the branch
# will be checked by running the $CHECK_COMMAND and piping the files
# new content in that process. If the process was successful (exit
# code == 0), the file will be accepted.
CHECK_COMMAND="false"
# --- 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 <ref> <oldrev> <newrev>)" >&2
exit 1
fi
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
echo "usage: $0 <ref> <oldrev> <newrev>" >&2
exit 1
fi
# --- Check types
zero="0000000000000000000000000000000000000000"
if [ "$newrev" = "$zero" ]; then
newrev_type=delete
else
newrev_type=$(git cat-file -t $newrev)
fi
#echo "refname: $refname"
#echo "oldrev: $oldrev"
#echo "newrev: $newrev"
#echo "newrev_type: $newrev_type"
files="$(git diff-tree --no-commit-id --name-only -r $newrev $refname | tr "\n" " ")"
echo "Affected files: $files"
case "$refname","$newrev_type" in
refs/heads/*,commit)
state=ok
for f in $files; do
if ! git cat-file --textconv $newrev:$f | $CHECK_COMMAND; then
state=failed
echo "File $f is corrupted."
fi
done;
if [ "$state" == "failed" ]; then
exit 1
fi;
echo "success! :)"
;;
*)
;;
esac
exit 0