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

Commit a2158e6

Browse files
committed
Fix finding git on mac and using the system git correctly
1 parent 733dadc commit a2158e6

File tree

7 files changed

+27
-11
lines changed

7 files changed

+27
-11
lines changed

src/GitHub.Api/IO/NiceIO.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public override string ToString()
378378
public string ToString(SlashMode slashMode)
379379
{
380380
if (!_isInitialized)
381-
return null;
381+
return String.Empty;
382382

383383
// Check if it's linux root /
384384
if (IsRoot && string.IsNullOrEmpty(_driveLetter))

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ITask<NPath> SetupGitIfNeeded()
4444
if (!environment.IsWindows)
4545
{
4646
startTask = new FindExecTask("git", cancellationToken)
47-
.Configure(processManager);
47+
.Configure(processManager, false, true);
4848
// we should doublecheck that system git is usable here
4949
installationState = new GitInstallationState
5050
{

src/GitHub.Api/OutputProcessors/IProcessManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ namespace GitHub.Unity
44
{
55
public interface IProcessManager
66
{
7-
T Configure<T>(T processTask, NPath? executable = null, string arguments = null, NPath? workingDirectory = null, bool withInput = false)
7+
T Configure<T>(T processTask, NPath? executable = null, string arguments = null, NPath? workingDirectory = null,
8+
bool withInput = false, bool dontSetupGit = false)
89
where T : IProcess;
910
IProcess Reconnect(IProcess processTask, int i);
1011
CancellationToken CancellationToken { get; }

src/GitHub.Api/OutputProcessors/ProcessManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public ProcessManager(IEnvironment environment, IProcessEnvironment gitEnvironme
2323
this.cancellationToken = cancellationToken;
2424
}
2525

26-
public T Configure<T>(T processTask, NPath? executable = null, string arguments = null, NPath? workingDirectory = null, bool withInput = false)
26+
public T Configure<T>(T processTask, NPath? executable = null, string arguments = null,
27+
NPath? workingDirectory = null,
28+
bool withInput = false,
29+
bool dontSetupGit = false)
2730
where T : IProcess
2831
{
2932
executable = executable ?? processTask.ProcessName?.ToNPath() ?? environment.GitExecutablePath;
@@ -42,7 +45,7 @@ public T Configure<T>(T processTask, NPath? executable = null, string arguments
4245
StandardErrorEncoding = Encoding.UTF8
4346
};
4447

45-
gitEnvironment.Configure(startInfo, workingDirectory ?? environment.RepositoryPath);
48+
gitEnvironment.Configure(startInfo, workingDirectory ?? environment.RepositoryPath, dontSetupGit);
4649

4750
if (executable.Value.IsRelative)
4851
{

src/GitHub.Api/Platform/IProcessEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace GitHub.Unity
44
{
55
public interface IProcessEnvironment
66
{
7-
void Configure(ProcessStartInfo psi, NPath workingDirectory);
7+
void Configure(ProcessStartInfo psi, NPath workingDirectory, bool dontSetupGit = false);
88
}
99
}

src/GitHub.Api/Platform/ProcessEnvironment.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public ProcessEnvironment(IEnvironment environment)
1515
Environment = environment;
1616
}
1717

18-
public void Configure(ProcessStartInfo psi, NPath workingDirectory)
18+
public void Configure(ProcessStartInfo psi, NPath workingDirectory, bool dontSetupGit = false)
1919
{
2020
psi.WorkingDirectory = workingDirectory;
2121
psi.EnvironmentVariables["HOME"] = NPath.HomeDirectory;
2222
psi.EnvironmentVariables["TMP"] = psi.EnvironmentVariables["TEMP"] = NPath.SystemTemp;
2323

2424
// if we don't know where git is, then there's nothing else to configure
25-
if (!Environment.GitInstallPath.IsInitialized)
25+
if (!Environment.GitInstallPath.IsInitialized || dontSetupGit)
2626
return;
2727

2828

@@ -52,7 +52,10 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory)
5252
baseExecPath = baseExecPath.Combine("mingw64");
5353
binPath = baseExecPath.Combine("bin");
5454
}
55+
5556
var execPath = baseExecPath.Combine("libexec", "git-core");
57+
if (!execPath.DirectoryExists())
58+
execPath = NPath.Default;
5659

5760
if (Environment.IsWindows)
5861
{
@@ -63,7 +66,9 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory)
6366
{
6467
path = $"{gitExecutableDir}:{binPath}:{execPath}:{gitLfsPath}:{Environment.Path}:{developerPaths}";
6568
}
66-
psi.EnvironmentVariables["GIT_EXEC_PATH"] = execPath.ToString();
69+
70+
if (execPath.IsInitialized)
71+
psi.EnvironmentVariables["GIT_EXEC_PATH"] = execPath.ToString();
6772

6873
psi.EnvironmentVariables["PATH"] = path;
6974
psi.EnvironmentVariables["GHU_FULLPATH"] = path;

src/GitHub.Api/Tasks/ProcessTask.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@ public static T Configure<T>(this T task, IProcessManager processManager, bool w
1818
return processManager.Configure(task, withInput: withInput);
1919
}
2020

21+
public static T Configure<T>(this T task, IProcessManager processManager, bool withInput, bool dontSetupGit)
22+
where T : IProcess
23+
{
24+
return processManager.Configure(task, withInput: withInput, dontSetupGit: dontSetupGit);
25+
}
26+
2127
public static T Configure<T>(this T task, IProcessManager processManager, string executable = null,
2228
string arguments = null,
2329
NPath? workingDirectory = null,
24-
bool withInput = false)
30+
bool withInput = false
31+
, bool dontSetupGit = false)
2532
where T : IProcess
2633
{
27-
return processManager.Configure(task, executable?.ToNPath(), arguments, workingDirectory, withInput);
34+
return processManager.Configure(task, executable?.ToNPath(), arguments, workingDirectory, withInput, dontSetupGit);
2835
}
2936
}
3037

0 commit comments

Comments
 (0)