-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to get git information
- Loading branch information
1 parent
90d9094
commit 4bbdf12
Showing
8 changed files
with
141 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace LinkDotNet.BuildInformation; | ||
|
||
public sealed class GitInformationInfo | ||
{ | ||
public string Branch { get; init; } = string.Empty; | ||
public string Commit { get; init; } = string.Empty; | ||
public string ShortCommit => Commit.Length > 7 ? Commit[..7] : Commit; | ||
public string NearestTag { get; init; } = string.Empty; | ||
public string DetailedTagDescription { get; init; } = string.Empty; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Diagnostics; | ||
|
||
namespace LinkDotNet.BuildInformation; | ||
|
||
public static class GitRetriever | ||
{ | ||
public static GitInformationInfo GetGitInformation(bool useGitInfo) | ||
{ | ||
if (!useGitInfo) | ||
{ | ||
return new GitInformationInfo(); | ||
} | ||
|
||
return new GitInformationInfo | ||
{ | ||
Branch = GetGitInfoByCommand("rev-parse --abbrev-ref HEAD"), | ||
Commit = GetGitInfoByCommand("rev-parse HEAD"), | ||
NearestTag = GetGitInfoByCommand("describe --tags --abbrev=0"), | ||
DetailedTagDescription = GetGitInfoByCommand("describe --tags"), | ||
}; | ||
|
||
static string GetGitInfoByCommand(string command) | ||
{ | ||
var processInfo = new ProcessStartInfo | ||
{ | ||
FileName = "git", | ||
Arguments = command, | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
}; | ||
|
||
var process = new Process { StartInfo = processInfo }; | ||
|
||
process.Start(); | ||
var result = process.StandardOutput.ReadToEnd().Trim(); | ||
process.WaitForExit(); | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters