From 77e2975ab2dce9b6f5d45fd597a3ba41102c8290 Mon Sep 17 00:00:00 2001 From: Guy Scharf Date: Fri, 7 Feb 2020 08:46:56 -0700 Subject: [PATCH] Rework update_gitinfo.bat There was a strange interaction between git rev-parse and git diff-index when run in a batch file. Reworked to change the way rev-parse command was handled. Also added check to make sure git.exe was in the path. --- oscar/update_gitinfo.bat | 41 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/oscar/update_gitinfo.bat b/oscar/update_gitinfo.bat index 652a21fc..6b9314f4 100755 --- a/oscar/update_gitinfo.bat +++ b/oscar/update_gitinfo.bat @@ -1,29 +1,34 @@ @echo off setlocal EnableDelayedExpansion set DIR=%~dp0 +:::set DIR=\oscar\oscar-code\oscar\ cd %DIR% -for /f %%i in ('git rev-parse --git-dir') do set GIT_DIR=%%i -if "%GIT_DIR%"=="" goto GitDone +:: Check git in path and git directory can be found +where /Q git.exe +if errorlevel 1 goto GitFail -for /f %%i in ('git rev-parse --abbrev-ref HEAD') do set GIT_BRANCH=%%i -if "%GIT_BRANCH%"=="HEAD" set GIT_BRANCH="" -for /f %%i in ('git rev-parse --short HEAD') do set GIT_REVISION=%%i -git diff-index --quiet HEAD -- -set GIT_INDEX=%errorlevel% +git rev-parse --git-dir >nul 2>&1 +if errorlevel 1 goto GitFail -if "%GIT_INDEX%"=="0" goto GitTag - -set GIT_REVISION=%GIT_REVISION%-plus -set GIT_TAG= -goto GitDone - -:GitTag -for /f %%i in ('git describe --exact-match --tags') do set GIT_TAG=%%i + for /f %%i in ('git rev-parse --abbrev-ref HEAD') do set GIT_BRANCH=%%i + if "%GIT_BRANCH%"=="HEAD" set GIT_BRANCH="" + for /f %%i in ('git rev-parse --short HEAD') do set GIT_REVISION=%%i + git diff-index --quiet HEAD -- + if %errorlevel%==0 goto GitTag + set GIT_REVISION=%GIT_REVISION%-plus + set GIT_TAG= + goto GitDone + :GitTag + for /f %%i in ('git describe --exact-match --tags') do set GIT_TAG=%%i + goto GitDone + +:GitFail + set GIT_REVISION="private" :GitDone -@echo Update_gtinfo.bat: GIT_DIR=%GIT_DIR%, GIT_BRANCH=%GIT_BRANCH%, GIT_REVISION=%GIT_REVISION%, GIT_TAG=%GIT_TAG% +@echo Update_gtinfo.bat: GIT_BRANCH=%GIT_BRANCH%, GIT_REVISION=%GIT_REVISION%, GIT_TAG=%GIT_TAG% echo // This is an auto generated file > %DIR%git_info.new @@ -37,9 +42,6 @@ if "%GIT_TAG%"=="" goto DefinesDone echo #define GIT_TAG "%GIT_TAG%" >> %DIR%git_info.new :DefinesDone -:::type %DIR%git_info.new -:::set - fc %DIR%git_info.h %DIR%git_info.new 1>nul 2>nul && del /q %DIR%git_info.new || goto NewFile goto AllDone @@ -48,3 +50,4 @@ echo Updating %DIR%git_info.h move /y %DIR%git_info.new %DIR%git_info.h :AllDone +endlocal \ No newline at end of file