-
Notifications
You must be signed in to change notification settings - Fork 360
/
MakeCommitHash.bat
45 lines (35 loc) · 1.64 KB
/
MakeCommitHash.bat
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
41
42
43
44
45
@echo off
IF EXIST "src/CommitHash.autogenerated" (
echo The file "src/CommitHash.autogenerated" already exists.
exit /b 0
)
FOR /F "tokens=*" %%g IN ('git rev-parse HEAD') DO (SET REF_COMMIT_HASH=%%g)
FOR /F "tokens=*" %%t IN ('git describe --tags --abbrev^=0') DO (SET REF_TAG=%%t)
IF "%REF_TAG%"=="" (SET REF_TAG=no_tag)
FOR /F "tokens=*" %%c IN ('git describe --tags --long') DO (
FOR /F "tokens=1,2 delims=-" %%a IN ("%%c") DO (
SET REF_TAG_LONG=%%a
SET REF_COMMITS_PAST_TAG=%%b
)
)
IF "%REF_COMMITS_PAST_TAG%"=="" (SET REF_COMMITS_PAST_TAG=0)
FOR /F "tokens=*" %%b IN ('git rev-parse --abbrev-ref HEAD') DO (SET REF_BRANCH=%%b)
FOR /F "tokens=*" %%n IN ('git rev-list --count HEAD') DO (SET REF_TOTAL_COMMITS=%%n)
IF "%REF_TOTAL_COMMITS%"=="" (SET REF_TOTAL_COMMITS=0)
FOR /F "tokens=2 delims==" %%a IN ('wmic OS get localdatetime /value') DO (
SET datetime=%%a
)
SET year=%datetime:~0,4%
SET month=%datetime:~4,2%
SET day=%datetime:~6,2%
SET hour=%datetime:~8,2%
SET minute=%datetime:~10,2%
echo #pragma once > src/CommitHash.autogenerated
echo #define REF_COMMIT_HASH "%REF_COMMIT_HASH%" >> src/CommitHash.autogenerated
echo #define REF_TAG "%REF_TAG%" >> src/CommitHash.autogenerated
echo #define REF_TAG_LONG "%REF_TAG_LONG%" >> src/CommitHash.autogenerated
echo #define REF_COMMITS_PAST_TAG %REF_COMMITS_PAST_TAG% >> src/CommitHash.autogenerated
echo #define REF_BRANCH "%REF_BRANCH%" >> src/CommitHash.autogenerated
echo #define REF_TOTAL_COMMITS %REF_TOTAL_COMMITS% >> src/CommitHash.autogenerated
echo #define REF_BUILD_DATE "%day%.%month%.%year%" >> src/CommitHash.autogenerated
echo #define REF_BUILD_TIME "%hour%:%minute%" >> src/CommitHash.autogenerated