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

Commit 7ea6fa6

Browse files
committed
Cleaning up Configure calls
1 parent 047bbb4 commit 7ea6fa6

File tree

4 files changed

+26
-54
lines changed

4 files changed

+26
-54
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 10 additions & 20 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,37 +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
{
178177
return new FuncTask<ValidateGitInstallResult>(TaskEx.FromResult(new ValidateGitInstallResult(false, null, null)));
179178
}
180179

181180
Version gitVersion = null;
182181
Version gitLfsVersion = null;
183182

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

192186
return gitVersionTask
193187
.Then((result, version) => gitVersion = version)
194188
.Then(gitLfsVersionTask)
195189
.Then((result, version) => gitLfsVersion = version)
196-
.Then(result => {
197-
var b = result
198-
&& gitVersion != null
199-
&& gitVersion >= Constants.MinimumGitVersion
200-
&& gitLfsVersion != null
201-
&& gitLfsVersion >= Constants.MinimumGitLfsVersion;
202-
203-
return new ValidateGitInstallResult(b, gitVersion, gitLfsVersion);
204-
});
190+
.Then(success => new ValidateGitInstallResult(success &&
191+
gitVersion?.CompareTo(Constants.MinimumGitVersion) >= 0 &&
192+
gitLfsVersion?.CompareTo(Constants.MinimumGitLfsVersion) >= 0,
193+
gitVersion, gitLfsVersion)
194+
);
205195
}
206196

207197
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: 8 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,10 @@ 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+
executable = FindExecutableInPath(executable, startInfo.EnvironmentVariables["PATH"]) ?? executable;
48+
startInfo.FileName = executable.FileName;
49+
startInfo.Arguments = arguments ?? processTask.ProcessArguments;
6950
processTask.Configure(startInfo);
7051
return processTask;
7152
}

0 commit comments

Comments
 (0)