blob: 4765a2f519ed83a0a7b740a289887f34463263c6 [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.
[email protected]547c64b2013-04-12 10:06:4721 target_os=$(git config --get-all target.os 2>/dev/null)
[email protected]e5599b12012-12-28 23:14:1822 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")
[email protected]547c64b2013-04-12 10:06:4758 if [ -n "$submod_os" -a "$submod_os" != "all" ]; then
[email protected]e5599b12012-12-28 23:14:1859 update_policy=none
[email protected]547c64b2013-04-12 10:06:4760 for os in $target_os; do
61 if [ "${submod_os/${os}/}" != "${submod_os}" ]; then
62 update_policy=checkout
63 fi
64 done
[email protected]e5599b12012-12-28 23:14:1865 else
[email protected]e5599b12012-12-28 23:14:1866 update_policy=checkout
67 fi
[email protected]547c64b2013-04-12 10:06:4768 if [ "$update_policy" != "none" ]; then
69 git submodule --quiet init "$1"
70 fi
[email protected]e5599b12012-12-28 23:14:1871 git config "submodule.$1.update" $update_policy
72 fi
[email protected]3113c8b2013-02-27 19:50:3673 ignore_policy=$(git config --get "submodule.$1.ignore")
74 if [ -z "$ignore_policy" ]; then
75 git config "submodule.$1.ignore" all
76 fi
[email protected]e5599b12012-12-28 23:14:1877 if [ "$update_policy" != "none" ]; then
78 update_submodule_url "$1"
79 echo "$solution/$1"
80 fi
81}
82
[email protected]c1200a82012-10-25 19:26:3183if [ -z "$*" ]; then
84 exit 0
85fi
86set -o pipefail
87dir="$1"
88solution="${1%%/*}"
[email protected]0c16fe62013-02-22 19:28:2389cd "$solution" 1>/dev/null
[email protected]e5599b12012-12-28 23:14:1890
[email protected]c1200a82012-10-25 19:26:3191if [ "$solution" = "$1" ]; then
[email protected]d2d18612013-01-23 19:36:5192 # Skip git checkouts not managed by crup.
93 if ! grep -q -s "The Chromium Authors" ".git/description"; then
94 echo "Skipping unmanaged git directory $1" 1>&2
95 exit 0
96 fi
97
[email protected]3113c8b2013-02-27 19:50:3698 # Set default behavior to ignore diffs in submodule checkouts
99 diff_policy=$(git config --get "diff.ignoreSubmodules")
100 if [ -z "$diff_policy" ]; then
101 git config diff.ignoreSubmodules all
102 fi
103
104 # Don't "pull" if checkout is not on a named branch
[email protected]e5599b12012-12-28 23:14:18105 shift
[email protected]69aea162013-02-15 18:52:51106 if test $# -ne 0; then
107 update_toplevel "$@"
[email protected]c1200a82012-10-25 19:26:31108 fi
[email protected]e5599b12012-12-28 23:14:18109
110 set_target_os
111
[email protected]fdcecad2013-03-22 22:26:04112 git ls-files -s | grep ^160000 | awk '{print $4}' |
[email protected]a79f5cf2012-12-20 23:57:46113 while read submod; do
[email protected]e5599b12012-12-28 23:14:18114 process_submodule "$submod"
[email protected]a79f5cf2012-12-20 23:57:46115 done
[email protected]c1200a82012-10-25 19:26:31116 status=$?
117else
118 submodule="${1#*/}"
[email protected]e5599b12012-12-28 23:14:18119 echo "[$solution] updating $submodule"
[email protected]fdcecad2013-03-22 22:26:04120 git submodule update --recursive --quiet "$submodule" |
121 ( grep -v '^Skipping submodule' || true ) | sed "s|^|[$1] |g" 2>/dev/null
[email protected]c1200a82012-10-25 19:26:31122 status=$?
123 if [ "$status" -ne "0" ]; then
124 echo "[$solution] FAILED to update $submodule"
125 fi
126fi
127exit $status