diff options
| author | Danilo M. <danix@danix.xyz> | 2026-06-25 17:36:06 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-06-25 17:36:06 +0200 |
| commit | 580ef7dd3debeba90b0cd006e0ae25ddd47b7bdc (patch) | |
| tree | d1a0fe704502b26db39028587cb60b574d9ca839 /.extras/hooks/pre-commit | |
| parent | bae22fe64f65744fafe7f22937adbd8278866c60 (diff) | |
| download | slackware-pentesting-suite-580ef7dd3debeba90b0cd006e0ae25ddd47b7bdc.tar.gz slackware-pentesting-suite-580ef7dd3debeba90b0cd006e0ae25ddd47b7bdc.zip | |
extras: add SBo git hooks (pre-commit sbolint, post-commit archive)
Versioned source of truth for the hooks installed in .git/hooks/. Reinstall after reclone with: cp .extras/hooks/* .git/hooks/
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to '.extras/hooks/pre-commit')
| -rwxr-xr-x | .extras/hooks/pre-commit | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/.extras/hooks/pre-commit b/.extras/hooks/pre-commit new file mode 100755 index 0000000..d2f9506 --- /dev/null +++ b/.extras/hooks/pre-commit @@ -0,0 +1,84 @@ +#!/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 + +# Check for staged source archives (.tar.gz, .tar.xz, .tar.bz2, .zip, etc.) +# Symlinks: auto-removed. Regular files: blocked (must not be committed). +source_pattern='\.\(tar\.gz\|tar\.xz\|tar\.bz2\|tar\.zst\|tgz\|zip\|7z\|rpm\|deb\)$' +source_blocked="" +while IFS= read -r f; do + mode=$(git ls-files --stage -- "$f" | awk '{print $1}') + if [ "$mode" = "120000" ]; then + echo "Removing staged symlink to source archive: $f" + git rm --cached -q -- "$f" + rm -f "$f" + else + source_blocked="$source_blocked $f" + fi +done < <(git diff --cached --name-only | grep -i "$source_pattern") +if [ -n "$source_blocked" ]; then + echo "*** ERROR: source archives staged for commit:" + for f in $source_blocked; do echo "*** $f"; done + echo "*** Remove them with: git rm --cached -- $source_blocked" + exit 1 +fi + +# 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 |
