Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
MostafaMollaali
dynamic
Commits
bfda1cb4
Commit
bfda1cb4
authored
5 years ago
by
Lars Bilke
Browse files
Options
Downloads
Patches
Plain Diff
[hook] Added file extension check, fixed lfs check.
parent
97bb7c8d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.pre-commit-config.yaml
+5
-0
5 additions, 0 deletions
.pre-commit-config.yaml
scripts/hooks/pre-commit-file-extensions.sh
+24
-0
24 additions, 0 deletions
scripts/hooks/pre-commit-file-extensions.sh
scripts/hooks/pre-commit-git-lfs.sh
+17
-6
17 additions, 6 deletions
scripts/hooks/pre-commit-git-lfs.sh
with
46 additions
and
6 deletions
.pre-commit-config.yaml
+
5
−
0
View file @
bfda1cb4
...
...
@@ -16,6 +16,11 @@ repos:
entry
:
git diff --check --cached -- ':!*.md' ':!*.pandoc' ':!*.asc' ':!*.dat' ':!*.ts'
language
:
system
stages
:
[
commit
,
manual
]
-
id
:
file-extensions
name
:
Check file extensions
entry
:
scripts/hooks/pre-commit-file-extensions.sh
language
:
system
stages
:
[
commit
,
manual
]
-
id
:
git-lfs
name
:
Check git lfs files
entry
:
scripts/hooks/pre-commit-git-lfs.sh
...
...
This diff is collapsed.
Click to expand it.
scripts/hooks/pre-commit-file-extensions.sh
0 → 100755
+
24
−
0
View file @
bfda1cb4
#!/usr/bin/env bash
# set -e
# Check for uppercase letters in filename extensions
pattern
=
".*
\.\w
*([A-Z]+)
\w
*$"
files
=
$(
git diff
--cached
--find-copies
--find-renames
--name-only
--diff-filter
=
ACMRTXBU |
grep
-E
"
$pattern
"
)
if
[[
-n
$files
]]
;
then
echo
"Attention!"
echo
"----------"
echo
"Found files that contain capital letters in the file extension."
echo
"Please rename the following files and commit again:"
while
read
-r
file
;
do
echo
-e
'\E[0;32m'
"
$file
"
'\033[0m'
done
<<<
"
$files
"
# Abort commit
exit
1
fi
exit
0
This diff is collapsed.
Click to expand it.
scripts/hooks/pre-commit-git-lfs.sh
+
17
−
6
View file @
bfda1cb4
...
...
@@ -3,17 +3,28 @@
set
-e
BINARY_FILES
=
""
CHANGED_FILES
=
$(
git diff
--cached
--name-only
--diff-filter
=
ACM
)
LFS_FILES
=
$(
echo
$CHANGED_FILES
| xargs
-I
{
lin
}
git check-attr filter
"{lin}"
|
grep
'filter: lfs$'
|
sed
-e
's/: filter: lfs//'
)
LFS_FILES
=
""
CHANGED_FILES
=
$(
git diff
--cached
--name-only
--diff-filter
=
ACMRTXBU
)
for
FILE
in
$LFS_FILES
;
do
SOFT_SHA
=
$(
git hash-object
-w
$FILE
)
RAW_SHA
=
$(
git hash-object
-w
--no-filters
$FILE
)
while
read
-r
FILE
;
do
LFS_FILE
=
$(
git check-attr filter
"
$FILE
"
|
grep
'filter: lfs$'
|
sed
-e
's/: filter: lfs//'
)
if
[
!
-z
"
$LFS_FILE
"
]
;
then
LFS_FILES
=
"
$LFS_FILES
$LFS_FILE
"
fi
done
<<<
"
$CHANGED_FILES
"
if
[
-z
"
$LFS_FILES
"
]
;
then
exit
0
fi
while
read
-r
FILE
;
do
SOFT_SHA
=
$(
git hash-object
-w
"
$FILE
"
)
RAW_SHA
=
$(
git hash-object
-w
--no-filters
"
$FILE
"
)
if
[
$SOFT_SHA
==
$RAW_SHA
]
;
then
BINARY_FILES
=
"
$FILE
\n
$BINARY_FILES
"
fi
done
done
<<<
"
$LFS_FILES
"
if
[[
-n
"
$BINARY_FILES
"
]]
;
then
echo
"Attention!"
...
...
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