Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit f65f713

Browse files
committed
Show some warnings when git can't be found and simplify some code
1 parent 149b998 commit f65f713

File tree

5 files changed

+122
-77
lines changed

5 files changed

+122
-77
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ abstract class ApplicationManagerBase : IApplicationManager
1414
private RepositoryManager repositoryManager;
1515
private Progress progressReporter;
1616
protected bool isBusy;
17-
protected bool firstRun;
18-
protected Guid instanceId;
17+
private bool firstRun;
18+
protected bool FirstRun { get { return firstRun; } set { firstRun = value; } }
19+
private Guid instanceId;
20+
protected Guid InstanceId { get { return instanceId; } set { instanceId = value; } }
1921

2022
public event Action<IProgress> OnProgress
2123
{
@@ -49,17 +51,16 @@ public void Run()
4951
{
5052
isBusy = true;
5153

52-
var thread = new Thread(obj =>
54+
var thread = new Thread(() =>
5355
{
5456
GitInstallationState state = new GitInstallationState();
55-
CancellationToken token = (CancellationToken)obj;
5657
try
5758
{
58-
SetupMetrics(Environment.UnityVersion, firstRun, instanceId);
59+
SetupMetrics(Environment.UnityVersion, instanceId);
5960

6061
if (Environment.IsMac)
6162
{
62-
var getEnvPath = new SimpleProcessTask(token, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
63+
var getEnvPath = new SimpleProcessTask(CancellationToken, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
6364
.Configure(ProcessManager, dontSetupGit: true)
6465
.Catch(e => true); // make sure this doesn't throw if the task fails
6566
var path = getEnvPath.RunWithReturn(true);
@@ -70,32 +71,17 @@ public void Run()
7071
}
7172
}
7273

74+
var installer = new GitInstaller(Environment, ProcessManager, CancellationToken, SystemSettings)
75+
{ Progress = progressReporter };
7376
state = SystemSettings.Get<GitInstallationState>(Constants.GitInstallationState) ?? state;
7477
if (state.GitIsValid && state.GitLfsIsValid)
7578
{
7679
if (firstRun)
7780
{
78-
// just check if the git/git lfs version is what we need
79-
var version = new GitVersionTask(token)
80-
.Configure(ProcessManager, state.GitExecutablePath, dontSetupGit: true)
81-
.Catch(e =>
82-
{
83-
Logger.Error(e, "Error getting git version");
84-
return true;
85-
})
86-
.RunWithReturn(true);
87-
state.GitIsValid = version >= Constants.MinimumGitVersion;
81+
installer.ValidateGitVersion(state);
8882
if (state.GitIsValid)
8983
{
90-
version = new GitLfsVersionTask(token)
91-
.Configure(ProcessManager, state.GitLfsExecutablePath, dontSetupGit: true)
92-
.Catch(e =>
93-
{
94-
Logger.Error(e, "Error getting lfs version");
95-
return true;
96-
})
97-
.RunWithReturn(true);
98-
state.GitLfsIsValid = version >= Constants.MinimumGitLfsVersion;
84+
installer.ValidateGitLfsVersion(state);
9985
}
10086
}
10187
}
@@ -105,9 +91,7 @@ public void Run()
10591

10692
if (!state.GitIsValid || !state.GitLfsIsValid)
10793
{
108-
state = new GitInstaller(Environment, ProcessManager, CancellationToken, SystemSettings)
109-
{ Progress = progressReporter }
110-
.SetupGitIfNeeded();
94+
state = installer.SetupGitIfNeeded();
11195
}
11296

11397
SetupGit(state);
@@ -123,7 +107,7 @@ public void Run()
123107
Logger.Error(ex, "A problem ocurred setting up Git");
124108
}
125109

126-
new ActionTask<bool>(token, (s, gitIsValid) =>
110+
new ActionTask<bool>(CancellationToken, (s, gitIsValid) =>
127111
{
128112
InitializationComplete();
129113
if (gitIsValid)
@@ -135,13 +119,31 @@ public void Run()
135119
{ Affinity = TaskAffinity.UI }
136120
.Start();
137121
});
138-
thread.Start(CancellationToken);
122+
thread.Start();
139123
}
140124

141125
public void SetupGit(GitInstaller.GitInstallationState state)
142126
{
143-
if (!(state.GitIsValid && state.GitLfsIsValid))
127+
if (!state.GitIsValid || !state.GitLfsIsValid)
128+
{
129+
if (!state.GitExecutablePath.IsInitialized)
130+
{
131+
Logger.Warning(Localization.GitNotFound);
132+
}
133+
else if (!state.GitLfsExecutablePath.IsInitialized)
134+
{
135+
Logger.Warning(Localization.GitLFSNotFound);
136+
}
137+
else if (state.GitVersion < Constants.MinimumGitVersion)
138+
{
139+
Logger.Warning(String.Format(Localization.GitVersionTooLow, state.GitExecutablePath, state.GitVersion, Constants.MinimumGitVersion));
140+
}
141+
else if (state.GitLfsVersion < Constants.MinimumGitLfsVersion)
142+
{
143+
Logger.Warning(String.Format(Localization.GitLfsVersionTooLow, state.GitLfsExecutablePath, state.GitLfsVersion, Constants.MinimumGitLfsVersion));
144+
}
144145
return;
146+
}
145147

146148
Environment.GitInstallPath = state.GitInstallationPath;
147149
Environment.GitExecutablePath = state.GitExecutablePath;
@@ -208,10 +210,9 @@ public void SetupGit(GitInstaller.GitInstallationState state)
208210
public void InitializeRepository()
209211
{
210212
isBusy = true;
211-
var thread = new Thread(obj =>
213+
var thread = new Thread(() =>
212214
{
213215
var success = true;
214-
CancellationToken token = (CancellationToken)obj;
215216
try
216217
{
217218
var targetPath = NPath.CurrentDirectory;
@@ -245,7 +246,7 @@ public void InitializeRepository()
245246
}
246247
isBusy = false;
247248
});
248-
thread.Start(CancellationToken);
249+
thread.Start();
249250
}
250251

251252
public void RestartRepository()
@@ -263,7 +264,7 @@ public void RestartRepository()
263264
Logger.Trace($"Got a repository? {(Environment.Repository != null ? Environment.Repository.LocalPath : "null")}");
264265
}
265266

266-
protected void SetupMetrics(string unityVersion, bool firstRun, Guid instanceId)
267+
protected void SetupMetrics(string unityVersion, Guid instanceId)
267268
{
268269
string userId = null;
269270
if (UserSettings.Exists(Constants.GuidKey))

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,12 @@ private GitInstallationState FindMacGit(GitInstallationState state)
9696
state = ValidateGitVersion(state);
9797
if (state.GitIsValid)
9898
state.GitInstallationPath = gitPath.Parent.Parent;
99-
else
100-
{
101-
state.GitInstallationPath = NPath.Default;
102-
state.GitExecutablePath = NPath.Default;
103-
}
10499
}
105100

106101
if (!state.GitLfsIsValid)
107102
{
108-
var gitLfsPath = new FindExecTask("git-lfs", cancellationToken).Configure(processManager, dontSetupGit: true)
103+
var gitLfsPath = new FindExecTask("git-lfs", cancellationToken)
104+
.Configure(processManager, dontSetupGit: true)
109105
.Catch(e => true)
110106
.RunWithReturn(true);
111107
state.GitLfsExecutablePath = gitLfsPath;
@@ -139,7 +135,7 @@ private GitInstallationState FindWindowsGit(GitInstallationState state)
139135
return state;
140136
}
141137

142-
private GitInstallationState ValidateGitVersion(GitInstallationState state)
138+
public GitInstallationState ValidateGitVersion(GitInstallationState state)
143139
{
144140
if (!state.GitExecutablePath.IsInitialized || !state.GitExecutablePath.FileExists())
145141
{
@@ -155,7 +151,7 @@ private GitInstallationState ValidateGitVersion(GitInstallationState state)
155151
return state;
156152
}
157153

158-
private GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
154+
public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
159155
{
160156
if (!state.GitLfsExecutablePath.IsInitialized || !state.GitLfsExecutablePath.FileExists())
161157
{

src/GitHub.Api/Localization.Designer.cs

Lines changed: 40 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.Api/Localization.resx

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<root>
3-
<!--
4-
Microsoft ResX Schema
5-
3+
<!--
4+
Microsoft ResX Schema
5+
66
Version 2.0
7-
8-
The primary goals of this format is to allow a simple XML format
9-
that is mostly human readable. The generation and parsing of the
10-
various data types are done through the TypeConverter classes
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
1111
associated with the data types.
12-
12+
1313
Example:
14-
14+
1515
... ado.net/XML headers & schema ...
1616
<resheader name="resmimetype">text/microsoft-resx</resheader>
1717
<resheader name="version">2.0</resheader>
@@ -26,36 +26,36 @@
2626
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
2727
<comment>This is a comment</comment>
2828
</data>
29-
30-
There are any number of "resheader" rows that contain simple
29+
30+
There are any number of "resheader" rows that contain simple
3131
name/value pairs.
32-
33-
Each data row contains a name, and value. The row also contains a
34-
type or mimetype. Type corresponds to a .NET class that support
35-
text/value conversion through the TypeConverter architecture.
36-
Classes that don't support this are serialized and stored with the
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
3737
mimetype set.
38-
39-
The mimetype is used for serialized objects, and tells the
40-
ResXResourceReader how to depersist the object. This is currently not
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
4141
extensible. For a given mimetype the value must be set accordingly:
42-
43-
Note - application/x-microsoft.net.object.binary.base64 is the format
44-
that the ResXResourceWriter will generate, however the reader can
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
4545
read any of the formats listed below.
46-
46+
4747
mimetype: application/x-microsoft.net.object.binary.base64
48-
value : The object must be serialized with
48+
value : The object must be serialized with
4949
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
5050
: and then encoded with base64 encoding.
51-
51+
5252
mimetype: application/x-microsoft.net.object.soap.base64
53-
value : The object must be serialized with
53+
value : The object must be serialized with
5454
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
5555
: and then encoded with base64 encoding.
5656
5757
mimetype: application/x-microsoft.net.object.bytearray.base64
58-
value : The object must be serialized into a byte array
58+
value : The object must be serialized into a byte array
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
@@ -294,4 +294,16 @@
294294
<data name="SwitchBranchFailedDescription" xml:space="preserve">
295295
<value>Could not switch to branch {0}</value>
296296
</data>
297-
</root>
297+
<data name="GitLFSNotFound" xml:space="preserve">
298+
<value>We could not find Git in the system.</value>
299+
</data>
300+
<data name="GitLfsVersionTooLow" xml:space="preserve">
301+
<value>The detected LFS at {0} has version {1}, which is too low. The minimum LFS version is {2}.</value>
302+
</data>
303+
<data name="GitNotFound" xml:space="preserve">
304+
<value>We could not find Git in the system.</value>
305+
</data>
306+
<data name="GitVersionTooLow" xml:space="preserve">
307+
<value>The detected Git at {0} has version {1}, which is too low. The minimum Git version is {2}.</value>
308+
</data>
309+
</root>

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class ApplicationManager : ApplicationManagerBase
1717
public ApplicationManager(IMainThreadSynchronizationContext synchronizationContext)
1818
: base(synchronizationContext as SynchronizationContext)
1919
{
20-
firstRun = ApplicationCache.Instance.FirstRun;
21-
instanceId = ApplicationCache.Instance.InstanceId;
20+
FirstRun = ApplicationCache.Instance.FirstRun;
21+
InstanceId = ApplicationCache.Instance.InstanceId;
2222

2323
ListenToUnityExit();
2424
Initialize();

0 commit comments

Comments
 (0)