Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Frank Dana
VTK
Commits
f8badc3d
Commit
f8badc3d
authored
Mar 08, 2022
by
Brad King
Browse files
pre-commit: add support for the ghostflow hooks-max-size attribute
parent
d033ed35
Changes
1
Hide whitespace changes
Inline
Side-by-side
pre-commit
View file @
f8badc3d
...
...
@@ -163,6 +163,8 @@ check_mode() {
size_max_KiB
=
$(
git config hooks.MaxObjectKiB
)
test
-n
"
$size_max_KiB
"
||
size_max_KiB
=
1024
size_max_bytes
=
$(
git config hooks.max-size
)
test
-n
"
$size_max_bytes
"
||
size_max_bytes
=
$((
"
${
size_max_KiB
}
"
*
1024
))
size_too_large_once
=
""
size_too_large_once
()
{
test
-z
"
$size_too_large_once
"
||
return
;
size_too_large_once
=
done
...
...
@@ -170,42 +172,61 @@ size_too_large_once() {
We prefer to keep large files out of the main source tree, especially
binary files that do not compress well. This hook disallows large files
by default but can be configured. A limit for specific files or patterns
may be set in ".gitattributes" with the "hooks
.MaxObjectKiB
" attribute.
may be set in ".gitattributes" with the "hooks
-max-size
" attribute.
For example, the line
*.c hooks
.MaxObjectKiB=2048
*.c hooks
-max-size=1500000
sets a limit of
2048 KiB
for C source files. See "git help attributes"
sets a limit of
1500000 bytes
for C source files. See "git help attributes"
for details on the .gitattributes format. If no attribute has been set
for a given file then its size is limited by the local default. Run
git config hooks.
M
ax
ObjectKiB $KiB
git config hooks.
m
ax
-size $bytes
to set the local default limit (0 to disable).
'
}
size_too_large
()
{
size_too_large_once
echo
"The path '
$file
' has size
$file_
KiB
KiB
, greater than allowed
$max_
KiB
KiB
."
echo
"The path '
$file
' has size
$file_
bytes
bytes
, greater than allowed
$max_
bytes
bytes
."
}
size_validate_max_KiB
()
{
test
"
$max_KiB
"
-ge
"0"
2>/dev/null
&&
return
0
echo
"The path '
$file
' has invalid attribute
\"
hooks-MaxObjectKiB=
$max_KiB
\"
."
echo
"The path '
$file
' has invalid attribute
\"
hooks.MaxObjectKiB=
$max_KiB
\"
."
return
1
}
size_validate_max_bytes
()
{
test
"
$max_bytes
"
-ge
"0"
2>/dev/null
&&
return
0
echo
"The path '
$file
' has invalid attribute
\"
hooks-max-size=
$max_bytes
\"
."
return
1
}
check_size
()
{
test
"
$dst_obj
"
!=
"
$zero
"
||
return
max_KiB
=
$(
git check-attr hooks.MaxObjectKiB
--
"
$file
"
|
sed
's/^[^:]*: hooks.MaxObjectKiB: //'
)
max_KiB
=
$(
git check-attr hooks.MaxObjectKiB
--
"
$file
"
|
sed
's/^[^:]*: hooks.MaxObjectKiB: //'
)
case
"
$max_KiB
"
in
'unset'
)
return
;;
# No maximum for this object.
'set'
)
max_KiB
=
"
$size_max_KiB
"
;;
# Use local default.
'unspecified'
)
max_KiB
=
"
$size_max_KiB
"
;;
# Use local default.
'unset'
)
;;
'set'
)
;;
'unspecified'
)
;;
*
)
size_validate_max_KiB
||
return
;;
esac
if
test
"
$max_KiB
"
-gt
"0"
;
then
file_KiB
=
$(
expr
'('
$(
git cat-file
-s
"
$dst_obj
"
)
+ 1023
')'
/ 1024
)
test
"
$file_KiB
"
-le
"
$max_KiB
"
||
size_too_large
max_bytes
=
$(
git check-attr hooks-max-size
--
"
$file
"
|
sed
's/^[^:]*: hooks-max-size: //'
)
case
"
$max_bytes
"
in
'unset'
)
return
;;
# No maximum for this object.
'set'
)
max_bytes
=
"
$size_max_bytes
"
;;
# Use local default.
'unspecified'
)
# Fall back to max KiB setting.
case
"
$max_KiB
"
in
'unset'
)
return
;;
# No maximum for this object.
'set'
)
max_bytes
=
$((
"
${
size_max_KiB
}
"
*
1024
))
;;
# Use local default.
'unspecified'
)
max_bytes
=
"
$size_max_bytes
"
;;
# Use local default.
*
)
max_bytes
=
$((
"
${
max_KiB
}
"
*
1024
))
;;
esac
;;
*
)
size_validate_max_bytes
||
return
;;
esac
if
test
"
$max_bytes
"
-gt
"0"
;
then
file_bytes
=
$(
git cat-file
-s
"
$dst_obj
"
)
test
"
$file_bytes
"
-le
"
$max_bytes
"
||
size_too_large
fi
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment