blob: 65ed877aefd9837cefb8a4b2328b092f8c58bf99 [file] [log] [blame]
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +01001#!/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
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +01006substat=".git-submodule-status"
7
8command=$1
9shift
Daniel P. Berrange37b5e742017-10-27 10:49:58 +010010maybe_modules="$@"
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +010011
Daniel P. Berrangecc84d632017-10-20 15:02:43 +010012test -z "$GIT" && GIT=git
13
14error() {
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
Daniel P. Berrangef62bbee2017-10-26 13:52:26 +010024 echo "Alternatively you may disable automatic GIT submodule checkout"
25 echo "with:"
26 echo
Mike Frysinger4e811292017-11-27 12:49:44 -050027 echo " $ ./configure --disable-git-update"
Daniel P. Berrangef62bbee2017-10-26 13:52:26 +010028 echo
29 echo "and then manually update submodules prior to running make, with:"
30 echo
Laurent Vivierbff8a0b2018-01-19 11:32:33 +010031 echo " $ scripts/git-submodule.sh update $modules"
Daniel P. Berrangef62bbee2017-10-26 13:52:26 +010032 echo
Daniel P. Berrangecc84d632017-10-20 15:02:43 +010033 exit 1
34}
35
Daniel P. Berrange37b5e742017-10-27 10:49:58 +010036modules=""
37for m in $maybe_modules
38do
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
46done
47
Daniel P. Berrange49ad3cf2017-10-30 09:29:29 +010048if test -n "$maybe_modules" && ! test -e ".git"
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +010049then
50 echo "$0: unexpectedly called with submodules but no git checkout exists"
51 exit 1
52fi
53
54case "$command" in
55status)
Daniel P. Berrange49ad3cf2017-10-30 09:29:29 +010056 if test -z "$maybe_modules"
57 then
58 test -s ${substat} && exit 1 || exit 0
59 fi
60
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +010061 test -f "$substat" || exit 1
Juan Quintela1a920d22020-01-29 11:21:13 +010062 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
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +010070 ;;
71update)
Daniel P. Berrange49ad3cf2017-10-30 09:29:29 +010072 if test -z "$maybe_modules"
73 then
74 test -e $substat || touch $substat
75 exit 0
76 fi
77
Daniel P. Berrangecc84d632017-10-20 15:02:43 +010078 $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
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +010083 ;;
84esac
Daniel P. Berrangecc84d632017-10-20 15:02:43 +010085
86exit 0