-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-relative.sh
executable file
·57 lines (49 loc) · 1.52 KB
/
init-relative.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Initialize the submodules with URLs overriden to subpaths relative to the
# path of the origin remote.
#
# This is useful for servers that are offline (no Internet connectivity),
# and that thus have all submodule repositories available at the
# same path as the parent repository.
#
# NOTE: this script is not recursive, it initializes URLs for submodules nested
# only up to depth = 1 (i.e. top-level plus one more level).
# Make command failures fatal
set -e
SELF_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"
source ${SELF_DIR}/git-alias.sh
if [ "$#" -eq 1 ]
then
BASE_URL="$1"
else
if [ "$#" -eq 0 ]
then
BASE_URL="$(git_remote_url origin)"
if [ -z "$BASE_URL" ]
then
echo "ERROR: no base URL passed; failed to get URL of origin remote" 1>&2
exit 1
fi
else
echo "Usage: $0 [base_url]" 1>&2
exit 1
fi
fi
echo "Initializing submodule URLs relative: $BASE_URL"
# Print commands
set -x
declare -a "mods=($(git submodule | sed -n 's/^.[A-Fa-f0-9]\+\s\+\(\S\+\).*/\1/p'))"
for mod in ${mods[@]}
do
git config submodule.${mod}.url ${BASE_URL}/${mod}
git submodule update --init -- ${mod}
pushd ${mod}
declare -a "nested_mods=($(git submodule | sed -n 's/^.[A-Fa-f0-9]\+\s\+\(\S\+\).*/\1/p'))"
for nested_mod in ${nested_mods[@]}
do
git config submodule.${nested_mod}.url ${BASE_URL}/${mod}/${nested_mod}
done
git submodule init
popd
done
git submodule update --init --recursive