Skip to content

Commit

Permalink
feat: Updated scripts/githooks/pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Dec 28, 2023
1 parent 1cd98e8 commit 94ec4d9
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions scripts/githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,13 @@ else
against="$empty_tree"
fi

# Set split so that for loop below can handle spaces in file names by splitting on line breaks
IFS='
'

shouldFail=false
for file in $( git diff-index --cached --name-only $against ); do
file_size=$(([ ! -f $file ] && echo 0) || (ls -la $file | awk '{ print $5 }'))
if [ "$file_size" -gt "$limit" ]; then
printError "File $file is $(( $file_size / 10**6 )) MB, which is larger than our configured limit of $limitInMB MB"
shouldFail=true
fi
for file in $(git diff --cached --name-only); do
filesize=$(stat -c%s "$file")
if [ $filesize -gt $limit ]; then
file_too_large $file $filesize
exit 1
fi
done

if $shouldFail
then
printMessage "If you really need to commit this file, you can override the size limit by setting the GIT_FILE_SIZE_LIMIT environment variable, e.g. GIT_FILE_SIZE_LIMIT=42000000 for 42MB. Or, commit with the --no-verify switch to skip the check entirely."
printError "Commit aborted"
Expand Down

0 comments on commit 94ec4d9

Please sign in to comment.