aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-11-30 05:21:27 -0500
committerB. Watson <urchlay@slackware.uk>2026-11-30 05:21:53 -0500
commit68c8b13abb6b52b1745feca3031decdb4d93bacb (patch)
treec98ba2e9edb2a4d31b0fa069842bc4a30e6c2f38
parentb512a44db0e8d276edaada569966bf37b513ef41 (diff)
downloadsbo-maintainer-tools-68c8b13abb6b52b1745feca3031decdb4d93bacb.tar.gz
Move hooks to hooks/.
-rw-r--r--HOOKS.txt38
-rw-r--r--README7
-rwxr-xr-xhooks/pre-commit135
-rwxr-xr-xhooks/pre-receive (renamed from pre-receive)0
-rw-r--r--pre-commit-sbolint62
5 files changed, 174 insertions, 68 deletions
diff --git a/HOOKS.txt b/HOOKS.txt
new file mode 100644
index 0000000..fa371e2
--- /dev/null
+++ b/HOOKS.txt
@@ -0,0 +1,38 @@
+Git Hooks
+=========
+
+- pre-commit: A git hook every SBo contributor should use, that
+ automatically calls sbolint and stops you from committing builds that
+ don't pass sbolint.
+
+- commit-msg: A git hook every SBo contributor should use, that
+ checks the formatting of commit messages, and adds the
+ "category/name: " prefix.
+
+- prepare-commit-msg: A git hook that adds the "Signed-off-by" line
+ to every commit message. You should *not* use this unless you are
+ either an SBo admin, or have received permission from the admins
+ to "sign off" commits.
+
+- pre-receive: A git hook that's installed on the SBo git server.
+ It's a "server-side" hook, so it's not that useful anywhere else,
+ but it's included here for reference. If you have an intermediate
+ "staging" git server where you push your changes before pushing
+ them to SBo or git(hub|lab), you can use this hook there.
+
+To use these hooks, copy them to your local git worktree (where you
+run "git commit", "git push", etc commands), like so:
+
+ cp pre-commit commit-msg /path/to/slackbuilds/.git/hooks
+
+...and make sure they have +x permission (chmod as needed).
+
+For documentation on the hooks themselves, see the comments in the
+scripts.
+
+If you ever need to bypass all the git hooks, you can use:
+
+ git commit -n <args>
+
+Also, pre-commit and commit-msg can be selectively disabled with
+environment variables.
diff --git a/README b/README
index 8fee27e..8768166 100644
--- a/README
+++ b/README
@@ -17,9 +17,6 @@ Included tools:
- sbopkglint: Checks your package, after it's built.
-- pre-commit-sbolint: A git pre-commit hook you should use, that
- automatically calls sbolint and stops you from committing bad code.
-
- sbofixinfo: Attempts to automatically fix common .info file problems.
- sbodl: Download source files listed in DOWNLOAD and DOWNLOAD_x86_64
@@ -42,9 +39,7 @@ Included tools:
incomplete, and not yet installed by "make install". Use it at your
own peril.
-- pre-receive: A git hook that's installed on the SBo git server. It's
- a "server-side" hook, so it's not that useful anywhere else, but
- it's included here for reference.
+- hooks/*: Git hooks. See HOOKS.txt for documentation.
Note that the SBo admins use sbolint and sbopkglint as part of the
approval process, when you submit an update. Failure to pass the lint
diff --git a/hooks/pre-commit b/hooks/pre-commit
new file mode 100755
index 0000000..4cd7aa1
--- /dev/null
+++ b/hooks/pre-commit
@@ -0,0 +1,135 @@
+#!/bin/bash
+
+# 20220315 bkw: SBo pre-commit hook, wrapper for sbolint.
+# 20260919 bkw: no code changes; update install comments.
+# 20261130 bkw: add check for md5sums in the .info file.
+
+# Installation:
+
+# This file is part of sbo-maintainer-tools, which you can get
+# from SBo:
+# https://slackbuilds.org/repository/15.0/system/sbo-maintainer-tools/
+
+# Copy this file to <gitdir>/.git/hooks, mode 0755 (or anyway, make it
+# executable).
+
+# 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>
+
+# This script also checks the .info file, to see whether VERSION changed.
+# If it has, it checks MD5SUM and/or MD5SUM_x86_64 to see whether they've
+# changed. If they haven't, the commit is aborted. This is to guard
+# against the common mistake of updating a build's version but forgetting
+# to update the md5sums in the .info file. If you are 100% sure your
+# commit is correct, you can skip the md5sum check:
+
+# MD5OK=yes git commit <arguments>
+
+# Notes:
+
+# This really uses bash features, please don't try changing the top
+# line to #!/bin/sh, it'll fail (even if /bin/sh is a symlink to
+# /bin/bash).
+
+# 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.
+
+#######################################################################
+set -e
+exec 1>&2
+
+check_info_file() {
+ local file="$1" # this is the modified version
+ local origfile="$1".old.$$ # this will be the original
+ local cksum
+
+ # could be an array but I refuse to use bash's hideous array syntax:
+ local errmsg
+
+ # if the file was removed, don't try to check it.
+ [ -e "$file" ] || return 0
+
+ # reconstitute the file as it was before this commit
+ cp "$file" "$origfile"
+ git diff --cached "$file" | patch -s -R -p3 "$origfile"
+
+ # if the file just added, $origfile won't exist after patching.
+ [ -e "$origfile" ] || return 0
+
+ source "$origfile"
+ oldver="$VERSION"
+ oldmd5="$MD5SUM"
+ oldmd5_64="$MD5SUM_x86_64"
+ rm -f "$origfile"
+
+ source "$file"
+ if [ "$VERSION" != "$oldver" ]; then
+ if [ -n "$oldmd5" -a -n "$MD5SUM" -a "$oldmd5" = "$MD5SUM" ]; then
+ errmsg+=" VERSION was updated but MD5SUM was not!\n"
+ fi
+ if [ -n "$oldmd5_64" -a -n "$MD5SUM_x86_64" -a "$oldmd5_64" = "$MD5SUM_x86_64" ]; then
+ errmsg+=" VERSION was updated but MD5SUM_x86_64 was not!\n"
+ fi
+ fi
+
+ if [ -z "$MD5SUM" -a -z "$MD5SUM_x86_64" ]; then
+ errmsg+=" MD5SUM and MD5SUM_x86_64 are both blank!\n"
+ else
+ # no quotes: we want to break on whitespace-separated words here.
+ for cksum in $MD5SUM $MD5SUM_x86_64; do
+ [[ $cksum =~ ^[a-z0-9]{32}$ ]] || errmsg+=" Invalid md5sum: $cksum\n"
+ done
+ fi
+
+ if [ -n "$errmsg" ]; then
+ echo -e "*** $file:\n$errmsg"
+ cat <<EOF
+Commit aborted. Either update the checksum(s) and retry the commit, or
+if you're 100% sure it's correct, rerun the commit with MD5OK=yes in
+the environment.
+EOF
+ exit 1
+ fi
+}
+
+# The fugly grep regex below matches only the actual .info files, named
+# category/prgnam/prgnam.info (and not other files named .info).
+
+if [ "${MD5OK:-no}" != "yes" ]; then
+ while read filename; do
+ check_info_file "$filename"
+ done < <(git diff --cached --name-only | grep '^[^/]*/\([^/]*\)/\1.info' || exit 0)
+fi
+
+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 was 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
diff --git a/pre-receive b/hooks/pre-receive
index 52303ab..52303ab 100755
--- a/pre-receive
+++ b/hooks/pre-receive
diff --git a/pre-commit-sbolint b/pre-commit-sbolint
deleted file mode 100644
index 1a0c796..0000000
--- a/pre-commit-sbolint
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/bin/bash
-
-# 20220315 bkw: SBo pre-commit hook, wrapper for sbolint.
-# 20260919 bkw: no code changes; update install comments.
-
-# Installation:
-
-# This file is part of sbo-maintainer-tools, which you can get
-# from SBo:
-# https://slackbuilds.org/repository/15.0/system/sbo-maintainer-tools/
-
-# Copy this file to <gitdir>/.git/hooks, mode 0755 (or anyway, make it
-# executable).
-
-# 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