summaryrefslogtreecommitdiff
path: root/scripts/pre-commit.sample
blob: 5324c3b4693b37340f2d104acdc9ce40863afb59 (plain)
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
#!/bin/sh

gitclangformat=$(which git-clang-format)

if [ "$gitclangformat" == "" ]
then
    gitclangformat=$(find /usr/bin/ -name "git-clang-format*")
fi

against=`git rev-parse --verify HEAD 2>&1`

if [ $against == "" ]
then
    # Initial commit: diff against an empty tree object
    against=5394c6fa5bf40d9bc8619026cbc4c306211a8499
fi

$gitclangformat $against -f -q

if [ $? != 0 ]
then
    echo "Format error!"
    echo "Use git clang-format"
    exit 1
fi

# Now update format changes and commit
git add $(git diff --name-only --cached)