Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xiaowei Li
VTK
Commits
f8badc3d
Commit
f8badc3d
authored
3 years ago
by
Brad King
Browse files
Options
Downloads
Patches
Plain Diff
pre-commit: add support for the ghostflow hooks-max-size attribute
parent
d033ed35
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pre-commit
+35
-14
35 additions, 14 deletions
pre-commit
with
35 additions
and
14 deletions
pre-commit
+
35
−
14
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
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment