From 50434b3b0bc081905771649a5cba2efb19e58509 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 5 Aug 2023 05:05:40 -0400 Subject: [PATCH] fix handling of deleted files in pre-commit hook --- .githooks/pre-commit | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 67fa561..69630d8 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,8 +1,9 @@ #!/bin/sh -git diff --cached --quiet -- scripts && exit 0 -git diff --name-only -- scripts | grep --fixed-strings "$(git diff --cached --name-only -- scripts)" && exit 1 +staged="$(git diff --cached --diff-filter=d --name-only -- scripts)" +[ "$staged" ] || exit 0 +git diff --name-only -- scripts | grep --fixed-strings "$staged" && exit 1 version="$(date --utc +%Y.%m.%d.%H%M%S)" -git diff --cached --name-only -- scripts | while read -r file; do +echo "$staged" | while read -r file; do sed --in-place "s/@version .*/@version $version/" "$file" git add "$file" done