Index: build/git-hooks/pre-commit |
diff --git a/build/git-hooks/pre-commit b/build/git-hooks/pre-commit |
index a39be2202cef12427192d6ac174fe3dec4d7f52d..790e14ec8412cd5a954cb785e1bce78367e6813d 100755 |
--- a/build/git-hooks/pre-commit |
+++ b/build/git-hooks/pre-commit |
@@ -1,6 +1,28 @@ |
#!/bin/sh |
-submods=$(git diff-index --cached --ignore-submodules=dirty HEAD | grep -e '^:160000' -e '^:...... 160000' | xargs) |
+submodule_diff() { |
+ if test -n "$2"; then |
+ git diff-tree -r --ignore-submodules=dirty "$1" "$2" | grep -e '^:160000' -e '^:...... 160000' | xargs |
+ else |
+ git diff-index --cached --ignore-submodules=dirty "$1" | grep -e '^:160000' -e '^:...... 160000' | xargs |
+ fi |
+} |
+ |
+if git rev-parse --verify --quiet --no-revs MERGE_HEAD; then |
+ merge_base=$(git merge-base HEAD MERGE_HEAD) |
+ if test -z "$(submodule_diff $merge_base HEAD)"; then |
+ # Most up-to-date submodules are in MERGE_HEAD. |
+ head_ref=MERGE_HEAD |
+ else |
+ # Most up-to-date submodules are in HEAD. |
+ head_ref=HEAD |
+ fi |
+else |
+ # No merge in progress. Submodules must match HEAD. |
+ head_ref=HEAD |
+fi |
+ |
+submods=$(submodule_diff $head_ref) |
if test "$submods"; then |
echo "You are trying to commit changes to the following submodules:" 1>&2 |
echo 1>&2 |
@@ -23,8 +45,11 @@ EOF |
exit 1 |
fi |
-if [ -n "$(git ls-files .gitmodules)" ] && |
- [ -n "$(git diff-index --cached HEAD .gitmodules)" ]; then |
+gitmodules_diff() { |
+ git diff-index --cached "$1" .gitmodules |
+} |
+ |
+if test "$(git ls-files .gitmodules)" -a "$(gitmodules_diff $head_ref)"; then |
Ami GONE FROM CHROMIUM
2014/04/04 18:07:13
This change undid the benefit of r257470 because
t
spang
2014/04/04 18:14:02
My bad.
|
cat <<EOF 1>&2 |
You are trying to commit a change to .gitmodules. That is not allowed. |
To make changes to submodule names/paths, edit DEPS. |