From 6c802cc70feea80e45eb538593f0aa636d844ffe Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Sat, 21 May 2022 13:23:22 +0200 Subject: [PATCH] meta:hooks:pre-commit: Check for broken symlinks Check that added/moved symlinks are not broken. --- meta/git/hooks/pre-commit | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/meta/git/hooks/pre-commit b/meta/git/hooks/pre-commit index a678266..e15b269 100755 --- a/meta/git/hooks/pre-commit +++ b/meta/git/hooks/pre-commit @@ -44,3 +44,16 @@ fi if ! git diff-index --check --cached $against --; then die fi + +# Check that added symlinks are not broken +git diff --staged --name-only --diff-filter=AR $against \ +| { + broken=0 + while read -r line; do + if [ -h "$line" ] && [ ! -e "$line" ]; then + broken=1 + printf "%s\n" "$line: Broken symlink" >&2 + fi + done + (( ! broken )) || die +}