Skip to content

Commit

Permalink
[skip ci] return empty string if CurrentCommit is empty in GitVersion
Browse files Browse the repository at this point in the history
Prevent exception if the working directory isn't a git directory (contains .git)
  • Loading branch information
maforget committed Jul 5, 2024
1 parent cb11c09 commit ba8b812
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cYo.Common/Runtime/GitVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public static class GitVersion
{
public static string GetCurrentVersionInfo()
{
var isDirty = !string.IsNullOrEmpty(Properties.Resources.isDirty.Trim());
var currentCommit = $"{Properties.Resources.CurrentCommit?.Substring(0, 7)}{(isDirty ? "-dirty" : "")}";
var isDirty = string.IsNullOrEmpty(Properties.Resources.isDirty?.Trim()) ? "" : "-dirty";
var currentCommit = string.IsNullOrEmpty(Properties.Resources.CurrentCommit) ? "" : $" [{Properties.Resources.CurrentCommit?[..7]}{isDirty}]";

return $" [{currentCommit}]";
return currentCommit;
}
}
}

0 comments on commit ba8b812

Please sign in to comment.