Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
aports
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Milan P. Stanić
aports
Commits
6b1401bf
Commit
6b1401bf
authored
Dec 31, 2017
by
Jakub Jirutka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
githooks: add check for file size into pre-commit hook
parent
9a8fafdf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
+26
-4
.githooks/pre-commit
.githooks/pre-commit
+26
-4
No files found.
.githooks/pre-commit
View file @
6b1401bf
...
...
@@ -5,6 +5,10 @@
#
set
-eu
# Maximal allowed size (in bytes) of a file.
FILE_SIZE_LIMIT
=
262144
# 256 kiB
if
!
command
-v
sha512sum
>
/dev/null
;
then
# macOS / BSDs (?) don't have sha512sum, but shasum.
alias sha512sum
=
'shasum -a 512'
...
...
@@ -14,13 +18,13 @@ error() {
printf
'\033[0;31mpre-commit:\033[0m %s\n'
"
$1
"
>
&2
# red
}
# Prints paths of created or modified
APKBUILD
s being committed.
changed_
apkbuild
s
()
{
# Prints paths of created or modified
file
s being committed.
changed_
file
s
()
{
git diff-index
\
--name-only
\
--cached
\
--diff-filter
=
ACMR HEAD
\
--
'**/APKBUILD'
--
"
$@
"
}
# Prints file names and checksums (in format <SHA-512>:<filename>) of local
...
...
@@ -79,7 +83,25 @@ check_local_sources() {
return
$status
}
# Checks if the file ($1) being committed is not bigger than FILE_SIZE_LIMIT.
check_file_size
()
{
local
path
=
"
$1
"
local
size
size
=
$(
git cat-file
-s
":
$path
"
)
if
[
$size
-gt
$FILE_SIZE_LIMIT
]
;
then
local
size_kb
=
$((
size
/
1024
))
for
apkbuild
in
$(
changed_apkbuilds
)
;
do
error
"file
\"
$path
\"
is quite big (
$((
size
/
1024
))
kiB), better to upload it to dev.alpinelinux.org"
return
1
fi
}
for
apkbuild
in
$(
changed_files
'**/APKBUILD'
)
;
do
check_local_sources
"
$apkbuild
"
done
for
path
in
$(
changed_files
)
;
do
check_file_size
"
$path
"
done
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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