-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathget_git_info.ps1
57 lines (53 loc) · 2.32 KB
/
get_git_info.ps1
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
46
47
48
49
50
51
52
53
54
55
56
57
# http://stackoverflow.com/a/39648656
Try
{
$gitUser = git config user.name;
$gitEmail = git config user.email;
$gitStateUser = git --no-pager log -1 --pretty=format:"%an";
$gitStateEmail = git --no-pager log -1 --pretty=format:"%ae";
$gitHashShort = git rev-parse --short HEAD;
$gitHashLong = git rev-parse HEAD;
$gitLastTag = git describe --tags --abbrev=0;
$gitOwnerRepo = [regex]::Match((git config --get remote.origin.url), "(?:github.com\/)(.+?)\/([^.\n]*)");
$gitOwner = $gitOwnerRepo.Groups[1].Value;
$gitRepo = $gitOwnerRepo.Groups[2].Value;
$gitBranch = git name-rev --name-only HEAD;
$gitCount = git rev-list HEAD --count;
$compileTime = [DateTime]::UtcNow.ToString('u').Replace('Z','UTC');
}
Catch
{
$gitUser = "unknown";
$gitEmail = "unknown@example.com";
$gitStateUser = "unknown";
$gitStateEmail = "unknown@example.com";
$gitHashShort = "unknown";
$gitHashLong = "unknown";
$gitLastTag = "0.1.0";
$gitOwner = "IcySon55";
$gitOwnerRepo = "Kuriimu";
$gitRepo = "Kuriimu";
$gitBranch = "master";
$gitCount = 0;
$compileTime = "unknown"
}
$projectPath = $args[0].Replace("""","");
$assemblyFile = $projectPath + "\Properties\AssemblyInfo.cs";
$templateAssemblyFile = $projectPath + "\Properties\AssemblyInfo_template.cs";
# Read template files, overwrite place holders with git version info
$newAssemblyContent = Get-Content -Encoding UTF8 $templateAssemblyFile |
%{$_ -replace '\$gitUser\$', $gitUser.Replace('"','\"') } |
%{$_ -replace '\$gitEmail\$', $gitEmail } |
%{$_ -replace '\$gitStateUser\$', $gitStateUser.Replace('"','\"') } |
%{$_ -replace '\$gitStateEmail\$', $gitStateEmail } |
%{$_ -replace '\$gitHashShort\$', $gitHashShort } |
%{$_ -replace '\$gitHashLong\$', $gitHashLong } |
%{$_ -replace '\$gitLastTag\$', $gitLastTag.TrimStart('v') } |
%{$_ -replace '\$gitOwner\$', $gitOwner } |
%{$_ -replace '\$gitRepo\$', $gitRepo } |
%{$_ -replace '\$gitBranch\$', $gitBranch } |
%{$_ -replace '\$gitCount\$', $gitCount } |
%{$_ -replace '\$compileTime\$', $compileTime };
# Write cs files only if there are changes
Write-Host " * Wrote AssemblyInfo.cs";
$newAssemblyContent | Out-File -Encoding UTF8 $assemblyFile;