OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # A convenience script to largely replicate the behavior of `gclient sync` in a | 6 # A convenience script to largely replicate the behavior of `gclient sync` in a |
7 # submodule-based checkout. Fetches latest commits for top-level solutions; | 7 # submodule-based checkout. Fetches latest commits for top-level solutions; |
8 # updates submodules; and runs post-sync hooks. | 8 # updates submodules; and runs post-sync hooks. |
9 | 9 |
10 # Auto-update depot_tools | 10 # Auto-update depot_tools |
(...skipping 27 matching lines...) Expand all Loading... |
38 fi | 38 fi |
39 | 39 |
40 if ( echo test | xargs -I bar true 2>/dev/null ); then | 40 if ( echo test | xargs -I bar true 2>/dev/null ); then |
41 replace_arg="-I replace_arg" | 41 replace_arg="-I replace_arg" |
42 else | 42 else |
43 replace_arg="-ireplace_arg" | 43 replace_arg="-ireplace_arg" |
44 fi | 44 fi |
45 | 45 |
46 usage() { | 46 usage() { |
47 cat <<EOF | 47 cat <<EOF |
48 Usage: git-crup [-n|--dry-run] [--fetch] [-j|--jobs [jobs]] | 48 Usage: git-crup [-n|--dry-run] [--fetch|--sync] [-j|--jobs [jobs]] |
49 [--no-hooks] [<args to git-pull or git-fetch>] | 49 [--no-hooks] [<args to git-pull or git-fetch>] |
50 EOF | 50 EOF |
51 } | 51 } |
52 | 52 |
53 serial_update() { | 53 serial_update() { |
54 ( cd "$1" | 54 ( cd "$1" |
55 $GIT_EXE $pull $pull_args -q origin | sed "s/^/[$1] /g" | 55 if test -n "$toplevel_cmd"; then |
56 if [ $? -ne 0 ]; then | 56 $toplevel_cmd | sed "s/^/[$1] /g" |
57 return $? | 57 if [ $? -ne 0 ]; then |
| 58 return $? |
| 59 fi |
58 fi | 60 fi |
59 $GIT_EXE submodule --quiet sync | 61 $GIT_EXE submodule --quiet sync |
60 $GIT_EXE ls-files -s | grep ^160000 | awk '{print $4}' | | 62 $GIT_EXE ls-files -s | grep ^160000 | awk '{print $4}' | |
61 while read submod; do | 63 while read submod; do |
62 "$crup_runner" "$1/$submod" | 64 "$crup_runner" "$1/$submod" |
63 done | 65 done |
64 ) | 66 ) |
65 } | 67 } |
66 | 68 |
67 while test $# -ne 0; do | 69 while test $# -ne 0; do |
(...skipping 18 matching lines...) Expand all Loading... |
86 -n|--dry-run) | 88 -n|--dry-run) |
87 ECHO=echo | 89 ECHO=echo |
88 ;; | 90 ;; |
89 -h|--help) | 91 -h|--help) |
90 usage | 92 usage |
91 exit 0 | 93 exit 0 |
92 ;; | 94 ;; |
93 --fetch) | 95 --fetch) |
94 pull=fetch | 96 pull=fetch |
95 ;; | 97 ;; |
| 98 --sync) |
| 99 pull= |
| 100 ;; |
96 --no-hooks|--nohooks) | 101 --no-hooks|--nohooks) |
97 hooks=no | 102 hooks=no |
98 ;; | 103 ;; |
99 *) | 104 *) |
100 pull_args="$pull_args $1" | 105 pull_args="$pull_args $1" |
101 break | 106 break |
102 ;; | 107 ;; |
103 esac | 108 esac |
104 shift | 109 shift |
105 done | 110 done |
(...skipping 11 matching lines...) Expand all Loading... |
117 | 122 |
118 if ( echo test test | xargs -P 2 true 2>/dev/null ); then | 123 if ( echo test test | xargs -P 2 true 2>/dev/null ); then |
119 xargs_parallel=yes | 124 xargs_parallel=yes |
120 else | 125 else |
121 if test "$j" != "1"; then | 126 if test "$j" != "1"; then |
122 echo "Warning: parallel execution is not supported on this platform." 1>&2 | 127 echo "Warning: parallel execution is not supported on this platform." 1>&2 |
123 fi | 128 fi |
124 xargs_parallel=no | 129 xargs_parallel=no |
125 fi | 130 fi |
126 | 131 |
| 132 if test -n "$pull"; then |
| 133 toplevel_cmd="$GIT_EXE $pull $pull_args -q origin" |
| 134 else |
| 135 toplevel_cmd= |
| 136 fi |
| 137 |
127 set -o pipefail | 138 set -o pipefail |
128 if test "$xargs_parallel" = "yes"; then | 139 if test "$xargs_parallel" = "yes"; then |
129 ( ls -d */.git | sed 's/\/\.git$//' | | 140 ( ls -d */.git | sed 's/\/\.git$//' | |
130 xargs $max_lines $replace_arg -P "$j" \ | 141 xargs $max_lines $replace_arg -P "$j" \ |
131 "$crup_runner" replace_arg $GIT_EXE $pull $pull_args -q origin | | 142 "$crup_runner" replace_arg $toplevel_cmd | |
132 xargs $max_lines -P "$j" "$crup_runner" ) | 143 xargs $max_lines -P "$j" "$crup_runner" ) |
133 else | 144 else |
134 ls -d */.git | | 145 ls -d */.git | |
135 while read gitdir; do | 146 while read gitdir; do |
136 serial_update "${gitdir%%/.git}" | 147 serial_update "${gitdir%%/.git}" |
137 done | 148 done |
138 fi | 149 fi |
139 | 150 |
140 status=$? | 151 status=$? |
141 | 152 |
142 if [ "$status" -ne 0 ]; then | 153 if [ "$status" -ne 0 ]; then |
143 cat 1>&2 <<EOF | 154 cat 1>&2 <<EOF |
144 Please check the preceding terminal output for error messages. | 155 Please check the preceding terminal output for error messages. |
145 Run 'git submodule status' to see the current state of submodule checkouts. | 156 Run 'git submodule status' to see the current state of submodule checkouts. |
146 EOF | 157 EOF |
147 exit $status | 158 exit $status |
148 fi | 159 fi |
149 | 160 |
150 if [ "$hooks" = "yes" ]; then | 161 if [ "$hooks" = "yes" ]; then |
151 "$runhooks" | 162 "$runhooks" |
152 status=$? | 163 status=$? |
153 fi | 164 fi |
154 | 165 |
155 echo | 166 echo |
156 exit $status | 167 exit $status |
OLD | NEW |