aboutsummaryrefslogtreecommitdiff
path: root/project/Win32BuildSetup/extract_git_rev.bat
blob: 6dcc72341191d9dacefac8788e2bf7f2288ab2a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

REM Batch file output: %GIT_REV% variable, containing the git revision

REM Use tgit.exe of TortoiseGit if available
SET GITEXE="tgit.exe"
%GITEXE% --version > NUL 2>&1
IF errorlevel 1 GOTO :notgit
GOTO :extract

:notgit

REM Fallback on msysgit - must be in the path
SET GITEXE="git.exe"
%GITEXE% --help > NUL 2>&1
IF errorlevel 1 GOTO :nogit
GOTO :extract

:nogit

REM Failure - no git tool to extract information.
SET GIT_REV=Unknown
GOTO :done

:extract

SET /a counter=0
FOR /F "tokens=1-4 delims=-" %%A IN ('"%GITEXE% log --summary --abbrev=7 -n 1 --date=short --pretty=format:"%%cd-%%h""') DO (
IF "!counter!"=="0" ( SET GIT_REV=%%A%%B%%C-%%D ) ELSE ( goto exitloop )
SET /a counter+=1
)

:exitloop

echo %GIT_REV%

:done

SET GITEXE=