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
34d32b0e
Commit
34d32b0e
authored
2 years ago
by
Allan Blanchard
Browse files
Options
Downloads
Patches
Plain Diff
[lint/headers] script for call
parent
5de8d26e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dev/check-files.sh
+120
-0
120 additions, 0 deletions
dev/check-files.sh
dev/git-hooks/pre-commit.sh
+5
-31
5 additions, 31 deletions
dev/git-hooks/pre-commit.sh
dev/git-hooks/pre-push.sh
+5
-31
5 additions, 31 deletions
dev/git-hooks/pre-push.sh
with
130 additions
and
62 deletions
dev/check-files.sh
0 → 100755
+
120
−
0
View file @
34d32b0e
#!/bin/bash
##########################################################################
# #
# This file is part of Frama-C. #
# #
# Copyright (C) 2007-2022 #
# CEA (Commissariat à l'énergie atomique et aux énergies #
# alternatives) #
# #
# you can redistribute it and/or modify it under the terms of the GNU #
# Lesser General Public License as published by the Free Software #
# Foundation, version 2.1. #
# #
# It is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Lesser General Public License for more details. #
# #
# See the GNU Lesser General Public License version 2.1 #
# for more details (enclosed in the file licenses/LGPLv2.1). #
# #
##########################################################################
THIS_SCRIPT
=
"
$0
"
LINT
=
check-lint
HDRCK
=
check-headers
DO_LINT
=
"yes"
DO_HDRCK
=
"yes"
REFERENCE
=
MODE
=
"all"
while
[
"
$1
"
!=
""
]
do
case
"
$1
"
in
"-h"
|
"-help"
|
"--help"
)
echo
"
${
THIS_SCRIPT
}
[OPTIONS]"
echo
"OPTIONS"
echo
" -h|-help|--help print this message and exit"
echo
" -f|--fix fix files"
echo
" -c|--commit check modified files to be commited only"
echo
" -p|--push check modified files to be pushed only"
echo
" --no-headers do not check headers"
echo
" --no-lint do not check lint"
exit
0
;;
"-f"
|
"--fix"
)
LINT
=
lint
HDRCK
=
headers
;;
"-p"
|
"--push"
)
REFERENCE
=
"origin/
$(
git rev-parse
--abbrev-ref
HEAD
)
"
MODE
=
"push"
;;
"-c"
|
"--commit"
)
MODE
=
"commit"
;;
"--no-headers"
)
DO_HDRCK
=
"no"
;;
"--no-lint"
)
DO_LINT
=
"no"
;;
*
)
echo
"Unknown option '
$1
'"
exit
2
;;
esac
shift
done
if
[
"
$MODE
"
=
"all"
]
;
then
if
[
$DO_LINT
=
"yes"
]
;
then
make
$LINT
||
exit
1
fi
if
[
$DO_HDRCK
=
"yes"
]
;
then
make
$HDRCK
HDRCK_EXTRA
=
"-quiet"
||
exit
1
fi
else
STAGED
=
$(
git diff
--diff-filter
ACMR
--name-only
--cached
$REFERENCE
|
sort
)
UNSTAGED
=
$(
git diff
--diff-filter
DMR
--name-only
|
sort
)
if
[
"
$STAGED
"
=
""
]
;
then
echo
"No staged modification since last
$MODE
, nothing to do."
exit
0
fi
if
[
"
$UNSTAGED
"
!=
""
]
;
then
INTER
=
$(
comm
-12
<
(
ls
$STAGED
)
<
(
ls
$UNSTAGED
)
)
if
[
"
$INTER
"
!=
""
]
;
then
echo
"Cannot validate push."
echo
"The following staged files have been modified, renamed or deleted."
for
file
in
$INTER
;
do
echo
"-
$file
"
done
exit
1
fi
fi
STAGED
=
$(
echo
$STAGED
|
tr
'\n'
' '
)
TMP
=
$(
mktemp
)
cleanup
()
{
rm
"
$TMP
"
}
trap
cleanup
exit
git check-attr
-za
$STAGED
>
"
$TMP
"
if
[
$DO_LINT
=
"yes"
]
;
then
make
$LINT
LINTCK_FILES_INPUT
=
"
$TMP
"
||
exit
1
fi
git check-attr
-z
header_spec
$STAGED
>
"
$TMP
"
if
[
$DO_HDRCK
=
"yes"
]
;
then
make
$HDRCK
HDRCK_FILES_INPUT
=
"
$TMP
"
HDRCK_EXTRA
=
"-quiet"
||
exit
1
fi
fi
This diff is collapsed.
Click to expand it.
dev/git-hooks/pre-commit.sh
+
5
−
31
View file @
34d32b0e
...
@@ -21,14 +21,14 @@
...
@@ -21,14 +21,14 @@
# #
# #
##########################################################################
##########################################################################
# Examples of installation of this pre-commit hook (client side):
# Example of installation of this pre-commit hook (client side):
# - cp ./dev/git-hooks/pre-commit.sh .git/hooks/pre-commit
# - (cd .git/hooks/ && ln -s ../../dev/git-hooks/pre-commit.sh pre-commit)
# - (cd .git/hooks/ && ln -s ../../dev/git-hooks/pre-commit.sh pre-commit)
# Note: if you decide to copy the file, the `SCRIPT_DIR` variable must be
# fixed accordingly.
echo
"Pre-commit Hook..."
echo
"Pre-commit Hook..."
STAGED
=
$(
git diff
--diff-filter
ACMR
--name-only
--cached
|
sort
)
STAGED
=
$(
git diff
--diff-filter
ACMR
--name-only
--cached
|
sort
)
UNSTAGED
=
$(
git diff
--diff-filter
DMR
--name-only
|
sort
)
if
[
"
$STAGED
"
=
""
]
;
if
[
"
$STAGED
"
=
""
]
;
then
then
...
@@ -36,31 +36,5 @@ then
...
@@ -36,31 +36,5 @@ then
exit
0
exit
0
fi
fi
if
[
"
$UNSTAGED
"
!=
""
]
;
SCRIPT_DIR
=
$(
dirname
--
"
$(
readlink
-f
--
"
$0
"
;
)
"
)
then
"
$SCRIPT_DIR
/../check-files.sh"
-c
||
exit
1
INTER
=
$(
comm
-12
<
(
ls
$STAGED
)
<
(
ls
$UNSTAGED
)
)
if
[
"
$INTER
"
!=
""
]
;
then
echo
"Cannot validate commit."
echo
"The following staged files have been modified, renamed or deleted."
for
file
in
$INTER
;
do
echo
"-
$file
"
done
exit
1
fi
fi
STAGED
=
$(
echo
$STAGED
|
tr
'\n'
' '
)
TMP
=
$(
mktemp
)
cleanup
()
{
rm
"
$TMP
"
}
trap
cleanup
exit
git check-attr
-za
$STAGED
>
"
$TMP
"
make lint
LINTCK_FILES_INPUT
=
"
$TMP
"
||
exit
1
git check-attr
-z
header_spec
$STAGED
>
"
$TMP
"
make check-headers
HDRCK_FILES_INPUT
=
"
$TMP
"
HDRCK_EXTRA
=
"-quiet"
||
exit
1
This diff is collapsed.
Click to expand it.
dev/git-hooks/pre-push.sh
+
5
−
31
View file @
34d32b0e
...
@@ -21,14 +21,14 @@
...
@@ -21,14 +21,14 @@
# #
# #
##########################################################################
##########################################################################
# Examples of installation of this pre-push hook (client side):
# Example of installation of this pre-push hook (client side):
# - cp ./dev/git-hooks/pre-push.sh .git/hooks/pre-push
# - (cd .git/hooks/ && ln -s ../../dev/git-hooks/pre-push.sh pre-push)
# - (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
)
STAGED
=
$(
git diff
--diff-filter
ACMR
--name-only
--cached
origin/
$(
git rev-parse
--abbrev-ref
HEAD
)
|
sort
)
UNSTAGED
=
$(
git diff
--diff-filter
DMR
--name-only
|
sort
)
if
[
"
$STAGED
"
=
""
]
;
if
[
"
$STAGED
"
=
""
]
;
then
then
...
@@ -36,31 +36,5 @@ then
...
@@ -36,31 +36,5 @@ then
exit
0
exit
0
fi
fi
if
[
"
$UNSTAGED
"
!=
""
]
;
SCRIPT_DIR
=
$(
dirname
--
"
$(
readlink
-f
--
"
$0
"
;
)
"
)
then
"
$SCRIPT_DIR
/../check-files.sh"
-p
||
exit
1
INTER
=
$(
comm
-12
<
(
ls
$STAGED
)
<
(
ls
$UNSTAGED
)
)
if
[
"
$INTER
"
!=
""
]
;
then
echo
"Cannot validate push."
echo
"The following staged files have been modified, renamed or deleted."
for
file
in
$INTER
;
do
echo
"-
$file
"
done
exit
1
fi
fi
STAGED
=
$(
echo
$STAGED
|
tr
'\n'
' '
)
TMP
=
$(
mktemp
)
cleanup
()
{
rm
"
$TMP
"
}
trap
cleanup
exit
git check-attr
-za
$STAGED
>
"
$TMP
"
make lint
LINTCK_FILES_INPUT
=
"
$TMP
"
||
exit
1
git check-attr
-z
header_spec
$STAGED
>
"
$TMP
"
make check-headers
HDRCK_FILES_INPUT
=
"
$TMP
"
HDRCK_EXTRA
=
"-quiet"
||
exit
1
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