]> jfr.im git - hooks.git/commitdiff
use erebus instead of h2i main
authorgit <redacted>
Wed, 11 Sep 2024 19:10:57 +0000 (13:10 -0600)
committergit <redacted>
Wed, 11 Sep 2024 19:10:57 +0000 (13:10 -0600)
main/update
master/update

index 4ef25a1e4fe67fc16cda552ba3209c364f6cc3f6..858b67153e1d97858ba46e9256f4d12a855f9202 100755 (executable)
@@ -1,14 +1,21 @@
-#!/bin/sh
+#!/bin/bash
 
 reponame="$(basename "$(readlink -f .)")"
 
 FORMAT="%C(auto)%h by %an (%ah: %s) sig: %G? %GS 0x%GK https://jfr.im/git/$reponame/commitdiff/%h"
-H2I="https://h2i:ef199c443ca3f1f49709dbe79c3758273658fb7cfbb2ff88ab97ef9aedd6bb30@chat.2948.ca/h2i/null"
+#H2I="https://h2i:ef199c443ca3f1f49709dbe79c3758273658fb7cfbb2ff88ab97ef9aedd6bb30@chat.2948.ca/h2i/null"
+NC=( nc -q 0 10.0.0.2 13336 )
 
 ref="$1"
 old="$2"
 new="$3"
 
+allowForcePush="$(git config --type=bool hooks.allowForcePush)"
+protectedRefs="$(git config --default refs/heads/main hooks.protectedRefs)"
+
+commits=""
+forced=""
+
 if [ "$old" = "0000000000000000000000000000000000000000" ]; then # new branch
        commits="created with $(git describe --always "$new")"
 elif [ "$new" = "0000000000000000000000000000000000000000" ]; then # deleted branch
@@ -17,16 +24,27 @@ elif [ "$old" = "$(git merge-base "$old" "$new")" ]; then # fast-forward update
        commits="updated from $(git describe --always "$old") -> $(git describe --always "$new")"
 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
+#curl -sS -d "[$reponame] $ref $commits" "$H2I" >/dev/null
+echo "[$reponame] $ref $commits" | "${NC[@]}" >/dev/null
 
 if [ "$old" = "0000000000000000000000000000000000000000" ]; then
        git show --no-show-signature --no-patch --pretty="tformat:$FORMAT" "$new"
 else
        git log --no-show-signature --pretty="tformat:$FORMAT" "$old".."$new"
 fi | while read line; do
-               curl -sS -d "$line" "$H2I" >/dev/null
+               : #curl -sS -d "$line" "$H2I" >/dev/null
+               echo "$line" | "${NC[@]}" >/dev/null
 done
+
+if [[ $forced == "true" && $allowForcePush != "true" && $ref =~ $protectedRefs ]]; then
+       echo "(BLOCKED PUSH, 'git config hooks.allowForcePush true' on server to allow)" | "${NC[@]}" >/dev/null
+       exit 1
+fi
+
+exit 0
index 4ef25a1e4fe67fc16cda552ba3209c364f6cc3f6..591aef7e1d025addb4861792605c78bf7ba63437 100755 (executable)
@@ -1,14 +1,21 @@
-#!/bin/sh
+#!/bin/bash
 
 reponame="$(basename "$(readlink -f .)")"
 
 FORMAT="%C(auto)%h by %an (%ah: %s) sig: %G? %GS 0x%GK https://jfr.im/git/$reponame/commitdiff/%h"
-H2I="https://h2i:ef199c443ca3f1f49709dbe79c3758273658fb7cfbb2ff88ab97ef9aedd6bb30@chat.2948.ca/h2i/null"
+#H2I="https://h2i:ef199c443ca3f1f49709dbe79c3758273658fb7cfbb2ff88ab97ef9aedd6bb30@chat.2948.ca/h2i/null"
+NC=( nc -q 0 10.0.0.2 13336 )
 
 ref="$1"
 old="$2"
 new="$3"
 
+allowForcePush="$(git config --type=bool hooks.allowForcePush)"
+protectedRefs="$(git config --default refs/heads/master hooks.protectedRefs)"
+
+commits=""
+forced=""
+
 if [ "$old" = "0000000000000000000000000000000000000000" ]; then # new branch
        commits="created with $(git describe --always "$new")"
 elif [ "$new" = "0000000000000000000000000000000000000000" ]; then # deleted branch
@@ -17,16 +24,27 @@ elif [ "$old" = "$(git merge-base "$old" "$new")" ]; then # fast-forward update
        commits="updated from $(git describe --always "$old") -> $(git describe --always "$new")"
 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
+#curl -sS -d "[$reponame] $ref $commits" "$H2I" >/dev/null
+echo "[$reponame] $ref $commits" | "${NC[@]}" >/dev/null
 
 if [ "$old" = "0000000000000000000000000000000000000000" ]; then
        git show --no-show-signature --no-patch --pretty="tformat:$FORMAT" "$new"
 else
        git log --no-show-signature --pretty="tformat:$FORMAT" "$old".."$new"
 fi | while read line; do
-               curl -sS -d "$line" "$H2I" >/dev/null
+               : #curl -sS -d "$line" "$H2I" >/dev/null
+               echo "$line" | "${NC[@]}" >/dev/null
 done
+
+if [[ $forced == "true" && $allowForcePush != "true" && $ref =~ $protectedRefs ]]; then
+       echo "(BLOCKED PUSH, 'git config hooks.allowForcePush true' on server to allow)" | "${NC[@]}" >/dev/null
+       exit 1
+fi
+
+exit 0