Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include file path in the error message #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion prevent-large-objects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ max_size="${1:?need max object size}"

found="false"
while read -r obj_id path; do
if [ -z "$path" ]; then
# Skip objects which are not files (commits, trees)
Comment on lines +15 to +16
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no assumption that the commit is the one currently checked out.

Nor is there any reason to limit it to not-commits.
e.g. someone might be really silly and create a multi-megabyte commit message.

continue
fi
size="$(git cat-file -s "$obj_id")"
if [ "$size" -lt "$max_size" ]; then
continue
Expand All @@ -25,7 +29,7 @@ while read -r obj_id path; do

if [ "$GITHUB_ACTION" != "" ] && [ "$GITHUB_WORKFLOW" != "" ]; then
# Output special github workflow metadata
printf "::error file=%s::Large git object (%d bytes)\n" "$path" "$size"
echo "::error file=$path::File $path is too large ($size bytes, $max_size is the limit)"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why swap from printf to echo?

fi
done

Expand Down