blob: b82a0fc20c39cc8cf1b669a9865757293b3d5e31 (
about) (
plain) (
blame)
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
|
#!/bin/bash
default_branch="$(git rev-parse --abbrev-ref HEAD)"
default_branch_path="$(git rev-parse --symbolic-full-name HEAD)"
suppress="$(git config --get --type bool --default=false hooks.suppressNotify)"
allowForcePush="$(git config --type=bool hooks.allowForcePush)"
protectedRefs="$(git config --default "$default_branch_path" hooks.protectedRefs)"
addlNotify="$(git config get --value '^([a-zA-Z0-9_.-]+|[0-9.]+|[0-9a-fA-F:.]+):[0-9]{1,5}$' hooks.notify)"
config="$(dirname "$(readlink -f "$0")")"/sh.conf
[ -r "$config" ] && source "$config"
reponame="$(readlink -f .)"
#reponame="${reponame%/.git}"
reponame="${reponame#/home/}"
FORMAT="%C(auto)%h by %an (%ah: %s) sig: %G? %GS 0x%GK https://cgit.space/~$reponame/commit/?id=%h"
ref="$1"
old="$2"
new="$3"
commits=""
forced=""
if ((16#$old == 0)); then # new branch
:
elif ((16#$new == 0)); then # deleted branch
commits="!! deleted branch"
elif [ "$old" = "$(git merge-base "$old" "$new")" ]; then # fast-forward update
:
elif [ "$new" = "$(git merge-base "$old" "$new")" ]; then # rollback
commits="!! rolled back to $(git describe --always "$new") erasing history through $(git describe --always "$old")"
forced="true"
else # commit --amend, rebase, or similar
commits="!! rewrote history from $(git describe --always "$(git merge-base "$old" "$new")") -> $(git describe --always "$new") erasing history through $(git describe --always "$old")"
forced="true"
fi
#curl -sS -d "[$reponame] $ref $commits" "$H2I" >/dev/null
if [ "$forced" = "true" ]; then
if [[ $allowForcePush != "true" && $ref =~ $protectedRefs ]]; then
echo "[$reponame] BLOCKED $ref $commits by $USER" | tee >(notify)
echo "('git config set hooks.allowForcePush true' on repo to allow)" | tee >(notify)
exit 1
else
: # notify allowed force push?
fi
fi
exit 0
|