]> jfr.im git - hooks.git/blame - main/update
init
[hooks.git] / main / update
CommitLineData
5edea21c 1#!/bin/sh
2
3reponame="$(basename "$(readlink -f .)")"
4
5FORMAT="%C(auto)%h by %an (%ah: %s) sig: %G? %GS 0x%GK https://jfr.im/git/$reponame/commitdiff/%h"
6H2I="https://h2i:ef199c443ca3f1f49709dbe79c3758273658fb7cfbb2ff88ab97ef9aedd6bb30@chat.2948.ca/h2i/null"
7
8ref="$1"
9old="$2"
10new="$3"
11
12set -x
13if [ "$old" = "0000000000000000000000000000000000000000" ]; then # new branch
14 commits="created with $(git describe --always "$new")"
15elif [ "$new" = "0000000000000000000000000000000000000000" ]; then # deleted branch
16 commits="deleted from $(git describe --always "$old")"
17elif [ "$old" = "$(git merge-base "$old" "$new")" ]; then # fast-forward update
18 commits="updated from $(git describe --always "$old") -> $(git describe --always "$new")"
19elif [ "$new" = "$(git merge-base "$old" "$new")" ]; then # rollback
20 commits="!! rolled back to $(git describe --always "$new") erasing history through $(git describe --always "$old")"
21else # commit --amend, rebase, or similar
22 commits="!! rewrote history from $(git describe --always "$(git merge-base "$old" "$new")") -> $(git describe --always "$new") erasing history through $(git describe --always "$old")"
23fi
24set +x
25
26curl -sS -d "[$reponame] $ref $commits" "$H2I" >/dev/null
27
28if [ "$old" = "0000000000000000000000000000000000000000" ]; then
29 git show --no-show-signature --no-patch --pretty="tformat:$FORMAT" "$new"
30else
31 git log --no-show-signature --pretty="tformat:$FORMAT" "$old".."$new"
32fi | while read line; do
33 curl -sS -d "$line" "$H2I" >/dev/null
34done