From a37080c9481a5e18ecb2a2f7b498fbaf758a2f1f Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Fri, 30 May 2025 00:51:41 +0200 Subject: [PATCH] hooks:pre-commit: Check for absolute links too I don't really want any absolute links here. --- meta/git/hooks/pre-commit | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/meta/git/hooks/pre-commit b/meta/git/hooks/pre-commit index 9f980f5..884dc6f 100755 --- a/meta/git/hooks/pre-commit +++ b/meta/git/hooks/pre-commit @@ -42,15 +42,22 @@ if ! git diff-index --check --cached $against --; then die fi -# Check that added symlinks are not broken +# Check that added symlinks are neither absolute nor broken git diff --staged --name-only --diff-filter=AR $against \ | { - broken=0 + abort=0 while read -r line; do - if [ -h "$line" ] && [ ! -e "$line" ]; then - broken=1 + [ -h "$line" ] || continue + + target="$(readlink "$line")" + if [ "${target:0:1}" = "/" ]; then + abort=1 + printf "%s\n" "$line: Absolute symlink" >&2 + fi + if [ ! -e "$line" ]; then + abort=1 printf "%s\n" "$line: Broken symlink" >&2 fi done - (( ! broken )) || die + (( ! abort )) || die }