blob: c8f5822c22a13852f6c2f3a7259cd0af80226ea1 [file] [log] [blame]
[email protected]c1200a82012-10-25 19:26:311#!/bin/bash
2
[email protected]69aea162013-02-15 18:52:513update_toplevel () {
4 # Don't "pull" if checkout is not on a named branch
5 if test "$2" = "pull" && ( ! git symbolic-ref HEAD >/dev/null 2>/dev/null ); then
6 first_args="$1 fetch"
7 else
8 first_args="$1 $2"
9 fi
10 shift 2
11 echo "[$solution] $first_args $@" 1>&2
12 $first_args $@ | sed "s/^/[$solution] /g" 1>&2
13 status=$?
14 if [ "$status" -ne 0 ]; then
15 exit $status
16 fi
17}
18
[email protected]e5599b12012-12-28 23:14:1819set_target_os () {
20 # Get the os we're building for. On first run, this will be unset.
21 target_os=$(git config target.os 2>/dev/null)
22 if [ -z "$target_os" ]; then
23 case $(uname -s) in
24 Linux) target_os=unix ;;
25 Darwin) target_os=mac ;;
26 CYGWIN*|MINGW*) target_os=win ;;
27 *)
28 echo "[$solution] *** No target.os set in .git/config, and I can't" 1>&2
29 echo "[$solution] *** figure it out from 'uname -s'" 1>&2
30 exit 1
31 ;;
32 esac
33 git config target.os "$target_os"
34 fi
35}
36
37update_submodule_url () {
38 # If the submodule's URL in .gitmodules has changed, propagate the new
39 # new URL down. This is the same as `git submodule sync`, but we do it
40 # this way because `git submodule sync` is absurdly slow.
41 new_url=$(git config -f .gitmodules "submodule.$1.url" 2>/dev/null)
42 old_url=$(git config "submodule.$1.url" 2>/dev/null)
43 if [ -n "$old_url" -a "$new_url" != "$old_url" ]; then
44 git config "submodule.$1.url" "$new_url"
45 if [ -e "$1"/.git ]; then
46 ( cd $submod && git config remote.origin.url "$new_url" )
47 fi
48 fi
49}
50
51process_submodule () {
52 # Check whether this submodule should be ignored or updated.
53 # If it's a new submodule, match the os specified in .gitmodules against
54 # the os specified in .git/config.
55 update_policy=$(git config --get "submodule.$1.update")
56 if [ -z "$update_policy" ]; then
57 submod_os=$(git config -f .gitmodules --get "submodule.$1.os")
58 if [ -n "$submod_os" -a \
59 "$submod_os" != "all" -a \
60 "${submod_os/${target_os}/}" = "${submod_os}" ]; then
61 update_policy=none
62 else
63 git submodule --quiet init "$1"
64 update_policy=checkout
65 fi
66 git config "submodule.$1.update" $update_policy
67 fi
[email protected]3113c8b2013-02-27 19:50:3668 ignore_policy=$(git config --get "submodule.$1.ignore")
69 if [ -z "$ignore_policy" ]; then
70 git config "submodule.$1.ignore" all
71 fi
[email protected]e5599b12012-12-28 23:14:1872 if [ "$update_policy" != "none" ]; then
73 update_submodule_url "$1"
74 echo "$solution/$1"
75 fi
76}
77
[email protected]c1200a82012-10-25 19:26:3178if [ -z "$*" ]; then
79 exit 0
80fi
81set -o pipefail
82dir="$1"
83solution="${1%%/*}"
[email protected]0c16fe62013-02-22 19:28:2384cd "$solution" 1>/dev/null
[email protected]e5599b12012-12-28 23:14:1885
[email protected]c1200a82012-10-25 19:26:3186if [ "$solution" = "$1" ]; then
[email protected]d2d18612013-01-23 19:36:5187 # Skip git checkouts not managed by crup.
88 if ! grep -q -s "The Chromium Authors" ".git/description"; then
89 echo "Skipping unmanaged git directory $1" 1>&2
90 exit 0
91 fi
92
[email protected]3113c8b2013-02-27 19:50:3693 # Set default behavior to ignore diffs in submodule checkouts
94 diff_policy=$(git config --get "diff.ignoreSubmodules")
95 if [ -z "$diff_policy" ]; then
96 git config diff.ignoreSubmodules all
97 fi
98
99 # Don't "pull" if checkout is not on a named branch
[email protected]e5599b12012-12-28 23:14:18100 shift
[email protected]69aea162013-02-15 18:52:51101 if test $# -ne 0; then
102 update_toplevel "$@"
[email protected]c1200a82012-10-25 19:26:31103 fi
[email protected]e5599b12012-12-28 23:14:18104
105 set_target_os
106
[email protected]c1200a82012-10-25 19:26:31107 "$GIT_EXE" ls-files -s | grep ^160000 | awk '{print $4}' |
[email protected]a79f5cf2012-12-20 23:57:46108 while read submod; do
[email protected]e5599b12012-12-28 23:14:18109 process_submodule "$submod"
[email protected]a79f5cf2012-12-20 23:57:46110 done
[email protected]c1200a82012-10-25 19:26:31111 status=$?
112else
113 submodule="${1#*/}"
[email protected]e5599b12012-12-28 23:14:18114 echo "[$solution] updating $submodule"
115 "$GIT_EXE" submodule update --quiet "$submodule" |
[email protected]c1200a82012-10-25 19:26:31116 ( grep -v '^Skipping submodule' || true ) | sed "s|^|[$1] |g"
117 status=$?
118 if [ "$status" -ne "0" ]; then
119 echo "[$solution] FAILED to update $submodule"
120 fi
121fi
122exit $status