Git Hooks: Fix and test binary file moves (#19)
Co-authored-by: Sebastian Parborg <sebastian@blender.org> Reviewed-on: https://projects.blender.org/infrastructure/gitea-custom/pulls/19
This commit is contained in:
@@ -48,8 +48,11 @@ while read oldrev newrev refname; do
|
||||
git cat-file --batch-check='%(objectname) %(objecttype) %(objectsize) %(rest)' | grep commit | awk '{print $1}'); do
|
||||
|
||||
# Get list of potentially binary files in this commit
|
||||
mapfile -t binary_files < <(git log --diff-filter=d --pretty=format:%H -M100% --numstat ${commit}^! | grep -e "- - \w" | awk '{print $3}')
|
||||
|
||||
mapfile -t binary_files < <(
|
||||
git log --diff-filter=d --pretty=format:%H -M100% --numstat ${commit}^! |
|
||||
awk -F'\t' '$1=="-" && $2=="-" {print $3}'
|
||||
)
|
||||
|
||||
if [ ${#binary_files[@]} -eq 0 ]; then
|
||||
continue
|
||||
fi
|
||||
@@ -62,6 +65,12 @@ while read oldrev newrev refname; do
|
||||
|
||||
rejected_files=()
|
||||
for file in "${binary_files[@]}"; do
|
||||
if [[ $file == *" => "* ]]; then
|
||||
# If the name contains " => " then this probably means the file was moved.
|
||||
# If it was just moved, then it must still be a binary file.
|
||||
rejected_files+=("$file")
|
||||
continue
|
||||
fi
|
||||
# Check if it's an LFS pointer
|
||||
# Use handle_pipefails as we may run into SIGPIPE error code
|
||||
if git show "${commit}:${file}" | git lfs pointer --check --stdin || handle_pipefails $?; then
|
||||
|
||||
Reference in New Issue
Block a user