hooks:pre-commit: Check for absolute links too
I don't really want any absolute links here.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user