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

Commit e38fb52

Browse files
Merge pull request #318 from github-for-unity/shana/272-fixes
Fixes to #272
2 parents 5d89039 + ec85581 commit e38fb52

File tree

5 files changed

+70
-94
lines changed

5 files changed

+70
-94
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ namespace GitHub.Unity
99
interface IGitClient
1010
{
1111
Task<NPath> FindGitInstallation();
12-
13-
ITask<ValidateGitInstallResult> ValidateGitInstall(string path);
12+
ITask<ValidateGitInstallResult> ValidateGitInstall(NPath path);
1413

1514
ITask Init(IOutputProcessor<string> processor = null);
1615

@@ -171,38 +170,28 @@ private async Task<NPath> LookForSystemGit()
171170
return path;
172171
}
173172

174-
public ITask<ValidateGitInstallResult> ValidateGitInstall(string path)
173+
public ITask<ValidateGitInstallResult> ValidateGitInstall(NPath path)
175174
{
176-
if (!path.ToNPath().FileExists())
175+
if (!path.FileExists())
177176
{
178-
return new FuncTask<ValidateGitInstallResult>(cancellationToken,
179-
() => new ValidateGitInstallResult(false, null, null));
177+
return new FuncTask<ValidateGitInstallResult>(TaskEx.FromResult(new ValidateGitInstallResult(false, null, null)));
180178
}
181179

182180
Version gitVersion = null;
183181
Version gitLfsVersion = null;
184182

185-
var gitVersionTask = new GitVersionTask(cancellationToken);
186-
gitVersionTask.Configure(processManager, path,
187-
gitVersionTask.ProcessArguments, environment.RepositoryPath);
188-
189-
var gitLfsVersionTask = new GitLfsVersionTask(cancellationToken);
190-
gitLfsVersionTask.Configure(processManager, path,
191-
gitLfsVersionTask.ProcessArguments, environment.RepositoryPath);
183+
var gitVersionTask = new GitVersionTask(cancellationToken).Configure(processManager, path);
184+
var gitLfsVersionTask = new GitLfsVersionTask(cancellationToken).Configure(processManager, path);
192185

193186
return gitVersionTask
194187
.Then((result, version) => gitVersion = version)
195188
.Then(gitLfsVersionTask)
196189
.Then((result, version) => gitLfsVersion = version)
197-
.Then(result => {
198-
var b = result
199-
&& gitVersion != null
200-
&& gitVersion >= Constants.MinimumGitVersion
201-
&& gitLfsVersion != null
202-
&& gitLfsVersion >= Constants.MinimumGitLfsVersion;
203-
204-
return new ValidateGitInstallResult(b, gitVersion, gitLfsVersion);
205-
});
190+
.Then(success => new ValidateGitInstallResult(success &&
191+
gitVersion?.CompareTo(Constants.MinimumGitVersion) >= 0 &&
192+
gitLfsVersion?.CompareTo(Constants.MinimumGitLfsVersion) >= 0,
193+
gitVersion, gitLfsVersion)
194+
);
206195
}
207196

208197
public ITask Init(IOutputProcessor<string> processor = null)

src/GitHub.Api/NewTaskSystem/ProcessTask.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ namespace GitHub.Unity
1111
{
1212
static class ProcessTaskExtensions
1313
{
14-
public static T Configure<T>(this T task, IProcessManager processManager, bool withInput = false)
14+
public static T Configure<T>(this T task, IProcessManager processManager, bool withInput)
1515
where T : IProcess
1616
{
17-
return processManager.Configure(task, withInput);
17+
return processManager.Configure(task, withInput: withInput);
1818
}
1919

20-
public static T Configure<T>(this T task, IProcessManager processManager, string executable, string arguments,
21-
NPath workingDirectory = null, bool withInput = false)
20+
public static T Configure<T>(this T task, IProcessManager processManager, string executable = null,
21+
string arguments = null,
22+
NPath workingDirectory = null,
23+
bool withInput = false)
2224
where T : IProcess
2325
{
24-
return processManager.Configure(task, executable, arguments, workingDirectory, withInput);
26+
return processManager.Configure(task, executable?.ToNPath(), arguments, workingDirectory, withInput);
2527
}
2628
}
2729

src/GitHub.Api/OutputProcessors/IProcessManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ namespace GitHub.Unity
44
{
55
interface IProcessManager
66
{
7-
T Configure<T>(T processTask, bool withInput = false) where T : IProcess;
8-
T Configure<T>(T processTask, string executableFileName, string arguments, NPath workingDirectory = null, bool withInput = false)
7+
T Configure<T>(T processTask, NPath executable = null, string arguments = null, NPath workingDirectory = null, bool withInput = false)
98
where T : IProcess;
109
IProcess Reconnect(IProcess processTask, int i);
1110
CancellationToken CancellationToken { get; }

src/GitHub.Api/OutputProcessors/ProcessManager.cs

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,13 @@ public ProcessManager(IEnvironment environment, IProcessEnvironment gitEnvironme
2222
this.cancellationToken = cancellationToken;
2323
}
2424

25-
public T Configure<T>(T processTask, bool withInput = false) where T : IProcess
26-
{
27-
NPath executableFileName;
28-
if (processTask.ProcessName != null)
29-
{
30-
executableFileName = processTask.ProcessName.ToNPath();
31-
//logger.Trace("Configuring Task:{0} with Exec:{1}", processTask.GetType().Name, executableFileName);
32-
}
33-
else
34-
{
35-
executableFileName = environment.GitExecutablePath;
36-
//logger.Trace("Configuring Task:{0} with Git", processTask.GetType().Name);
37-
}
38-
39-
return Configure(processTask,
40-
executableFileName,
41-
processTask.ProcessArguments,
42-
environment.RepositoryPath, withInput);
43-
}
44-
45-
public T Configure<T>(T processTask, string executableFileName, string arguments, NPath workingDirectory = null, bool withInput = false)
25+
public T Configure<T>(T processTask, NPath executable = null, string arguments = null, NPath workingDirectory = null, bool withInput = false)
4626
where T : IProcess
4727
{
28+
executable = executable ?? processTask.ProcessName?.ToNPath() ?? environment.GitExecutablePath;
29+
4830
//If this null check fails, be sure you called Configure() on your task
49-
Guard.ArgumentNotNull(executableFileName, nameof(executableFileName));
31+
Guard.ArgumentNotNull(executable, nameof(executable));
5032

5133
var startInfo = new ProcessStartInfo
5234
{
@@ -61,11 +43,13 @@ public T Configure<T>(T processTask, string executableFileName, string arguments
6143

6244
gitEnvironment.Configure(startInfo, workingDirectory ?? environment.RepositoryPath);
6345

64-
var execPath = executableFileName.ToNPath();
65-
if (execPath.IsRelative)
66-
executableFileName = FindExecutableInPath(execPath, startInfo.EnvironmentVariables["PATH"]) ?? execPath.FileName;
67-
startInfo.FileName = executableFileName;
68-
startInfo.Arguments = arguments;
46+
if (executable.IsRelative)
47+
{
48+
executable = executable.FileName.ToNPath();
49+
executable = FindExecutableInPath(executable, startInfo.EnvironmentVariables["PATH"]) ?? executable;
50+
}
51+
startInfo.FileName = executable;
52+
startInfo.Arguments = arguments ?? processTask.ProcessArguments;
6953
processTask.Configure(startInfo);
7054
return processTask;
7155
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitPathView.cs

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -226,59 +226,61 @@ private void ValidateAndSetGitInstallPath(string value)
226226

227227
gitVersionErrorMessage = null;
228228

229-
GitClient.ValidateGitInstall(value).ThenInUI((sucess, result) => {
230-
if (!sucess)
229+
GitClient.ValidateGitInstall(value.ToNPath())
230+
.ThenInUI((sucess, result) =>
231231
{
232-
Logger.Trace(ErrorGettingSoftwareVersionMessage);
233-
gitVersionErrorMessage = ErrorGettingSoftwareVersionMessage;
234-
235-
isBusy = false;
236-
237-
return;
238-
}
239-
240-
if (!result.IsValid)
241-
{
242-
Logger.Warning("Software versions do not meet minimums Git:{0} (Minimum:{1}) GitLfs:{2} (Minimum:{3})",
243-
result.GitVersion,
244-
Constants.MinimumGitVersion,
245-
result.GitLfsVersion,
246-
Constants.MinimumGitLfsVersion);
232+
if (!sucess)
233+
{
234+
Logger.Trace(ErrorGettingSoftwareVersionMessage);
235+
gitVersionErrorMessage = ErrorGettingSoftwareVersionMessage;
247236

248-
var errorMessageStringBuilder = new StringBuilder();
237+
isBusy = false;
249238

250-
if (result.GitVersion < Constants.MinimumGitVersion)
251-
{
252-
errorMessageStringBuilder.AppendFormat(ErrorMinimumGitVersionMessageFormat, result.GitVersion, Constants.MinimumGitVersion);
239+
return;
253240
}
254241

255-
if (result.GitLfsVersion < Constants.MinimumGitLfsVersion)
242+
if (!result.IsValid)
256243
{
257-
if(errorMessageStringBuilder.Length > 0)
244+
Logger.Warning("Software versions do not meet minimums Git:{0} (Minimum:{1}) GitLfs:{2} (Minimum:{3})",
245+
result.GitVersion,
246+
Constants.MinimumGitVersion,
247+
result.GitLfsVersion,
248+
Constants.MinimumGitLfsVersion);
249+
250+
var errorMessageStringBuilder = new StringBuilder();
251+
252+
if (result.GitVersion < Constants.MinimumGitVersion)
258253
{
259-
errorMessageStringBuilder.Append(Environment.NewLine);
254+
errorMessageStringBuilder.AppendFormat(ErrorMinimumGitVersionMessageFormat, result.GitVersion, Constants.MinimumGitVersion);
260255
}
261256

262-
errorMessageStringBuilder.AppendFormat(ErrorMinimumGitLfsVersionMessageFormat, result.GitLfsVersion, Constants.MinimumGitLfsVersion);
263-
}
257+
if (result.GitLfsVersion < Constants.MinimumGitLfsVersion)
258+
{
259+
if (errorMessageStringBuilder.Length > 0)
260+
{
261+
errorMessageStringBuilder.Append(Environment.NewLine);
262+
}
264263

265-
gitVersionErrorMessage = errorMessageStringBuilder.ToString();
264+
errorMessageStringBuilder.AppendFormat(ErrorMinimumGitLfsVersionMessageFormat, result.GitLfsVersion, Constants.MinimumGitLfsVersion);
265+
}
266266

267-
isBusy = false;
268-
return;
269-
}
267+
gitVersionErrorMessage = errorMessageStringBuilder.ToString();
270268

271-
Logger.Trace("Software versions meet minimums Git:{0} GitLfs:{1}",
272-
result.GitVersion,
273-
result.GitLfsVersion);
269+
isBusy = false;
270+
return;
271+
}
274272

275-
Manager.SystemSettings.Set(Constants.GitInstallPathKey, value);
276-
Environment.GitExecutablePath = value.ToNPath();
273+
Logger.Trace("Software versions meet minimums Git:{0} GitLfs:{1}",
274+
result.GitVersion,
275+
result.GitLfsVersion);
277276

278-
gitExecHasChanged = true;
279-
isBusy = false;
277+
Manager.SystemSettings.Set(Constants.GitInstallPathKey, value);
278+
Environment.GitExecutablePath = value.ToNPath();
279+
280+
gitExecHasChanged = true;
281+
isBusy = false;
280282

281-
}).Start();
283+
}).Start();
282284
}
283285
}
284286
}

0 commit comments

Comments
 (0)