diff --git a/fetch.bat b/fetch.bat index eef301915..26d8bc130 100755 --- a/fetch.bat +++ b/fetch.bat @@ -7,8 +7,8 @@ setlocal :: Synchronize the root directory before deferring control back to gclient.py. call "%~dp0\update_depot_tools.bat" :: Abort the script if we failed to update depot_tools. -IF %errorlevel% NEQ 0 ( - goto :EOF +IF %ERRORLEVEL% NEQ 0 ( + exit /b %ERRORLEVEL% ) :: Ensure that "depot_tools" is somewhere in PATH so this tool can be used diff --git a/gclient.bat b/gclient.bat index 2934a6ce1..5a6ca1938 100755 --- a/gclient.bat +++ b/gclient.bat @@ -10,8 +10,8 @@ IF "%DEPOT_TOOLS_UPDATE%" == "0" GOTO :CALL_GCLIENT :: Synchronize the root directory before deferring control back to gclient.py. call "%~dp0update_depot_tools.bat" %* :: Abort the script if we failed to update depot_tools. -IF %errorlevel% NEQ 0 ( - goto :EOF +IF %ERRORLEVEL% NEQ 0 ( + exit /b %ERRORLEVEL% ) :CALL_GCLIENT diff --git a/gsutil.py.bat b/gsutil.py.bat index 5f367cb2a..ab9719087 100755 --- a/gsutil.py.bat +++ b/gsutil.py.bat @@ -10,8 +10,8 @@ IF "%DEPOT_TOOLS_UPDATE%" == "0" GOTO :CALL_GSUTIL :: Synchronize the root directory before deferring control back to gsutil.py. call "%~dp0update_depot_tools.bat" %* :: Abort the script if we failed to update depot_tools. -IF %errorlevel% NEQ 0 ( - goto :EOF +IF %ERRORLEVEL% NEQ 0 ( + exit /b %ERRORLEVEL% ) :CALL_GSUTIL diff --git a/update_depot_tools b/update_depot_tools index ce95e8857..b748ed0ff 100755 --- a/update_depot_tools +++ b/update_depot_tools @@ -129,7 +129,11 @@ if [ "X$DEPOT_TOOLS_UPDATE" != "X0" ]; then if [ -e "$base_dir/.git" ]; then cd "$base_dir" update_git_repo + UPDATE_RESULT=$? cd - > /dev/null + if [[ $UPDATE_RESULT -ne 0 ]]; then + exit $UPDATE_RESULT + fi fi # Sync CIPD-boostrapped packages. diff --git a/update_depot_tools.bat b/update_depot_tools.bat index 4381a6806..563f13151 100644 --- a/update_depot_tools.bat +++ b/update_depot_tools.bat @@ -5,17 +5,24 @@ :: This batch file will try to sync the root directory. -setlocal +setlocal enabledelayedexpansion :: Windows freaks out if a file is overwritten while it's being executed. Copy :: this script off to a temporary location and reinvoke from there before :: running any git commands. IF "%~nx0"=="update_depot_tools.bat" ( COPY /Y "%~dp0update_depot_tools.bat" "%TEMP%\update_depot_tools_tmp.bat" >nul - if errorlevel 1 goto :EOF + if errorlevel 1 ( + echo Error updating depot_tools, can't copy update_depot_tools.bat to TEMP. + :: !VAR! syntax is used to get delayed expansion, because %VAR% syntax would + :: return a value that was set prior entering the IF () block. + exit /b !ERRORLEVEL! + ) :: Use call/exit to avoid leaving an orphaned window title. call "%TEMP%\update_depot_tools_tmp.bat" "%~dp0" %* - exit /b %ERRORLEVEL% + :: !VAR! syntax is used to get delayed expansion, because %VAR% syntax would + :: return a value that was set prior entering the IF () block. + exit /b !ERRORLEVEL! ) set DEPOT_TOOLS_DIR=%~1 @@ -25,15 +32,16 @@ SHIFT IF EXIST "%DEPOT_TOOLS_DIR%.disable_auto_update" GOTO :EOF IF "%DEPOT_TOOLS_UPDATE%" == "0" GOTO :EOF +echo Updating depot_tools... set GIT_URL=https://chromium.googlesource.com/chromium/tools/depot_tools.git :: Download git for the first time if it's not present. call git --version > nul 2>&1 -if %errorlevel% == 0 goto :GIT_UPDATE +if %ERRORLEVEL% == 0 goto :GIT_UPDATE call "%DEPOT_TOOLS_DIR%bootstrap\win_tools.bat" if errorlevel 1 ( echo Error updating depot_tools, no revision tool found. - goto :EOF + exit /b %ERRORLEVEL% ) :GIT_UPDATE @@ -60,7 +68,7 @@ call git fetch -q origin > NUL call git checkout -q origin/main > NUL if errorlevel 1 ( echo Failed to update depot_tools. - goto :EOF + exit /b %ERRORLEVEL% ) :: Sync CIPD and CIPD client tools.