]>
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 | |
cc84d63a DB |
12 | test -z "$GIT" && GIT=git |
13 | ||
14 | error() { | |
15 | echo "$0: $*" | |
16 | echo | |
17 | echo "Unable to automatically checkout GIT submodules '$modules'." | |
18 | echo "If you require use of an alternative GIT binary (for example to" | |
19 | echo "enable use of a transparent proxy), then please specify it by" | |
20 | echo "running configure by with the '--with-git' argument. e.g." | |
21 | echo | |
22 | echo " $ ./configure --with-git='tsocks git'" | |
23 | echo | |
f62bbee5 DB |
24 | echo "Alternatively you may disable automatic GIT submodule checkout" |
25 | echo "with:" | |
26 | echo | |
4e811296 | 27 | echo " $ ./configure --disable-git-update" |
f62bbee5 DB |
28 | echo |
29 | echo "and then manually update submodules prior to running make, with:" | |
30 | echo | |
bff8a0bb | 31 | echo " $ scripts/git-submodule.sh update $modules" |
f62bbee5 | 32 | echo |
cc84d63a DB |
33 | exit 1 |
34 | } | |
35 | ||
37b5e74e DB |
36 | modules="" |
37 | for m in $maybe_modules | |
38 | do | |
39 | $GIT submodule status $m 1> /dev/null 2>&1 | |
40 | if test $? = 0 | |
41 | then | |
42 | modules="$modules $m" | |
43 | else | |
44 | echo "warn: ignoring non-existent submodule $m" | |
45 | fi | |
46 | done | |
47 | ||
49ad3cfa | 48 | if test -n "$maybe_modules" && ! test -e ".git" |
aef45d51 DB |
49 | then |
50 | echo "$0: unexpectedly called with submodules but no git checkout exists" | |
51 | exit 1 | |
52 | fi | |
53 | ||
54 | case "$command" in | |
55 | status) | |
49ad3cfa DB |
56 | if test -z "$maybe_modules" |
57 | then | |
58 | test -s ${substat} && exit 1 || exit 0 | |
59 | fi | |
60 | ||
aef45d51 | 61 | test -f "$substat" || exit 1 |
1a920d2b JQ |
62 | for module in $modules; do |
63 | CURSTATUS=$($GIT submodule status $module) | |
64 | OLDSTATUS=$(cat $substat | grep $module) | |
65 | if test "$CURSTATUS" != "$OLDSTATUS"; then | |
66 | exit 1 | |
67 | fi | |
68 | done | |
69 | exit 0 | |
aef45d51 DB |
70 | ;; |
71 | update) | |
49ad3cfa DB |
72 | if test -z "$maybe_modules" |
73 | then | |
74 | test -e $substat || touch $substat | |
75 | exit 0 | |
76 | fi | |
77 | ||
cc84d63a DB |
78 | $GIT submodule update --init $modules 1>/dev/null |
79 | test $? -ne 0 && error "failed to update modules" | |
80 | ||
81 | $GIT submodule status $modules > "${substat}" | |
82 | test $? -ne 0 && error "failed to save git submodule status" >&2 | |
aef45d51 DB |
83 | ;; |
84 | esac | |
cc84d63a DB |
85 | |
86 | exit 0 |