commit c69d0dbe11b44251d686b3d8492f01bdb344b12f
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Sun, 19 Oct 2025 11:33:13 -0500
Add functional initial version
Diffstat:
7 files changed, 202 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,21 @@
+SCRIPTS =\
+ stagit-hook\
+ stagit-hook-hook\
+ stagit-hook-install\
+
+PREFIX = /usr/local/
+MANPREFIX = ${PREFIX}/man
+
+install:
+.for s in ${SCRIPTS}
+ install -o root -g bin -m 755 $s ${PREFIX}/bin/$s
+.endfor
+ install -o root -g bin -m 644 stagit-hook.1 ${MANPREFIX}/man1/stagit-hook.1
+ install -o root -g bin -m 644 stagit-hook.5 ${MANPREFIX}/man5/stagit-hook.5
+ makewhatis -d ${MANPREFIX} ${MANPREFIX}/man1/stagit-hook.1 ${MANPREFIX}/man5/stagit-hook.5
+
+uninstall:
+.for s in ${SCRIPTS}
+ rm -f /usr/local/bin/$s
+.endfor
+ rm -f ${MANPREFIX}/man1/stagit-hook.1 ${MANPREFIX}/man5/stagit-hook.5
diff --git a/README b/README
@@ -0,0 +1,7 @@
+stagit-hook
+===========
+
+The stagit-hook project provides an easy interface to maintain
+post-update git hooks to run
+[stagit](https://codemadness.org/git/stagit/log.html)(*1*) on your
+public repositories.
diff --git a/stagit-hook b/stagit-hook
@@ -0,0 +1,88 @@
+#!/bin/sh
+
+err() {
+ echo "$@" 1>&2
+ exit 1
+}
+
+# Lists repositories we want in the index, sorted by most recent
+# commit. While it's not the best way, any repository with the
+# post-update hook is listed. (So long as you haven't changed the
+# hooks directory.)
+hooked() (
+ find "$HOME" -maxdepth 3 -path '*/hooks/post-update' | sed s./hooks/post-update$.. |
+ while read dir
+ do (
+ cd "$dir"
+ git show -s --format="%ct $dir" ||
+ err "$dir: Unable to get repo information"
+ ) done | sort -rn | cut -f2-
+)
+
+index() {
+ hooked | xargs stagit-index > "$basedir"/index.html
+}
+
+repo() {
+ abs="$(readlink -f "$1")"
+ nam="$(basename "$abs")"
+ dir="$basedir"/"$nam"
+ mkdir -p "$dir"
+ cd "$dir"
+ stagit -u "$baseurl" "$abs"
+}
+
+loadconfig() {
+ if test -f "$rc"
+ then
+ while read key val
+ do
+ case $key in
+ (basedir) basedir="$val" ;;
+ (baseurl) baseurl="$val" ;;
+ (*) err 'Invalid configuration'
+ esac
+ done < "$rc"
+ fi
+}
+
+rc=/etc/stagit-hook
+host="$(hostname)"
+basedir=/var/www/htdocs/"$host"/projects/
+baseurl=https://"$host"/projects/
+
+loadconfig
+
+if test $# -gt 0
+then
+ case "$1" in
+ (install)
+ shift
+ stagit-hook-install "$@"
+ "$0" reindex "$@"
+ exit ;;
+ (reindex)
+ shift
+ for d in "$@"
+ do
+ repo "$d"
+ done
+ index
+ exit ;;
+ (*)
+ err 'usage: stagit-hook [repo ...]'
+ esac
+fi
+
+printenv GIT_DIR >/dev/null ||
+ err 'error: Expected to be run as a git hook'
+
+err="$(mktemp -t stagit-hook-errXXXXXX)"
+trap 'rm -f "$err"' EXIT
+{
+ repo "$GIT_DIR"
+ index
+} > "$err" 2>&1 || {
+ logger -t stagit-hook -p error < "$err"
+ exit 1
+}
diff --git a/stagit-hook-hook b/stagit-hook-hook
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec stagit-hook
diff --git a/stagit-hook-install b/stagit-hook-install
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+for r in "${@:?usage: stagit-hook-install repo [...]}"
+do
+ cp "$(which stagit-hook-hook)" "$r"/hooks/post-update
+done
diff --git a/stagit-hook.1 b/stagit-hook.1
@@ -0,0 +1,47 @@
+.Dd October 19, 2025
+.Dt STAGIT-HOOK 1
+.Os
+.Sh NAME
+.Nm stagit-hook
+.Nd Git hook to automatically run stagit
+.Sh SYNOPSIS
+.Nm
+.Nm
+.Ar install repo Op Ar ...
+.Nm
+.Ar reindex repo Op Ar ...
+.Sh DESCRIPTION
+When used without any arguments,
+the
+.Nm
+utility behaves like a post-update git hook. When run with the
+.Ar install
+command, a post-update hook is installed in the given repositories
+and an initial set of stagit files are generated. To force reindexing
+of a repository, you may use the
+.Ar reindex
+command.
+.Pp
+.Sh FILES
+.Bl -tag -width Ds
+.It Pa /etc/stagit-hook
+.Xr stagit-hook 5
+configuration file.
+.El
+.Sh EXIT STATUS
+.Ex -std
+.Sh EXAMPLES
+.Pp
+Install stagit hook in the
+.Qq example
+repository:
+.Pp
+.Dl $ stagit-hook install ./example
+.Pp
+.Sh SEE ALSO
+.Xr stagit 1 ,
+.Xr stagit-index 1 ,
+.Xr githooks 5 ,
+.Xr stagit-hook 5
+.Sh AUTHORS
+.An Jacob R. Edwards Aq Mt jacob@jacobedwards.org
diff --git a/stagit-hook.5 b/stagit-hook.5
@@ -0,0 +1,30 @@
+.Dd October 19, 2025
+.Dt STAGIT-HOOK 5
+.Os
+.Sh NAME
+.Nm stagit-hook
+.Nd stagit-hook configuration file
+.Sh DESCRIPTION
+.Nm
+reads configuration from
+.Pa /etc/stagit-hook
+allowing you to set the
+.Va baseurl
+and
+.Va basedir
+variables.
+Here is an example configuration file:
+.Bd -literal
+baseurl https://example.com/git
+basedir /var/www/htdocs/example.com/git
+.Ed
+.Sh FILES
+.Bl -tag -width Ds
+.It Pa /etc/stagit-hook
+Contains configuration data for
+.Xr stagit-hook 1 .
+.El
+.Sh SEE ALSO
+.Xr stagit-hook 1
+.Sh AUTHORS
+.An Jacob R. Edwards Aq Mt jacob@jacobedwards.org