-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget_version.ps1
More file actions
44 lines (38 loc) · 1.06 KB
/
get_version.ps1
File metadata and controls
44 lines (38 loc) · 1.06 KB
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
Push-Location "$PSScriptRoot/../.."
$dirty = $false
$uncommittedChanges = (git status -s).Length -gt 0
$latestTag = git describe --tags --abbrev=0
if($LASTEXITCODE -ne 0) {
$latestTag = "0.0.0"
$dirty = $true
} else {
$tagHash = git rev-list -n 1 "$latestTag"
$currentHash = git rev-parse HEAD
$dirty = $tagHash -ne $currentHash
$dirty = $dirty -or $uncommittedChanges
}
$latestTagDash = $latestTag.IndexOf('-')
if($latestTagDash -eq -1)
{
$latestTagDash = $latestTag.Length
}
$gitVer = $latestTag.Replace('.', ',').Substring(0, $latestTagDash).Substring(1)
$fixVer = "9999"
if($latestTag.Contains("-pre"))
{
$fixVer = $latestTag.Substring($latestTag.IndexOf("-pre") + 4)
}
$gitVer += "," + ($dirty ? $fixVer : "0")
$dirtySuffix = ""
if($dirty)
{
$dirtySuffix = " (" + (git rev-parse --short HEAD)
if($uncommittedChanges)
{
$dirtySuffix += "+"
}
$dirtySuffix += ")"
}
$gitVerStr = $latestTag.Substring(1) + $dirtySuffix
Write-Output "#define GIT_VER $gitVer
#define GIT_VER_STR ""$gitVerStr\0""" > include/Version.h