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

Commit 0237ef2

Browse files
Tracking when git is custom vs internal
1 parent 2971a8a commit 0237ef2

File tree

7 files changed

+43
-13
lines changed

7 files changed

+43
-13
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using System.Collections.Generic;
6+
using System.Diagnostics.Eventing.Reader;
67
using GitHub.Logging;
78

89
namespace GitHub.Unity
@@ -53,9 +54,9 @@ protected void Initialize()
5354
public void Run(bool firstRun)
5455
{
5556
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
56-
57-
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken,
58-
(_, path) => InitializeEnvironment(path))
57+
58+
var initEnvironmentTask = new ActionTask<object[]>(CancellationToken,
59+
(_, values) => InitializeEnvironment((NPath)values[0], (bool)values[1]))
5960
{ Affinity = TaskAffinity.UI };
6061

6162
isBusy = true;
@@ -87,7 +88,9 @@ public void Run(bool firstRun)
8788
{
8889
if (path.IsInitialized)
8990
{
90-
t.GetEndOfChain().Then(initEnvironmentTask, taskIsTopOfChain: true);
91+
t.GetEndOfChain()
92+
.Then(b => new object[] {path, true})
93+
.Then(initEnvironmentTask, taskIsTopOfChain: true);
9194
return;
9295
}
9396
Logger.Trace("Using portable git");
@@ -98,7 +101,9 @@ public void Run(bool firstRun)
98101
task.Progress(progressReporter.UpdateProgress);
99102
task.OnEnd += (thisTask, result, success, exception) =>
100103
{
101-
thisTask.GetEndOfChain().Then(initEnvironmentTask, taskIsTopOfChain: true);
104+
thisTask.GetEndOfChain()
105+
.Then(b => new object[] { result, false })
106+
.Then(initEnvironmentTask, taskIsTopOfChain: true);
102107
};
103108

104109
// append installer task to top chain
@@ -204,8 +209,9 @@ protected void SetupMetrics(string unityVersion, bool firstRun)
204209
/// Initialize environment after finding where git is. This needs to run on the main thread
205210
/// </summary>
206211
/// <param name="gitExecutablePath"></param>
212+
/// <param name="isCustomGitExec"></param>
207213
/// <param name="octorunScriptPath"></param>
208-
private void InitializeEnvironment(NPath gitExecutablePath)
214+
private void InitializeEnvironment(NPath gitExecutablePath, bool isCustomGitExec)
209215
{
210216
isBusy = false;
211217
SetupMetrics();
@@ -216,6 +222,7 @@ private void InitializeEnvironment(NPath gitExecutablePath)
216222
}
217223

218224
Environment.GitExecutablePath = gitExecutablePath;
225+
Environment.IsCustomGitExecutable = isCustomGitExec;
219226
Environment.User.Initialize(GitClient);
220227

221228
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
@@ -226,7 +233,7 @@ private void InitializeEnvironment(NPath gitExecutablePath)
226233
{
227234
var credHelperTask = GitClient.GetConfig("credential.helper", GitConfigSource.Global);
228235
credHelperTask.OnEnd += (thisTask, credentialHelper, success, exception) =>
229-
{
236+
{
230237
if (!success || string.IsNullOrEmpty(credentialHelper))
231238
{
232239
Logger.Warning("No Windows CredentialHelper found: Setting to wincred");

src/GitHub.Api/OutputProcessors/ProcessManager.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using GitHub.Logging;
22
using System;
3+
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.IO;
56
using System.Linq;
@@ -29,7 +30,18 @@ public T Configure<T>(T processTask, NPath? executable = null, string arguments
2930
bool dontSetupGit = false)
3031
where T : IProcess
3132
{
32-
executable = executable ?? processTask.ProcessName?.ToNPath() ?? environment.GitExecutablePath;
33+
if (executable == null)
34+
{
35+
if (processTask.ProcessName?.ToNPath() != null)
36+
{
37+
executable = processTask.ProcessName.ToNPath();
38+
}
39+
else
40+
{
41+
executable = environment.GitExecutablePath;
42+
dontSetupGit = environment.IsCustomGitExecutable;
43+
}
44+
}
3345

3446
//If this null check fails, be sure you called Configure() on your task
3547
Guard.ArgumentNotNull(executable, nameof(executable));
@@ -85,11 +97,15 @@ public void RunCommandLineWindow(NPath workingDirectory)
8597
gitEnvironment.Configure(startInfo, workingDirectory);
8698

8799
var envVars = startInfo.EnvironmentVariables;
88-
var scriptContents = new[] {
100+
var scriptContents = new List<string> {
89101
$"cd \"{envVars["GHU_WORKINGDIR"]}\"",
90-
$"PATH=\"{envVars["GHU_FULLPATH"]}\" /bin/bash"
91102
};
92-
environment.FileSystem.WriteAllLines(envVarFile, scriptContents);
103+
104+
if (!environment.IsCustomGitExecutable) {
105+
scriptContents.Add($"PATH=\"{envVars["GHU_FULLPATH"]}\" /bin/bash");
106+
}
107+
108+
environment.FileSystem.WriteAllLines(envVarFile, scriptContents.ToArray());
93109
Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions)493); // -rwxr-xr-x mode (0755)
94110
}
95111
else

src/GitHub.Api/Platform/DefaultEnvironment.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ public NPath OctorunScriptPath
147147
octorunScriptPath = value;
148148
}
149149
}
150+
151+
public bool IsCustomGitExecutable { get; set; }
152+
150153
public NPath GitExecutablePath
151154
{
152155
get { return gitExecutablePath; }

src/GitHub.Api/Platform/IEnvironment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface IEnvironment
1212

1313
NPath Path { get; }
1414
string NewLine { get; }
15+
bool IsCustomGitExecutable { get; set; }
1516
NPath GitExecutablePath { get; set; }
1617
NPath NodeJsExecutablePath { get; }
1718
NPath OctorunScriptPath { get; set; }

src/GitHub.Api/Platform/ProcessEnvironment.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory, bool dontSet
2020
psi.WorkingDirectory = workingDirectory;
2121
psi.EnvironmentVariables["HOME"] = NPath.HomeDirectory;
2222
psi.EnvironmentVariables["TMP"] = psi.EnvironmentVariables["TEMP"] = NPath.SystemTemp;
23+
psi.EnvironmentVariables["GHU_WORKINGDIR"] = workingDirectory;
2324

2425
// if we don't know where git is, then there's nothing else to configure
2526
if (!Environment.GitInstallPath.IsInitialized || dontSetupGit)
2627
return;
2728

28-
2929
Guard.ArgumentNotNull(psi, "psi");
3030

3131
// We need to essentially fake up what git-cmd.bat does
@@ -77,7 +77,6 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory, bool dontSet
7777

7878
psi.EnvironmentVariables["PATH"] = path;
7979
psi.EnvironmentVariables["GHU_FULLPATH"] = path;
80-
psi.EnvironmentVariables["GHU_WORKINGDIR"] = workingDirectory;
8180

8281
psi.EnvironmentVariables["PLINK_PROTOCOL"] = "ssh";
8382
psi.EnvironmentVariables["TERM"] = "msys";

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ private void ValidateAndSetGitInstallPath(string value)
255255
{
256256
Manager.SystemSettings.Unset(Constants.GitInstallPathKey);
257257
Environment.GitExecutablePath = result;
258+
Environment.IsCustomGitExecutable = false;
258259

259260
gitExecHasChanged = true;
260261
}
@@ -323,6 +324,7 @@ private void ValidateAndSetGitInstallPath(string value)
323324

324325
Manager.SystemSettings.Set(Constants.GitInstallPathKey, value);
325326
Environment.GitExecutablePath = value.ToNPath();
327+
Environment.IsCustomGitExecutable = true;
326328

327329
gitExecHasChanged = true;
328330
}

src/tests/IntegrationTests/IntegrationTestEnvironment.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public string GetSpecialFolder(Environment.SpecialFolder folder)
8888
public string NewLine => Environment.NewLine;
8989
public string UnityVersion => "5.6";
9090

91+
public bool IsCustomGitExecutable { get; set; }
92+
9193
public NPath GitExecutablePath
9294
{
9395
get { return defaultEnvironment.GitExecutablePath; }

0 commit comments

Comments
 (0)