Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / build / git-hooks / pre-commit
1 #!/bin/sh
2
3 submodule_diff() {
4   if test -n "$2"; then
5     git diff-tree -r --ignore-submodules=dirty "$1" "$2" | grep -e '^:160000' -e '^:...... 160000' | xargs
6   else
7     git diff-index --cached --ignore-submodules=dirty "$1" | grep -e '^:160000' -e '^:...... 160000' | xargs
8   fi
9 }
10
11 if git rev-parse --verify --quiet --no-revs MERGE_HEAD; then
12   merge_base=$(git merge-base HEAD MERGE_HEAD)
13   if test -z "$(submodule_diff $merge_base HEAD)"; then
14     # Most up-to-date submodules are in MERGE_HEAD.
15     head_ref=MERGE_HEAD
16   else
17     # Most up-to-date submodules are in HEAD.
18     head_ref=HEAD
19   fi
20 else
21   # No merge in progress. Submodules must match HEAD.
22   head_ref=HEAD
23 fi
24
25 submods=$(submodule_diff $head_ref)
26 if test "$submods"; then
27   echo "You are trying to commit changes to the following submodules:" 1>&2
28   echo 1>&2
29   echo $submods | cut -d ' ' -f 6 | sed 's/^/  /g' 1>&2
30   cat <<EOF 1>&2
31
32 Submodule commits are not allowed.  Please run:
33
34   git status --ignore-submodules=dirty
35
36 and/or:
37
38   git diff-index --cached --ignore-submodules=dirty HEAD
39
40 ... to see what's in your index.
41
42 If you're really and truly trying to roll the version of a submodule, you should
43 commit the new version to DEPS, instead.
44 EOF
45   exit 1
46 fi
47
48 gitmodules_diff() {
49   git diff-index --cached "$1" .gitmodules
50 }
51
52 if [ "$(git ls-files .gitmodules)" ] && [ "$(gitmodules_diff $head_ref)" ]; then
53   cat <<EOF 1>&2
54 You are trying to commit a change to .gitmodules.  That is not allowed.
55 To make changes to submodule names/paths, edit DEPS.
56 EOF
57   exit 1
58 fi
59
60 exit 0