]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/bash | |
2 | ||
3 | reponame="$(basename "$(readlink -f .)")" | |
4 | ||
5 | FORMAT="%C(auto)%h by %an (%ah: %s) sig: %G? %GS 0x%GK https://jfr.im/git/$reponame/commitdiff/%h" | |
6 | #H2I="https://h2i:ef199c443ca3f1f49709dbe79c3758273658fb7cfbb2ff88ab97ef9aedd6bb30@chat.2948.ca/h2i/null" | |
7 | NC=( nc -q 0 10.0.0.2 13336 ) | |
8 | ||
9 | ref="$1" | |
10 | old="$2" | |
11 | new="$3" | |
12 | ||
13 | allowForcePush="$(git config --type=bool hooks.allowForcePush)" | |
14 | protectedRefs="$(git config --default refs/heads/main hooks.protectedRefs)" | |
15 | ||
16 | commits="" | |
17 | forced="" | |
18 | ||
19 | if [ "$old" = "0000000000000000000000000000000000000000" ]; then # new branch | |
20 | commits="created with $(git describe --always "$new")" | |
21 | elif [ "$new" = "0000000000000000000000000000000000000000" ]; then # deleted branch | |
22 | commits="deleted from $(git describe --always "$old")" | |
23 | elif [ "$old" = "$(git merge-base "$old" "$new")" ]; then # fast-forward update | |
24 | commits="updated from $(git describe --always "$old") -> $(git describe --always "$new")" | |
25 | elif [ "$new" = "$(git merge-base "$old" "$new")" ]; then # rollback | |
26 | commits="!! rolled back to $(git describe --always "$new") erasing history through $(git describe --always "$old")" | |
27 | forced="true" | |
28 | else # commit --amend, rebase, or similar | |
29 | commits="!! rewrote history from $(git describe --always "$(git merge-base "$old" "$new")") -> $(git describe --always "$new") erasing history through $(git describe --always "$old")" | |
30 | forced="true" | |
31 | fi | |
32 | ||
33 | #curl -sS -d "[$reponame] $ref $commits" "$H2I" >/dev/null | |
34 | echo "[$reponame] $ref $commits" | "${NC[@]}" >/dev/null | |
35 | ||
36 | if [ "$old" = "0000000000000000000000000000000000000000" ]; then | |
37 | git show --no-show-signature --no-patch --pretty="tformat:$FORMAT" "$new" | |
38 | else | |
39 | git log --no-show-signature --pretty="tformat:$FORMAT" "$old".."$new" | |
40 | fi | while read line; do | |
41 | : #curl -sS -d "$line" "$H2I" >/dev/null | |
42 | echo "$line" | "${NC[@]}" >/dev/null | |
43 | done | |
44 | ||
45 | if [[ $forced == "true" && $allowForcePush != "true" && $ref =~ $protectedRefs ]]; then | |
46 | echo "(BLOCKED PUSH, 'git config hooks.allowForcePush true' on server to allow)" | "${NC[@]}" >/dev/null | |
47 | exit 1 | |
48 | fi | |
49 | ||
50 | exit 0 |