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

Commit 7946ffe

Browse files
Storing the git exec path in settings and loading the git exec path from settings
1 parent 8c0967e commit 7946ffe

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,10 @@ public virtual async Task Run(bool firstRun)
5252
}
5353
else
5454
{
55-
var progress = new ProgressReport();
56-
57-
var gitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
58-
var gitSetup = new GitInstaller(Environment, CancellationToken);
59-
var expectedPath = gitSetup.GitInstallationPath;
60-
var setupDone = await gitSetup.SetupIfNeeded(progress.Percentage, progress.Remaining);
61-
if (setupDone)
62-
Environment.GitExecutablePath = gitSetup.GitExecutablePath;
63-
else
64-
Environment.GitExecutablePath = await LookForGitInstallationPath(gitClient, SystemSettings).SafeAwait();
65-
66-
GitClient = gitClient;
55+
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
56+
Environment.GitExecutablePath = await DetermineGitExecutablePath();
6757

68-
Logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", gitSetup.GitExecutablePath, gitSetup.GitExecutablePath.FileExists());
58+
Logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", Environment.GitExecutablePath, Environment.GitExecutablePath.FileExists());
6959

7060
if (Environment.IsWindows)
7161
{
@@ -164,19 +154,25 @@ private async Task LoadKeychain()
164154
}
165155
}
166156

167-
private static async Task<NPath> LookForGitInstallationPath(IGitClient gitClient, ISettings systemSettings)
157+
private async Task<NPath> DetermineGitExecutablePath(ProgressReport progress = null)
168158
{
169-
NPath cachedGitInstallPath = null;
170-
var path = systemSettings.Get(Constants.GitInstallPathKey);
171-
if (!String.IsNullOrEmpty(path))
172-
cachedGitInstallPath = path.ToNPath();
159+
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
160+
if (gitExecutablePath != null && gitExecutablePath.FileExists())
161+
{
162+
Logger.Trace("Using git install path from settings");
163+
return gitExecutablePath;
164+
}
173165

174-
// Root paths
175-
if (cachedGitInstallPath != null && cachedGitInstallPath.DirectoryExists())
166+
var gitInstaller = new GitInstaller(Environment, CancellationToken);
167+
var setupDone = await gitInstaller.SetupIfNeeded(progress?.Percentage, progress?.Remaining);
168+
if (setupDone)
176169
{
177-
return cachedGitInstallPath;
170+
Logger.Trace("Setup performed using new path");
171+
return gitInstaller.GitExecutablePath;
178172
}
179-
return await gitClient.FindGitInstallation();
173+
174+
Logger.Trace("Finding git install path");
175+
return await GitClient.FindGitInstallation().SafeAwait();
180176
}
181177

182178
protected void SetupMetrics(string unityVersion, bool firstRun)

src/GitHub.Api/Platform/Settings.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public override void Initialize()
4646
{
4747
logger.Debug($"Initializing settings {GetType()}");
4848
cachePath = SettingsPath.Combine(SettingsFileName);
49-
logger.Trace("Initializing settings file at {0}", cachePath);
49+
50+
logger.Debug("Initializing settings file at {0}", cachePath);
5051
LoadFromCache(cachePath);
5152
}
5253

@@ -65,19 +66,31 @@ public override string Get(string key, string fallback = "")
6566
object value = null;
6667
if (cacheData.GitHubUnity.TryGetValue(key, out value))
6768
{
69+
logger.Debug("Get: {0}", key);
6870
return (T)value;
6971
}
7072

73+
logger.Debug("Miss: {0}", key);
7174
return fallback;
7275
}
7376

7477
public override void Set<T>(string key, T value)
7578
{
76-
if (!cacheData.GitHubUnity.ContainsKey(key))
77-
cacheData.GitHubUnity.Add(key, value);
78-
else
79-
cacheData.GitHubUnity[key] = value;
80-
SaveToCache(cachePath);
79+
try
80+
{
81+
logger.Trace("Set: {0}", key);
82+
83+
if (!cacheData.GitHubUnity.ContainsKey(key))
84+
cacheData.GitHubUnity.Add(key, value);
85+
else
86+
cacheData.GitHubUnity[key] = value;
87+
SaveToCache(cachePath);
88+
}
89+
catch (Exception e)
90+
{
91+
logger.Error(e, "Error storing to cache");
92+
throw;
93+
}
8194
}
8295

8396
public override void Unset(string key)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ private void OnInstallPathGUI()
607607
}
608608
if (EditorGUI.EndChangeCheck())
609609
{
610+
Logger.Trace("Setting GitExecPath: " + gitExecPath);
611+
612+
Manager.SystemSettings.Set(Constants.GitInstallPathKey, gitExecPath);
610613
Environment.GitExecutablePath = gitExecPath.ToNPath();
611614
}
612615

0 commit comments

Comments
 (0)