xref: /openbmc/qemu/scripts/git-submodule.sh (revision 520e210c)
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
6substat=".git-submodule-status"
7
8command=$1
9shift
10maybe_modules="$@"
11
12test -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
24    echo "Alternatively you may disable automatic GIT submodule checkout"
25    echo "with:"
26    echo
27    echo " $ ./configure --disable-git-update"
28    echo
29    echo "and then manually update submodules prior to running make, with:"
30    echo
31    echo " $ scripts/git-submodule.sh update $modules"
32    echo
33    exit 1
34}
35
36modules=""
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
48if test -n "$maybe_modules" && ! test -e ".git"
49then
50    echo "$0: unexpectedly called with submodules but no git checkout exists"
51    exit 1
52fi
53
54case "$command" in
55status)
56    if test -z "$maybe_modules"
57    then
58         test -s ${substat} && exit 1 || exit 0
59    fi
60
61    test -f "$substat" || exit 1
62    CURSTATUS=$($GIT submodule status $modules)
63    OLDSTATUS=$(cat $substat)
64    test "$CURSTATUS" = "$OLDSTATUS"
65    exit $?
66    ;;
67update)
68    if test -z "$maybe_modules"
69    then
70        test -e $substat || touch $substat
71        exit 0
72    fi
73
74    $GIT submodule update --init $modules 1>/dev/null
75    test $? -ne 0 && error "failed to update modules"
76
77    $GIT submodule status $modules > "${substat}"
78    test $? -ne 0 && error "failed to save git submodule status" >&2
79    ;;
80esac
81
82exit 0
83