]>
Commit | Line | Data |
---|---|---|
aef45d51 DB |
1 | #!/bin/sh |
2 | # | |
3 | # This code is licensed under the GPL version 2 or later. See | |
4 | # the COPYING file in the top-level directory. | |
5 | ||
aef45d51 DB |
6 | substat=".git-submodule-status" |
7 | ||
8 | command=$1 | |
9 | shift | |
37b5e74e | 10 | maybe_modules="$@" |
aef45d51 | 11 | |
7d7dbf9d DS |
12 | # if --with-git-submodules=ignore, do nothing |
13 | test "$command" = "ignore" && exit 0 | |
14 | ||
cc84d63a DB |
15 | test -z "$GIT" && GIT=git |
16 | ||
7d7dbf9d DS |
17 | cd "$(dirname "$0")/.." |
18 | ||
19 | update_error() { | |
cc84d63a DB |
20 | echo "$0: $*" |
21 | echo | |
22 | echo "Unable to automatically checkout GIT submodules '$modules'." | |
23 | echo "If you require use of an alternative GIT binary (for example to" | |
24 | echo "enable use of a transparent proxy), then please specify it by" | |
25 | echo "running configure by with the '--with-git' argument. e.g." | |
26 | echo | |
27 | echo " $ ./configure --with-git='tsocks git'" | |
28 | echo | |
f62bbee5 DB |
29 | echo "Alternatively you may disable automatic GIT submodule checkout" |
30 | echo "with:" | |
31 | echo | |
7d7dbf9d | 32 | echo " $ ./configure --with-git-submodules=validate" |
f62bbee5 DB |
33 | echo |
34 | echo "and then manually update submodules prior to running make, with:" | |
35 | echo | |
bff8a0bb | 36 | echo " $ scripts/git-submodule.sh update $modules" |
f62bbee5 | 37 | echo |
cc84d63a DB |
38 | exit 1 |
39 | } | |
40 | ||
7d7dbf9d DS |
41 | validate_error() { |
42 | if test "$1" = "validate"; then | |
43 | echo "GIT submodules checkout is out of date, and submodules" | |
44 | echo "configured for validate only. Please run" | |
45 | echo " scripts/git-submodule.sh update $maybe_modules" | |
46 | echo "from the source directory or call configure with" | |
47 | echo " --with-git-submodules=update" | |
48 | echo "To disable GIT submodules validation, use" | |
49 | echo " --with-git-submodules=ignore" | |
50 | fi | |
51 | exit 1 | |
52 | } | |
53 | ||
37b5e74e DB |
54 | modules="" |
55 | for m in $maybe_modules | |
56 | do | |
57 | $GIT submodule status $m 1> /dev/null 2>&1 | |
58 | if test $? = 0 | |
59 | then | |
60 | modules="$modules $m" | |
61 | else | |
62 | echo "warn: ignoring non-existent submodule $m" | |
63 | fi | |
64 | done | |
65 | ||
49ad3cfa | 66 | if test -n "$maybe_modules" && ! test -e ".git" |
aef45d51 DB |
67 | then |
68 | echo "$0: unexpectedly called with submodules but no git checkout exists" | |
69 | exit 1 | |
70 | fi | |
71 | ||
72 | case "$command" in | |
7d7dbf9d | 73 | status|validate) |
49ad3cfa DB |
74 | if test -z "$maybe_modules" |
75 | then | |
7d7dbf9d | 76 | test -s ${substat} && validate_error "$command" || exit 0 |
49ad3cfa DB |
77 | fi |
78 | ||
7d7dbf9d | 79 | test -f "$substat" || validate_error "$command" |
1a920d2b JQ |
80 | for module in $modules; do |
81 | CURSTATUS=$($GIT submodule status $module) | |
82 | OLDSTATUS=$(cat $substat | grep $module) | |
83 | if test "$CURSTATUS" != "$OLDSTATUS"; then | |
7d7dbf9d | 84 | validate_error "$command" |
1a920d2b JQ |
85 | fi |
86 | done | |
87 | exit 0 | |
aef45d51 DB |
88 | ;; |
89 | update) | |
49ad3cfa DB |
90 | if test -z "$maybe_modules" |
91 | then | |
92 | test -e $substat || touch $substat | |
93 | exit 0 | |
94 | fi | |
95 | ||
cc84d63a | 96 | $GIT submodule update --init $modules 1>/dev/null |
7d7dbf9d | 97 | test $? -ne 0 && update_error "failed to update modules" |
cc84d63a DB |
98 | |
99 | $GIT submodule status $modules > "${substat}" | |
7d7dbf9d | 100 | test $? -ne 0 && update_error "failed to save git submodule status" >&2 |
aef45d51 DB |
101 | ;; |
102 | esac | |
cc84d63a DB |
103 | |
104 | exit 0 |