mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-09 04:30:43 +00:00
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.
This commit is contained in:
parent
0afaec53b5
commit
77e2975ab2
@ -1,29 +1,34 @@
|
|||||||
@echo off
|
@echo off
|
||||||
setlocal EnableDelayedExpansion
|
setlocal EnableDelayedExpansion
|
||||||
set DIR=%~dp0
|
set DIR=%~dp0
|
||||||
|
:::set DIR=\oscar\oscar-code\oscar\
|
||||||
cd %DIR%
|
cd %DIR%
|
||||||
|
|
||||||
for /f %%i in ('git rev-parse --git-dir') do set GIT_DIR=%%i
|
:: Check git in path and git directory can be found
|
||||||
if "%GIT_DIR%"=="" goto GitDone
|
where /Q git.exe
|
||||||
|
if errorlevel 1 goto GitFail
|
||||||
|
|
||||||
for /f %%i in ('git rev-parse --abbrev-ref HEAD') do set GIT_BRANCH=%%i
|
git rev-parse --git-dir >nul 2>&1
|
||||||
if "%GIT_BRANCH%"=="HEAD" set GIT_BRANCH=""
|
if errorlevel 1 goto GitFail
|
||||||
for /f %%i in ('git rev-parse --short HEAD') do set GIT_REVISION=%%i
|
|
||||||
git diff-index --quiet HEAD --
|
|
||||||
set GIT_INDEX=%errorlevel%
|
|
||||||
|
|
||||||
if "%GIT_INDEX%"=="0" goto GitTag
|
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
|
||||||
|
|
||||||
set GIT_REVISION=%GIT_REVISION%-plus
|
git diff-index --quiet HEAD --
|
||||||
set GIT_TAG=
|
if %errorlevel%==0 goto GitTag
|
||||||
goto GitDone
|
set GIT_REVISION=%GIT_REVISION%-plus
|
||||||
|
set GIT_TAG=
|
||||||
:GitTag
|
goto GitDone
|
||||||
for /f %%i in ('git describe --exact-match --tags') do set GIT_TAG=%%i
|
:GitTag
|
||||||
|
for /f %%i in ('git describe --exact-match --tags') do set GIT_TAG=%%i
|
||||||
|
goto GitDone
|
||||||
|
|
||||||
|
:GitFail
|
||||||
|
set GIT_REVISION="private"
|
||||||
:GitDone
|
: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
|
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
|
echo #define GIT_TAG "%GIT_TAG%" >> %DIR%git_info.new
|
||||||
:DefinesDone
|
: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
|
fc %DIR%git_info.h %DIR%git_info.new 1>nul 2>nul && del /q %DIR%git_info.new || goto NewFile
|
||||||
goto AllDone
|
goto AllDone
|
||||||
|
|
||||||
@ -48,3 +50,4 @@ echo Updating %DIR%git_info.h
|
|||||||
move /y %DIR%git_info.new %DIR%git_info.h
|
move /y %DIR%git_info.new %DIR%git_info.h
|
||||||
|
|
||||||
:AllDone
|
:AllDone
|
||||||
|
endlocal
|
Loading…
Reference in New Issue
Block a user