FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppcheck/tools/git-pre-commit-cppcheck at main · cppchecksolutions/cppcheck · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
cppchecksolutions
/
cppcheck
Public
forked from
cppcheck-opensource/cppcheck
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppcheck
/
tools
/
git-pre-commit-cppcheck
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (43 loc) · 1.24 KB
Breadcrumbs
cppcheck
/
tools
/
git-pre-commit-cppcheck
Copy path
File metadata and controls
48 lines (43 loc) · 1.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!
/bin/sh
#
Usage: add this file to your project's .git/hooks directory. Rename it to
#
just 'pre-commit'.
#
Now, when you change some files in repository and try to commit these
#
changes, git will run this script right before commit. Cppcheck will scan
#
changed/new files in repository. If it finds some issues, script returns with
#
exit code 1, rejecting commit. Otherwise, script returns 0, and you can
#
actually commit your changes.
#
#
Example:
#
$ cat hello.c
#
int main() {
#
int *s = malloc(10);
#
}
#
$ git add hello.c
#
$ git commit
#
Checking hello.c...
#
[hello.c:3]: (error) Memory leak: s
#
[hello.c:2]: (error) The allocated size 10 is not a multiple of the underlying type's size.
#
#
$ vim hello.c
#
$ cat hello.c
#
int main() {
#
}
#
$ git add hello.c
#
$ git commit
#
Checking hello.c...
#
$
if
git rev-parse --verify HEAD
>
/dev/null
2>&1
then
against=HEAD
else
#
Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
#
We should pass only added or modified C/C++ source files to cppcheck.
changed_files=
$(
git diff-index --cached
$against
|
\
grep -E
'
[MA] .*\.(c|cpp|cc|cxx)$
'
|
cut -f 2
)
if
[
-n
"
$changed_files
"
]
;
then
cppcheck --error-exitcode=1
$changed_files
exit
$?
fi
exit
0
Back
|
FazBrowse Home
|
New Git URL