Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
pub
frama-c
Commits
808e234d
Commit
808e234d
authored
1 year ago
by
Virgile Prevosto
Browse files
Options
Downloads
Patches
Plain Diff
experiments on using push hook arguments directly
parent
96a4fa11
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dev/check-files.sh
+6
-6
6 additions, 6 deletions
dev/check-files.sh
dev/git-hooks/pre-push.sh
+23
-12
23 additions, 12 deletions
dev/git-hooks/pre-push.sh
with
29 additions
and
18 deletions
dev/check-files.sh
+
6
−
6
View file @
808e234d
...
@@ -38,7 +38,7 @@ do
...
@@ -38,7 +38,7 @@ do
echo
" -h|-help|--help print this message and exit"
echo
" -h|-help|--help print this message and exit"
echo
" -f|--fix fix files"
echo
" -f|--fix fix files"
echo
" -c|--commit check modified files to be committed only"
echo
" -c|--commit check modified files to be committed only"
echo
" -p|--push
check modified files to be pushed only"
echo
" -p|--push
range
check modified files to be pushed only"
echo
" --no-headers do not check headers"
echo
" --no-headers do not check headers"
echo
" --no-lint do not check lint"
echo
" --no-lint do not check lint"
exit
0
exit
0
...
@@ -48,11 +48,12 @@ do
...
@@ -48,11 +48,12 @@ do
HDRCK
=
headers
HDRCK
=
headers
;;
;;
"-p"
|
"--push"
)
"-p"
|
"--push"
)
REMOTE
=
$(
git config
--default
origin
--get
clone.defaultRemoteName
)
shift
REFERENCE
=
"
$REMOTE
/
$(
git rev-parse
--abbrev-ref
HEAD
)
"
DIFF_ARG
=
$1
MODE
=
"push"
MODE
=
"push"
;;
;;
"-c"
|
"--commit"
)
"-c"
|
"--commit"
)
DIFF_ARG
=
--cached
MODE
=
"commit"
MODE
=
"commit"
;;
;;
"--no-headers"
)
"--no-headers"
)
...
@@ -87,9 +88,8 @@ else
...
@@ -87,9 +88,8 @@ else
rm
-f
"
$TMP_STAGED
"
"
$TMP_UNSTAGED
"
"
$TMP_INPUT
"
"
$TMP_INTER
"
rm
-f
"
$TMP_STAGED
"
"
$TMP_UNSTAGED
"
"
$TMP_INPUT
"
"
$TMP_INTER
"
}
}
trap
cleanup
exit
trap
cleanup
exit
git diff
--diff-filter
ACMR
--name-only
$DIFF_ARG
|
sort
>
"
$TMP_STAGED
"
git diff
--diff-filter
ACMR
--name-only
-z
--cached
$REFERENCE
|
sort
-z
>
"
$TMP_STAGED
"
git diff
--diff-filter
DMR
--name-only
|
sort
>
"
$TMP_UNSTAGED
"
git diff
--diff-filter
DMR
--name-only
-z
|
sort
-z
>
"
$TMP_UNSTAGED
"
if
[
!
-s
"
$TMP_STAGED
"
]
;
if
[
!
-s
"
$TMP_STAGED
"
]
;
then
then
...
...
This diff is collapsed.
Click to expand it.
dev/git-hooks/pre-push.sh
+
23
−
12
View file @
808e234d
...
@@ -21,20 +21,31 @@
...
@@ -21,20 +21,31 @@
# #
# #
##########################################################################
##########################################################################
# Example of installation of this pre-push hook (client side):
ROOT
=
$(
git rev-parse
--show-toplevel
)
# - (cd .git/hooks/ && ln -s ../../dev/git-hooks/pre-push.sh pre-push)
# Note: if you decide to copy the file, the `SCRIPT_DIR` variable must be
# fixed accordingly.
echo
"Pre-push Hook..."
echo
"Pre-push Hook..."
STAGED
=
$(
git
diff
--diff-filter
ACMR
--name-only
--cached
origin/
$(
git rev-parse
--abbrev-ref
HEAD
)
|
sort
)
empty
=
$(
git
hash-object
--stdin
</dev/null |
tr
'[0-9a-f]'
'0'
)
if
[
"
$STAGED
"
=
""
]
;
remote
=
$1
then
echo
"No diff since last push, nothing to do"
exit
0
fi
SCRIPT_DIR
=
$(
dirname
--
"
$(
readlink
-f
--
"
$0
"
;
)
"
)
while
read
local_ref local_oid remote_ref remote_oid
"
$SCRIPT_DIR
/../check-files.sh"
-p
||
exit
1
do
if
test
"
$local_oid
"
=
"
$empty
"
then
# Handle delete
:
else
if
test
"
$remote_oid
"
=
"
$zero
"
then
# New branch, examine all commits
range
=
"
$local_oid
"
else
# Update to existing branch, examine new commits
range
=
"
$remote_oid
$local_oid
"
fi
"
$ROOT
/dev/check-files.sh"
-p
"
$range
"
||
exit
1
;
fi
;
done
exit
0
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