Skip to content

Commit 911b427

Browse files
committedOct 31, 2018
Make GitExtensions project authority of GIT info
Prevents environment data from getting stale by a commit but GitGUI not being rebuilt
1 parent 162a5c2 commit 911b427

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed
 

‎GitExtensions/GitExtensions.csproj

+7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@
8787
<ItemGroup>
8888
<EmbeddedResource Include="AutoCompleteRegexes.txt" />
8989
</ItemGroup>
90+
<ItemGroup>
91+
<PackageReference Include="GitInfo">
92+
<Version>2.0.18</Version>
93+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
94+
<PrivateAssets>all</PrivateAssets>
95+
</PackageReference>
96+
</ItemGroup>
9097
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
9198
<Target Name="AddPluginBinaries" AfterTargets="ResolveProjectReferences">
9299
<ItemGroup>

‎GitExtensions/Program.cs

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ private static void Main()
5454
}
5555
}
5656

57+
// This is done here so these values can be used in the GitGui project but this project is the authority of the values.
58+
UserEnvironmentInformation.Initialise(ThisAssembly.Git.Sha, ThisAssembly.Git.IsDirty);
59+
5760
// NOTE we perform the rest of the application's startup in another method to defer
5861
// the JIT processing more types than required to configure NBug.
5962
// In this way, there's more chance we can handle startup exceptions correctly.

‎GitUI/GitUI.csproj

-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@
5858
<Reference Include="System.Xml" />
5959
</ItemGroup>
6060
<ItemGroup>
61-
<PackageReference Include="GitInfo">
62-
<Version>2.0.18</Version>
63-
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
64-
<PrivateAssets>all</PrivateAssets>
65-
</PackageReference>
6661
<PackageReference Include="Microsoft-WindowsAPICodePack-Core">
6762
<Version>1.1.3.3</Version>
6863
</PackageReference>

‎GitUI/UserEnvironmentInformation.cs

+27-9
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ namespace GitUI
88
{
99
public sealed class UserEnvironmentInformation
1010
{
11-
public static void CopyInformation()
12-
{
13-
Clipboard.SetText(GetInformation());
14-
}
11+
private static bool _alreadySet;
12+
private static bool _dirty;
13+
private static string _sha;
14+
15+
public static void CopyInformation() => Clipboard.SetText(GetInformation());
1516

1617
public static string GetInformation()
1718
{
19+
if (!_alreadySet)
20+
{
21+
throw new InvalidOperationException($"{nameof(Initialise)} must be called first");
22+
}
23+
1824
string gitVer;
1925
try
2026
{
@@ -27,12 +33,24 @@ public static string GetInformation()
2733

2834
StringBuilder sb = new StringBuilder();
2935

30-
sb.AppendFormat("- Git Extensions {0}{1}", AppSettings.ProductVersion, Environment.NewLine);
31-
sb.AppendFormat("- {0} {1}{2}", ThisAssembly.Git.Sha, ThisAssembly.Git.IsDirty ? " (Dirty)" : "", Environment.NewLine);
32-
sb.AppendFormat("- Git {0}{1}", gitVer, Environment.NewLine);
33-
sb.AppendFormat("- {0}{1}", Environment.OSVersion, Environment.NewLine);
34-
sb.AppendFormat("- {0}", RuntimeInformation.FrameworkDescription);
36+
sb.Append($"- Git Extensions {AppSettings.ProductVersion}{Environment.NewLine}");
37+
sb.Append($"- {_sha} {(_dirty ? " (Dirty)" : "")}{Environment.NewLine}");
38+
sb.Append($"- Git {gitVer}{Environment.NewLine}");
39+
sb.Append($"- {Environment.OSVersion}{Environment.NewLine}");
40+
sb.Append($"- {RuntimeInformation.FrameworkDescription}");
3541
return sb.ToString();
3642
}
43+
44+
public static void Initialise(string sha, bool isDirty)
45+
{
46+
if (_alreadySet)
47+
{
48+
return;
49+
}
50+
51+
_alreadySet = true;
52+
_sha = sha;
53+
_dirty = isDirty;
54+
}
3755
}
3856
}

‎UnitTests/GitUITests/TranslationTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void TearDown()
2828
[Apartment(ApartmentState.STA)]
2929
public void CreateInstanceOfClass()
3030
{
31+
UserEnvironmentInformation.Initialise("", false);
3132
var translatableTypes = TranslationUtil.GetTranslatableTypes();
3233

3334
var problems = new List<(string typeName, Exception exception)>();

0 commit comments

Comments
 (0)
Please sign in to comment.