OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
| 3 set_target_os () { |
| 4 # Get the os we're building for. On first run, this will be unset. |
| 5 target_os=$(git config target.os 2>/dev/null) |
| 6 if [ -z "$target_os" ]; then |
| 7 case $(uname -s) in |
| 8 Linux) target_os=unix ;; |
| 9 Darwin) target_os=mac ;; |
| 10 CYGWIN*|MINGW*) target_os=win ;; |
| 11 *) |
| 12 echo "[$solution] *** No target.os set in .git/config, and I can't" 1>&2 |
| 13 echo "[$solution] *** figure it out from 'uname -s'" 1>&2 |
| 14 exit 1 |
| 15 ;; |
| 16 esac |
| 17 git config target.os "$target_os" |
| 18 fi |
| 19 } |
| 20 |
| 21 update_submodule_url () { |
| 22 # If the submodule's URL in .gitmodules has changed, propagate the new |
| 23 # new URL down. This is the same as `git submodule sync`, but we do it |
| 24 # this way because `git submodule sync` is absurdly slow. |
| 25 new_url=$(git config -f .gitmodules "submodule.$1.url" 2>/dev/null) |
| 26 old_url=$(git config "submodule.$1.url" 2>/dev/null) |
| 27 if [ -n "$old_url" -a "$new_url" != "$old_url" ]; then |
| 28 git config "submodule.$1.url" "$new_url" |
| 29 if [ -e "$1"/.git ]; then |
| 30 ( cd $submod && git config remote.origin.url "$new_url" ) |
| 31 fi |
| 32 fi |
| 33 } |
| 34 |
| 35 process_submodule () { |
| 36 # Check whether this submodule should be ignored or updated. |
| 37 # If it's a new submodule, match the os specified in .gitmodules against |
| 38 # the os specified in .git/config. |
| 39 update_policy=$(git config --get "submodule.$1.update") |
| 40 if [ -z "$update_policy" ]; then |
| 41 submod_os=$(git config -f .gitmodules --get "submodule.$1.os") |
| 42 if [ -n "$submod_os" -a \ |
| 43 "$submod_os" != "all" -a \ |
| 44 "${submod_os/${target_os}/}" = "${submod_os}" ]; then |
| 45 update_policy=none |
| 46 else |
| 47 git submodule --quiet init "$1" |
| 48 update_policy=checkout |
| 49 fi |
| 50 git config "submodule.$1.update" $update_policy |
| 51 fi |
| 52 if [ "$update_policy" != "none" ]; then |
| 53 update_submodule_url "$1" |
| 54 echo "$solution/$1" |
| 55 fi |
| 56 } |
| 57 |
3 if [ -z "$*" ]; then | 58 if [ -z "$*" ]; then |
4 exit 0 | 59 exit 0 |
5 fi | 60 fi |
6 set -o pipefail | 61 set -o pipefail |
7 dir="$1" | 62 dir="$1" |
8 solution="${1%%/*}" | 63 solution="${1%%/*}" |
9 cd "$solution" | 64 cd "$solution" |
| 65 |
10 if [ "$solution" = "$1" ]; then | 66 if [ "$solution" = "$1" ]; then |
| 67 # Don't "pull" if checkout is not on a named branch |
11 shift | 68 shift |
12 # Don't "pull" if checkout is not on a named branch | |
13 if test "$2" = "pull" && ( ! git symbolic-ref HEAD >/dev/null 2>/dev/null ); t
hen | 69 if test "$2" = "pull" && ( ! git symbolic-ref HEAD >/dev/null 2>/dev/null ); t
hen |
14 first_args="$1 fetch" | 70 first_args="$1 fetch" |
15 else | 71 else |
16 first_args="$1 $2" | 72 first_args="$1 $2" |
17 fi | 73 fi |
18 shift 2 | 74 shift 2 |
19 $first_args $@ | sed "s/^/[$solution] /g" 1>&2 | 75 $first_args $@ | sed "s/^/[$solution] /g" 1>&2 |
20 if [ $? -ne 0 ]; then | 76 if [ $? -ne 0 ]; then |
21 exit $? | 77 exit $? |
22 fi | 78 fi |
23 "$GIT_EXE" submodule --quiet sync | 79 |
| 80 set_target_os |
| 81 |
24 "$GIT_EXE" ls-files -s | grep ^160000 | awk '{print $4}' | | 82 "$GIT_EXE" ls-files -s | grep ^160000 | awk '{print $4}' | |
25 while read submod; do | 83 while read submod; do |
26 # Check whether this submodule should be ignored or updated. | 84 process_submodule "$submod" |
27 # If it's a new submodule, match the os specified in .gitmodules against | |
28 # the os specified in .git/config. | |
29 update_policy=$(git config "submodule.$submod.update" 2>/dev/null) | |
30 if [ -z "$update_policy" ]; then | |
31 target_os=$(git config target.os 2>/dev/null) | |
32 submod_os=$(git config -f .gitmodules "submodule.$submod.os" 2>/dev/null) | |
33 if [ -n "$target_os" -a -n "$submod_os" ] && | |
34 [ "$submod_os" != "all" -a "$submod_os" != "$target_os" ]; then | |
35 update_policy=none | |
36 else | |
37 update_policy=checkout | |
38 fi | |
39 git config "submodule.$submod.update" $update_policy 2>/dev/null | |
40 fi | |
41 if [ "$update_policy" != "none" ]; then | |
42 echo "$solution/$submod" | |
43 fi | |
44 done | 85 done |
45 status=$? | 86 status=$? |
46 else | 87 else |
47 submodule="${1#*/}" | 88 submodule="${1#*/}" |
48 echo "[$solution] updating $submodule ..." | 89 echo "[$solution] updating $submodule" |
49 "$GIT_EXE" submodule update --quiet --init "$submodule" | | 90 "$GIT_EXE" submodule update --quiet "$submodule" | |
50 ( grep -v '^Skipping submodule' || true ) | sed "s|^|[$1] |g" | 91 ( grep -v '^Skipping submodule' || true ) | sed "s|^|[$1] |g" |
51 status=$? | 92 status=$? |
52 if [ "$status" -ne "0" ]; then | 93 if [ "$status" -ne "0" ]; then |
53 echo "[$solution] FAILED to update $submodule" | 94 echo "[$solution] FAILED to update $submodule" |
54 fi | 95 fi |
55 fi | 96 fi |
56 exit $status | 97 exit $status |
OLD | NEW |