| 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 orig_args="$@" |
| 11 if [ -z "$GIT_CRUP_REINVOKE" ]; then | |
| 12 update_depot_tools || exit 1 | |
| 13 GIT_CRUP_REINVOKE=1 exec bash "$0" "$@" | |
| 14 fi | |
| 15 | |
| 16 export GIT_MERGE_AUTOEDIT=0 | |
| 17 | |
| 18 ECHO= | 11 ECHO= |
| 19 pull=pull | 12 pull=pull |
| 20 pull_args= | 13 pull_args= |
| 21 hooks=yes | 14 hooks=yes |
| 22 j=10 | 15 j=10 |
| 23 crup_runner="crup-runner.sh" | 16 crup_runner="crup-runner.sh" |
| 24 runhooks="git-runhooks" | |
| 25 | |
| 26 kernel_name=$(uname -s) | |
| 27 if [ "${kernel_name:0:5}" = "MINGW" -o "${kernel_name:0:6}" = "CYGWIN" ]; then | |
| 28 GIT_EXE=git.exe | |
| 29 else | |
| 30 GIT_EXE=git | |
| 31 fi | |
| 32 export GIT_EXE | |
| 33 | |
| 34 if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then | |
| 35 max_lines="--max-lines=1" | |
| 36 else | |
| 37 max_lines="-L 1" | |
| 38 fi | |
| 39 | |
| 40 if ( echo test | xargs -I bar true 2>/dev/null ); then | |
| 41 replace_arg="-I replace_arg" | |
| 42 else | |
| 43 replace_arg="-ireplace_arg" | |
| 44 fi | |
| 45 | 17 |
| 46 usage() { | 18 usage() { |
| 47 cat <<EOF | 19 cat <<EOF |
| 48 Usage: git-crup [-n|--dry-run] [--fetch|--sync] [-j|--jobs [jobs]] | 20 Usage: git-crup [-n|--dry-run] [--fetch|--sync] [-j|--jobs [jobs]] |
| 49 [--no-hooks] [<args to git-pull or git-fetch>] | 21 [--no-hooks] [<args to git-pull or git-fetch>] |
| 22 |
| 23 -n, --dry-run Don't do anything; just show what would have been done. |
| 24 --fetch Run 'git fetch' on top-level sources, but don't merge. |
| 25 --sync Don't do anything at all to the top-level sources. |
| 26 -j, --jobs Run this many jobs in parallel. |
| 27 --no-hooks Don't run hooks (e.g., to generate build files) after |
| 28 updating. |
| 50 EOF | 29 EOF |
| 51 } | 30 } |
| 52 | 31 |
| 53 serial_update() { | 32 serial_update() { |
| 54 ( cd "$1" | 33 ( cd "$1" |
| 55 if test -n "$toplevel_cmd"; then | 34 if test -n "$toplevel_cmd"; then |
| 56 $toplevel_cmd | sed "s/^/[$1] /g" | 35 $ECHO $toplevel_cmd | sed "s/^/[$1] /g" |
| 57 if [ $? -ne 0 ]; then | 36 if [ $? -ne 0 ]; then |
| 58 return $? | 37 return $? |
| 59 fi | 38 fi |
| 60 fi | 39 fi |
| 61 $GIT_EXE submodule --quiet sync | 40 $ECHO git submodule --quiet sync |
| 62 $GIT_EXE ls-files -s | grep ^160000 | awk '{print $4}' | | 41 $ECHO git ls-files -s | grep ^160000 | awk '{print $4}' | |
| 63 while read submod; do | 42 while read submod; do |
| 64 "$crup_runner" "$1/$submod" | 43 $ECHO "$crup_runner" "$1/$submod" |
| 65 done | 44 done |
| 66 ) | 45 ) |
| 67 } | 46 } |
| 68 | 47 |
| 69 while test $# -ne 0; do | 48 while test $# -ne 0; do |
| 70 case "$1" in | 49 case "$1" in |
| 71 -j[0-9]*) | 50 -j[0-9]*) |
| 72 j=$(echo "$1" | cut -c3-) | 51 j=$(echo "$1" | cut -c3-) |
| 73 ;; | 52 ;; |
| 74 --jobs=[0-9]*) | 53 --jobs=[0-9]*) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 102 hooks=no | 81 hooks=no |
| 103 ;; | 82 ;; |
| 104 *) | 83 *) |
| 105 pull_args="$pull_args $1" | 84 pull_args="$pull_args $1" |
| 106 break | 85 break |
| 107 ;; | 86 ;; |
| 108 esac | 87 esac |
| 109 shift | 88 shift |
| 110 done | 89 done |
| 111 | 90 |
| 91 # Auto-update depot_tools. |
| 92 if [ -z "$GIT_CRUP_REINVOKE" ]; then |
| 93 kernel_name="\$(uname -s)" |
| 94 if [ "\${kernel_name:0:5}" = "MINGW" ]; then |
| 95 cmd '/C update_depot_tools.bat' |
| 96 else |
| 97 update_depot_tools |
| 98 fi |
| 99 GIT_CRUP_REINVOKE=1 exec bash "$0" $orig_args |
| 100 fi |
| 101 |
| 112 while test "$PWD" != "/"; do | 102 while test "$PWD" != "/"; do |
| 113 if test -f "$PWD/src/.gitmodules"; then | 103 if test -f "$PWD/src/.gitmodules"; then |
| 114 break | 104 break |
| 115 fi | 105 fi |
| 116 cd .. | 106 cd .. |
| 117 done | 107 done |
| 118 if test "$PWD" = "/"; then | 108 if test "$PWD" = "/"; then |
| 119 echo "Could not find the root of your checkout; aborting." 1>&2 | 109 echo "Could not find the root of your checkout; aborting." 1>&2 |
| 120 exit 1 | 110 exit 1 |
| 121 fi | 111 fi |
| 122 | 112 |
| 113 export GIT_MERGE_AUTOEDIT=no |
| 114 |
| 115 if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then |
| 116 max_lines="--max-lines=1" |
| 117 else |
| 118 max_lines="-L 1" |
| 119 fi |
| 120 |
| 121 if ( echo test | xargs -I bar true 2>/dev/null ); then |
| 122 replace_arg="-I replace_arg" |
| 123 else |
| 124 replace_arg="-ireplace_arg" |
| 125 fi |
| 126 |
| 123 if ( echo test test | xargs -P 2 true 2>/dev/null ); then | 127 if ( echo test test | xargs -P 2 true 2>/dev/null ); then |
| 124 xargs_parallel=yes | 128 xargs_parallel=yes |
| 125 else | 129 else |
| 126 if test "$j" != "1"; then | 130 if test "$j" != "1"; then |
| 127 echo "Warning: parallel execution is not supported on this platform." 1>&2 | 131 echo "Warning: parallel execution is not supported on this platform." 1>&2 |
| 128 fi | 132 fi |
| 129 xargs_parallel=no | 133 xargs_parallel=no |
| 130 fi | 134 fi |
| 131 | 135 |
| 132 if test -n "$pull"; then | 136 if test -n "$pull"; then |
| 133 toplevel_cmd="$GIT_EXE $pull $pull_args -q origin" | 137 toplevel_cmd="git $pull $pull_args -q origin" |
| 134 else | 138 else |
| 135 toplevel_cmd= | 139 toplevel_cmd= |
| 136 fi | 140 fi |
| 137 | 141 |
| 138 set -o pipefail | 142 set -o pipefail |
| 139 if test "$xargs_parallel" = "yes"; then | 143 if test "$xargs_parallel" = "yes"; then |
| 140 ( ls -d */.git | sed 's/\/\.git$//' | | 144 ( ls -d */.git | sed 's/\/\.git$//' | |
| 141 xargs $max_lines $replace_arg -P "$j" \ | 145 xargs $max_lines $replace_arg -P "$j" \ |
| 142 "$crup_runner" replace_arg $toplevel_cmd | | 146 "$crup_runner" replace_arg $ECHO $toplevel_cmd | |
| 143 xargs $max_lines -P "$j" "$crup_runner" ) | 147 xargs $max_lines -P "$j" $ECHO "$crup_runner" ) |
| 144 else | 148 else |
| 145 ls -d */.git | | 149 ls -d */.git | |
| 146 while read gitdir; do | 150 while read gitdir; do |
| 147 serial_update "${gitdir%%/.git}" | 151 serial_update "${gitdir%%/.git}" |
| 148 done | 152 done |
| 149 fi | 153 fi |
| 150 | 154 |
| 151 status=$? | 155 status=$? |
| 152 | 156 |
| 153 if [ "$status" -ne 0 ]; then | 157 if [ "$status" -ne 0 ]; then |
| 154 cat 1>&2 <<EOF | 158 cat 1>&2 <<EOF |
| 155 Please check the preceding terminal output for error messages. | 159 Please check the preceding terminal output for error messages. |
| 156 Run 'git submodule status' to see the current state of submodule checkouts. | 160 Run 'git submodule status' to see the current state of submodule checkouts. |
| 157 EOF | 161 EOF |
| 158 exit $status | 162 exit $status |
| 159 fi | 163 fi |
| 160 | 164 |
| 161 if [ "$hooks" = "yes" ]; then | 165 if [ "$hooks" = "yes" ]; then |
| 162 "$runhooks" | 166 $ECHO git runhooks |
| 163 status=$? | 167 status=$? |
| 164 fi | 168 fi |
| 165 | 169 |
| 166 echo | 170 echo |
| 167 exit $status | 171 exit $status |
| OLD | NEW |