forked from rpm-software-management/dnf5
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clang-format
executable file
·37 lines (29 loc) · 1000 Bytes
/
clang-format
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
#!/bin/sh
show_help() {
cat << EOF
Usage: $0 [PATHSPEC]...
Calls clang-format on git tree files. If there's a non-empty diff between the
working tree and HEAD (note, even if the diff is only on non-C/C++ sources),
clang-format is called only on C/C++ source files that contain changes. If
there are no changes in the working tree, calls clang-format on all C/C++
source files in git.
PATHSPEC is passed directly to the git commands used, it can specify
files or directories to run on.
Options:
-h, --help Show this help
EOF
exit 0
}
if [ "$1" = "-h" -o "$1" = "--help" ]; then
show_help
fi
# the tutorial files are snippets, not full sources, clang-format doesn't work well on them
EXCLUDE=":!:test/tutorial"
if [ -n "`git diff --name-only`" ]; then
FILES=`git diff --name-only -- "$@" $EXCLUDE | grep -E '\.(c|cpp|h|hpp)$'`
else
FILES=`git ls-files -- "$@" $EXCLUDE | grep -E '\.(c|cpp|h|hpp)$'`
fi
for FILE in $FILES; do
clang-format -i "$FILE"
done