aboutsummaryrefslogtreecommitdiffstats
path: root/.extras/hooks/pre-commit
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-05-13 21:04:09 +0200
committerDanilo M. <danix@danix.xyz>2026-05-13 21:04:09 +0200
commit5798158b4c826ac44b59369b45048be14ce171cd (patch)
treedc1a08061fe4674d77a227285b2cf907b5642c2e /.extras/hooks/pre-commit
parent8daed34072ebf8327991c048c2fa73461063bafd (diff)
downloadmy-slackbuilds-5798158b4c826ac44b59369b45048be14ce171cd.tar.gz
my-slackbuilds-5798158b4c826ac44b59369b45048be14ce171cd.zip
hooks: block/auto-remove staged source archives in pre-commit
Symlinks to source archives are silently unstaged and deleted. Real source archive files abort the commit and list all offenders. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to '.extras/hooks/pre-commit')
-rwxr-xr-x.extras/hooks/pre-commit21
1 files changed, 21 insertions, 0 deletions
diff --git a/.extras/hooks/pre-commit b/.extras/hooks/pre-commit
index 06cb7a5..d2f9506 100755
--- a/.extras/hooks/pre-commit
+++ b/.extras/hooks/pre-commit
@@ -31,6 +31,27 @@
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.