aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-03-31 12:19:56 +0200
committerDanilo M. <danix@danix.xyz>2026-03-31 12:19:56 +0200
commit59d70bd5f0418205f97426dd6d400adc68e91082 (patch)
tree8a3268615cdc0630f8999c769dd576b2f0640799
parentd3b865ccf522114746b51ac483cd5c856512310a (diff)
downloadmy-slackbuilds-59d70bd5f0418205f97426dd6d400adc68e91082.tar.gz
my-slackbuilds-59d70bd5f0418205f97426dd6d400adc68e91082.zip
hooks: add pre-commit and post-commit hooks to version control
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rw-r--r--CLAUDE.md14
-rw-r--r--README.md17
-rwxr-xr-xhooks/post-commit51
-rwxr-xr-xhooks/pre-commit63
4 files changed, 141 insertions, 4 deletions
diff --git a/CLAUDE.md b/CLAUDE.md
index a566ccb..0e40e2c 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -98,14 +98,20 @@ Source: https://slackware.uk/~urchlay/repos/sbo-maintainer-tools
### Git hook setup
-Install the pre-commit hook into this repo:
+Both hooks are tracked in the `hooks/` directory. Install them after cloning:
```bash
-cp /usr/doc/sbo-maintainer-tools-0.9.3/pre-commit-sbolint .git/hooks/pre-commit
-chmod +x .git/hooks/pre-commit
+cp hooks/pre-commit .git/hooks/pre-commit
+cp hooks/post-commit .git/hooks/post-commit
+chmod +x .git/hooks/pre-commit .git/hooks/post-commit
```
-To bypass it in exceptional cases:
+| Hook | Trigger | Purpose |
+|------|---------|---------|
+| `pre-commit` | Before every commit | Runs `sbolint` on staged packages; blocks commit on errors |
+| `post-commit` | After every commit | Offers to create a `SBo/<pkg>.tar.gz` archive for submission |
+
+To bypass the pre-commit lint check in exceptional cases:
```bash
SBOLINT=no git commit -m'Message here'
```
diff --git a/README.md b/README.md
index 35057b1..ffdef5b 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,23 @@ Check each package's `README` for dependencies and any special build instruction
---
+## Git Hooks
+
+Two hooks are included in `hooks/`. Install them after cloning:
+
+```bash
+cp hooks/pre-commit .git/hooks/pre-commit
+cp hooks/post-commit .git/hooks/post-commit
+chmod +x .git/hooks/pre-commit .git/hooks/post-commit
+```
+
+| Hook | Purpose |
+|------|---------|
+| `pre-commit` | Runs [`sbolint`](https://slackware.uk/~urchlay/repos/sbo-maintainer-tools) on staged packages before each commit |
+| `post-commit` | After each commit, offers to create a `SBo/<pkg>.tar.gz` archive ready for submission to SlackBuilds.org |
+
+---
+
## License
GPL-2.0 — see [LICENSE](LICENSE).
diff --git a/hooks/post-commit b/hooks/post-commit
new file mode 100755
index 0000000..9f92e3c
--- /dev/null
+++ b/hooks/post-commit
@@ -0,0 +1,51 @@
+#!/bin/bash
+# post-commit hook: create SBo submission archive for added/updated packages
+set -u
+
+REPO_ROOT=$(git rev-parse --show-toplevel)
+SBO_DIR="$REPO_ROOT/SBo"
+
+# Find packages whose .SlackBuild was added (A) or modified (M) in this commit.
+# git diff-tree output format: <status>\t<file>
+# We only want files exactly one directory deep, e.g. hugo/hugo.SlackBuild.
+PACKAGES=()
+while IFS=$'\t' read -r status file; do
+ [[ "$status" != "A" && "$status" != "M" ]] && continue
+ dir=$(dirname "$file")
+ base=$(basename "$file")
+ [[ "$dir" == "." ]] && continue # skip root-level files
+ [[ "$dir" == *"/"* ]] && continue # skip files deeper than one level
+ [[ "$base" == *.SlackBuild ]] || continue
+ PACKAGES+=("$dir")
+done < <(git diff-tree --no-commit-id -r --name-status HEAD)
+
+[[ ${#PACKAGES[@]} -eq 0 ]] && exit 0
+
+for pkg in "${PACKAGES[@]}"; do
+ echo ""
+ echo "==> Package: $pkg"
+ echo ""
+ echo "Files to be archived:"
+ echo "---------------------"
+ while IFS= read -r f; do
+ printf '%s\n' "${f#"$REPO_ROOT/"}"
+ done < <(find "$REPO_ROOT/$pkg" -type f | sort)
+ echo ""
+ printf "Create SBo archive for '%s'? [y/N] " "$pkg"
+ read -r answer </dev/tty
+ case "$answer" in
+ [yY]|[yY][eE][sS])
+ mkdir -p "$SBO_DIR"
+ if tar -czf "$SBO_DIR/$pkg.tar.gz" -C "$REPO_ROOT" "$pkg"; then
+ echo " -> Archive created: SBo/$pkg.tar.gz"
+ else
+ echo " -> Archive FAILED." >&2
+ fi
+ ;;
+ *)
+ echo " -> Skipped."
+ ;;
+ esac
+done
+
+exit 0
diff --git a/hooks/pre-commit b/hooks/pre-commit
new file mode 100755
index 0000000..06cb7a5
--- /dev/null
+++ b/hooks/pre-commit
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+# 20220315 bkw: SBo pre-commit hook, wrapper for sbolint.
+
+# Installation:
+
+# Copy this to <gitdir>/.git/hooks, mode 0755 (or anyway, make it
+# executable). Also get sbolint and install it somewhere on $PATH,
+# like /usr/local/bin. sbolint comes from:
+
+# https://slackware.uk/~urchlay/repos/sbostuff/plain/sbolint
+
+# That's a wgettable URL. You can also clone the sbostuff
+# repo from https://slackware.uk/~urchlay/repos/sbostuff if you want.
+
+# Usage:
+
+# Just do your usual "git commit". When you do, sbolint will run on
+# the build you're updating. If it finds any issues, it will cause the
+# commit to abort, so you can fix whatever's wrong and try the commit
+# again.
+
+# Since sbolint isn't perfect, you can skip the check for any commit
+# by running e.g:
+
+# SBOLINT=no git commit <arguments>
+
+# You can also run sbolint by itself, and read its documentation with
+# "sbolint --docs".
+
+set -e
+exec 1>&2
+
+# There should normally only be one changed build per commit, but this
+# rule may get broken when the repo's frozen pending a new Slackware
+# release. So use a loop.
+
+# The weird-looking "< <(command)" syntax is why this script must
+# have a #!/bin/bash at the top: it won't work with #!/bin/sh, even if
+# /bin/sh is a symlink to bash.
+
+if [ "${SBOLINT:-yes}" = "yes" ]; then
+ sbolintfailed=""
+ if ! which sbolint &>/dev/null; then
+ echo "WARNING: can't find sbolint in PATH, no linting will be done"
+ else
+ while read build; do
+ # if there's no slack-desc or README, assume the build has been removed.
+ # the directory still might exist after a "git rm -rf" because it
+ # might contain untracked files (e.g. the source tarball).
+ if [ -e "$build/slack-desc" -o -e "$build/README" ]; then
+ sbolint "$build" || sbolintfailed=1
+ fi
+ done < <(git diff --cached --name-only | cut -d/ -f1,2 | sort -u)
+ fi
+ if [ -n "$sbolintfailed" ]; then
+ echo "*** sbolint failed, fix the errors or set SBOLINT=no"
+ echo "*** in the environment to commit anyway."
+ exit 1
+ fi
+fi
+
+exit 0