summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar steering7253 <steering7253@proton.me>2026-04-18 03:55:33 -0600
committerGravatar steering7253 <steering7253@proton.me>2026-04-18 03:55:33 -0600
commitb672cd74f9cf11844e8adcbee98a84ecfa9095ea (patch)
tree21aafc45ee94d9a6cb3fb04318100f903c9512f9
-rw-r--r--.gitignore1
l---------post-commit1
l---------post-merge1
-rwxr-xr-xpost-update16
-rwxr-xr-xupdate57
5 files changed, 76 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fee9217
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.conf
diff --git a/post-commit b/post-commit
new file mode 120000
index 0000000..e92df4e
--- /dev/null
+++ b/post-commit
@@ -0,0 +1 @@
+post-update \ No newline at end of file
diff --git a/post-merge b/post-merge
new file mode 120000
index 0000000..e92df4e
--- /dev/null
+++ b/post-merge
@@ -0,0 +1 @@
+post-update \ No newline at end of file
diff --git a/post-update b/post-update
new file mode 100755
index 0000000..bef2cac
--- /dev/null
+++ b/post-update
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+default_branch="$(git rev-parse --abbrev-ref HEAD)"
+default_branch_path="$(git rev-parse --symbolic-full-name HEAD)"
+
+if git show "$default_branch":README.md >/dev/null 2>&1; then
+ git show "$default_branch":README.md | tee info/web/README.md | cmark >info/web/README.html
+else
+ if git show "$default_branch":README.html >/dev/null 2>&1; then
+ git show "$default_branch":README.html >info/web/README.html
+ else
+ rm -f info/web/README.html
+ fi
+fi
+TZ= date +'%Y-%m-%d %H:%M:%S %z' >last-modified
+exec git update-server-info
diff --git a/update b/update
new file mode 100755
index 0000000..5f1efd4
--- /dev/null
+++ b/update
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+default_branch="$(git rev-parse --abbrev-ref HEAD)"
+default_branch_path="$(git rev-parse --symbolic-full-name HEAD)"
+
+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"
+NC=( nc -q 0 "${to_host:-127.0.0.1}" "${to_port:-1337}" )
+
+ref="$1"
+old="$2"
+new="$3"
+
+allowForcePush="$(git config --type=bool hooks.allowForcePush)"
+protectedRefs="$(git config --default "$default_branch_path" hooks.protectedRefs)"
+
+commits=""
+forced=""
+
+if [ "$old" = "0000000000000000000000000000000000000000" ]; then # new branch
+ commits="created with $(git describe --always "$new")"
+elif [ "$new" = "0000000000000000000000000000000000000000" ]; then # deleted branch
+ commits="deleted from $(git describe --always "$old")"
+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
+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
+ 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