summaryrefslogtreecommitdiffstats
path: root/git-hooks/clang-format-pre-commit
blob: 8b18541e2905e779702d7582c6472cb5bfc062c7 (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
29
30
31
32
33
#! /bin/sh
# Copyright (C) 2018 The Qt Company Ltd.
# Contact: http://www.qt.io/licensing/
#
# You may use this file under the terms of the 3-clause BSD license.
# See the file LICENSE from this package for details.
#

# Usage: in every repository you want to have checked:
#    cd .git/hooks
#    ln -s ../../../qtrepotools/git-hooks/clang-format-pre-commit pre-commit
#    mklink pre-commit ..\..\..\qtrepotools\git-hooks\clang-format-pre-commit
#

CLANG_FORMAT=`which git-clang-format`
if test -z "$CLANG_FORMAT"; then
    echo "Please install clang-format and make sure git-clang-format is in the path."
    exit 0
fi

CLANG_FORMAT_DIFF=`git clang-format -q --diff`
if [ "$CLANG_FORMAT_DIFF" = "no modified files to format" ]; then
    exit 0
fi
if test -n "$CLANG_FORMAT_DIFF"; then
    echo "clang-format output:"
    echo "$CLANG_FORMAT_DIFF"
    echo "clang-format detected change in format, please run:"
    echo "  git clang-format"
    echo "and amend the change."
    exit 1
fi