• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3submodule_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
11if 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
20else
21  # No merge in progress. Submodules must match HEAD.
22  head_ref=HEAD
23fi
24
25submods=$(submodule_diff $head_ref)
26if 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
32Submodule commits are not allowed.  Please run:
33
34  git status --ignore-submodules=dirty
35
36and/or:
37
38  git diff-index --cached --ignore-submodules=dirty HEAD
39
40... to see what's in your index.
41
42If you're really and truly trying to roll the version of a submodule, you should
43commit the new version to DEPS, instead.
44EOF
45  exit 1
46fi
47
48gitmodules_diff() {
49  git diff-index --cached "$1" .gitmodules
50}
51
52if [ "$(git ls-files .gitmodules)" ] && [ "$(gitmodules_diff $head_ref)" ]; then
53  cat <<EOF 1>&2
54You are trying to commit a change to .gitmodules.  That is not allowed.
55To make changes to submodule names/paths, edit DEPS.
56EOF
57  exit 1
58fi
59
60exit 0
61