From 5798158b4c826ac44b59369b45048be14ce171cd Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 13 May 2026 21:04:09 +0200 Subject: 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 --- .extras/hooks/pre-commit | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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. -- cgit v1.2.3