Debian Codegraph @

.githooks/pre-commit

raw
1 #!/bin/sh
2 #
3 # This pre-commit hook checks if any versions of clang-format
4 # are installed, and if so, uses the installed version to format
5 # the staged changes.
6
7 base=/opt/rocm/hcc/bin/clang-format
8 format=""
9
10 # Redirect output to stderr.
11 exec 1>&2
12
13 # check if clang-format is installed
14 type "$base" >/dev/null 2>&1 && format="$base"
15
16 # no versions of clang-format are installed
17 if [ -z "$format" ]
18 then
19 echo "$base is not installed. Pre-commit hook will not be executed."
20 exit 0
21 fi
22
23 # Do everything from top - level
24 cd $(git rev-parse --show-toplevel)
25
26 if git rev-parse --verify HEAD >/dev/null 2>&1
27 then
28 against=HEAD
29 else
30 # Initial commit: diff against an empty tree object
31 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
32 fi
33
34 # do the formatting
35 for file in $(git diff-index --cached --name-only $against | grep -E '\.h$|\.hpp$|\.cpp$|\.cl$|\.h\.in$|\.hpp\.in$|\.cpp\.in$')
36 do
37 if [ -e "$file" ]
38 then
39 echo "$format $file"
40 "$format" -i -style=file "$file"
41 fi
42 done
43