Roll src/third_party/WebKit f007c95:0171005 (svn 185074:185088)
[chromium-blink-merge.git] / build / git-hooks / pre-commit
blob41b596344c4bc0295f5ad383fb8f74b291c5eda2
1 #!/bin/sh
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
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
20 else
21 # No merge in progress. Submodules must match HEAD.
22 head_ref=HEAD
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
32 Submodule commits are not allowed. Please run:
34 git status --ignore-submodules=dirty
36 and/or:
38 git diff-index --cached --ignore-submodules=dirty HEAD
40 ... to see what's in your index.
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
48 gitmodules_diff() {
49 git diff-index --cached "$1" .gitmodules
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
60 exit 0