]>
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 | |
6f3ae23b | 12 | # if not running in a git checkout, do nothing |
7d7dbf9d DS |
13 | test "$command" = "ignore" && exit 0 |
14 | ||
50cfed80 | 15 | test -z "$GIT" && GIT=$(command -v git) |
cc84d63a | 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" | |
50cfed80 PB |
24 | echo "enable use of a transparent proxy), please disable automatic" |
25 | echo "GIT submodule checkout with:" | |
f62bbee5 | 26 | echo |
6f3ae23b | 27 | echo " $ ./configure --disable-download" |
f62bbee5 DB |
28 | echo |
29 | echo "and then manually update submodules prior to running make, with:" | |
30 | echo | |
50cfed80 | 31 | echo " $ GIT='tsocks git' scripts/git-submodule.sh update $modules" |
f62bbee5 | 32 | echo |
cc84d63a DB |
33 | exit 1 |
34 | } | |
35 | ||
7d7dbf9d DS |
36 | validate_error() { |
37 | if test "$1" = "validate"; then | |
38 | echo "GIT submodules checkout is out of date, and submodules" | |
39 | echo "configured for validate only. Please run" | |
40 | echo " scripts/git-submodule.sh update $maybe_modules" | |
41 | echo "from the source directory or call configure with" | |
6f3ae23b | 42 | echo " --enable-download" |
7d7dbf9d DS |
43 | fi |
44 | exit 1 | |
45 | } | |
46 | ||
d120116b PB |
47 | check_updated() { |
48 | local CURSTATUS OLDSTATUS | |
49 | CURSTATUS=$($GIT submodule status $module) | |
50 | OLDSTATUS=$(grep $module $substat) | |
51 | test "$CURSTATUS" = "$OLDSTATUS" | |
52 | } | |
53 | ||
dd84a906 DB |
54 | if test -n "$maybe_modules" && ! test -e ".git" |
55 | then | |
56 | echo "$0: unexpectedly called with submodules but no git checkout exists" | |
57 | exit 1 | |
58 | fi | |
59 | ||
50cfed80 PB |
60 | if test -n "$maybe_modules" && test -z "$GIT" |
61 | then | |
62 | echo "$0: unexpectedly called with submodules but git binary not found" | |
63 | exit 1 | |
64 | fi | |
65 | ||
37b5e74e DB |
66 | modules="" |
67 | for m in $maybe_modules | |
68 | do | |
69 | $GIT submodule status $m 1> /dev/null 2>&1 | |
70 | if test $? = 0 | |
71 | then | |
72 | modules="$modules $m" | |
73 | else | |
74 | echo "warn: ignoring non-existent submodule $m" | |
75 | fi | |
76 | done | |
77 | ||
aef45d51 | 78 | case "$command" in |
7d7dbf9d | 79 | status|validate) |
7d7dbf9d | 80 | test -f "$substat" || validate_error "$command" |
fdb8fd8c | 81 | test -z "$maybe_modules" && exit 0 |
1a920d2b | 82 | for module in $modules; do |
d120116b | 83 | check_updated $module || validate_error "$command" |
1a920d2b JQ |
84 | done |
85 | exit 0 | |
aef45d51 DB |
86 | ;; |
87 | update) | |
fdb8fd8c PB |
88 | test -e $substat || touch $substat |
89 | test -z "$maybe_modules" && exit 0 | |
49ad3cfa | 90 | |
cc84d63a | 91 | $GIT submodule update --init $modules 1>/dev/null |
7d7dbf9d | 92 | test $? -ne 0 && update_error "failed to update modules" |
d120116b PB |
93 | for module in $modules; do |
94 | check_updated $module || echo Updated "$module" | |
95 | done | |
cc84d63a | 96 | |
fdb8fd8c PB |
97 | (while read -r; do |
98 | for module in $modules; do | |
99 | case $REPLY in | |
100 | *" $module "*) continue 2 ;; | |
101 | esac | |
102 | done | |
103 | printf '%s\n' "$REPLY" | |
104 | done | |
105 | $GIT submodule status $modules | |
106 | test $? -ne 0 && update_error "failed to save git submodule status" >&2) < $substat > $substat.new | |
107 | mv -f $substat.new $substat | |
aef45d51 DB |
108 | ;; |
109 | esac | |
cc84d63a DB |
110 | |
111 | exit 0 |