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

Commit f7c31a1

Browse files
committed
More git installer fixes
1 parent 7709a8b commit f7c31a1

File tree

13 files changed

+239
-251
lines changed

13 files changed

+239
-251
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,22 @@ public void Run()
7171
}
7272
}
7373

74-
var installer = new GitInstaller(Environment, ProcessManager, CancellationToken, SystemSettings)
74+
var installer = new GitInstaller(Environment, ProcessManager, CancellationToken)
7575
{ Progress = progressReporter };
76-
state = SystemSettings.Get<GitInstallationState>(Constants.GitInstallationState) ?? state;
76+
state = Environment.GitInstallationState;
77+
if (!state.GitIsValid && !state.GitLfsIsValid && FirstRun)
78+
{
79+
// importing old settings
80+
NPath gitExecutablePath = Environment.SystemSettings.Get(Constants.GitInstallPathKey, NPath.Default);
81+
if (gitExecutablePath.IsInitialized)
82+
{
83+
Environment.SystemSettings.Unset(Constants.GitInstallPathKey);
84+
state.GitExecutablePath = gitExecutablePath;
85+
state.GitInstallationPath = gitExecutablePath.Parent.Parent;
86+
Environment.GitInstallationState = state;
87+
}
88+
}
89+
7790
if (state.GitIsValid && state.GitLfsIsValid)
7891
{
7992
if (firstRun)
@@ -145,11 +158,7 @@ public void SetupGit(GitInstaller.GitInstallationState state)
145158
return;
146159
}
147160

148-
Environment.GitInstallPath = state.GitInstallationPath;
149-
Environment.GitExecutablePath = state.GitExecutablePath;
150-
Environment.GitLfsInstallPath = state.GitLfsInstallationPath;
151-
Environment.GitLfsExecutablePath = state.GitLfsExecutablePath;
152-
Environment.IsCustomGitExecutable = state.IsCustomGitPath;
161+
Environment.GitInstallationState = state;
153162
Environment.User.Initialize(GitClient);
154163

155164
if (firstRun)

src/GitHub.Api/Git/GitClient.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace GitHub.Unity
88
{
99
public interface IGitClient
1010
{
11-
ITask<GitInstallationState> ValidateGitInstall(ISettings settings, NPath path, bool isCustomGit);
1211
ITask<string> Init(IOutputProcessor<string> processor = null);
1312
ITask<string> LfsInstall(IOutputProcessor<string> processor = null);
1413
ITask<GitAheadBehindStatus> AheadBehindStatus(string gitRef, string otherRef, IOutputProcessor<GitAheadBehindStatus> processor = null);
@@ -57,26 +56,6 @@ public GitClient(IEnvironment environment, IProcessManager processManager, Cance
5756
this.cancellationToken = cancellationToken;
5857
}
5958

60-
public ITask<GitInstallationState> ValidateGitInstall(ISettings settings, NPath path, bool isCustomGit)
61-
{
62-
return new FuncTask<GitInstallationState>(cancellationToken, () =>
63-
{
64-
NPath existingPath = settings.Get(Constants.GitInstallPathKey).ToNPath();
65-
settings.Set(Constants.GitInstallPathKey, path);
66-
var state = new GitInstaller.GitInstallationState();
67-
var installer = new GitInstaller(environment, processManager, cancellationToken, settings);
68-
state = installer.VerifyGitFromSettings(state);
69-
if (!state.GitIsValid)
70-
{
71-
if (!existingPath.IsInitialized)
72-
settings.Unset(Constants.GitInstallPathKey);
73-
else
74-
settings.Set(Constants.GitInstallPathKey, existingPath);
75-
}
76-
return state;
77-
});
78-
}
79-
8059
public ITask<string> Init(IOutputProcessor<string> processor = null)
8160
{
8261
return new GitInitTask(cancellationToken, processor)

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,41 @@ public class GitInstaller
1111

1212
private readonly IEnvironment environment;
1313
private readonly IProcessManager processManager;
14-
private readonly ISettings systemSettings;
1514
private readonly GitInstallDetails installDetails;
1615
private readonly IZipHelper sharpZipLibHelper;
1716

1817
public IProgress Progress { get; set; }
1918

2019
public GitInstaller(IEnvironment environment, IProcessManager processManager,
2120
CancellationToken token,
22-
ISettings systemSettings,
2321
GitInstallDetails installDetails = null)
2422
{
2523
this.environment = environment;
2624
this.processManager = processManager;
27-
this.systemSettings = systemSettings;
2825
this.sharpZipLibHelper = ZipHelper.Instance;
2926
this.cancellationToken = token;
3027
this.installDetails = installDetails ?? new GitInstallDetails(environment.UserCachePath, environment.IsWindows);
3128
}
3229

33-
public GitInstallationState SetupGitIfNeeded()
30+
public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
3431
{
35-
var state = new GitInstallationState();
36-
state = VerifyGitFromSettings(state);
32+
state = VerifyGitSettings(state);
3733
if (state.GitIsValid && state.GitLfsIsValid)
3834
{
3935
Logger.Trace("Using git install path from settings: {0}", state.GitExecutablePath);
4036
state.GitLastCheckTime = DateTimeOffset.Now;
41-
systemSettings?.Set(Constants.GitInstallationState, state);
4237
return state;
4338
}
4439

45-
if (environment.IsWindows)
46-
state = FindWindowsGit(state);
47-
else
48-
state = FindMacGit(state);
40+
if (environment.IsMac)
41+
state = FindSystemGit(state);
42+
state = SetDefaultPaths(state);
4943

5044
state = CheckForUpdates(state);
5145

5246
if (state.GitIsValid && state.GitLfsIsValid)
5347
{
5448
state.GitLastCheckTime = DateTimeOffset.Now;
55-
systemSettings?.Set(Constants.GitInstallationState, state);
5649
return state;
5750
}
5851

@@ -61,35 +54,42 @@ public GitInstallationState SetupGitIfNeeded()
6154
state = GrabZipFromResourcesIfNeeded(state);
6255
state = ExtractGit(state);
6356
state.GitLastCheckTime = DateTimeOffset.Now;
64-
systemSettings?.Set(Constants.GitInstallationState, state);
6557
return state;
6658
}
6759

68-
public GitInstallationState VerifyGitFromSettings(GitInstallationState state)
60+
public GitInstallationState VerifyGitSettings(GitInstallationState state = null)
6961
{
70-
if (systemSettings == null)
62+
state = state ?? environment.GitInstallationState;
63+
if (!state.GitExecutablePath.IsInitialized && !state.GitLfsExecutablePath.IsInitialized)
7164
return state;
7265

73-
NPath gitExecutablePath = systemSettings.Get(Constants.GitInstallPathKey).ToNPath();
74-
if (!gitExecutablePath.IsInitialized || !gitExecutablePath.FileExists())
75-
return state;
76-
77-
state.GitExecutablePath = gitExecutablePath;
7866
state = ValidateGitVersion(state);
7967
if (state.GitIsValid)
8068
state.GitInstallationPath = state.GitExecutablePath.Parent.Parent;
81-
state.GitLfsExecutablePath = ProcessManager.FindExecutableInPath(installDetails.GitLfsExecutable, true, state.GitInstallationPath);
69+
70+
var isDefaultGitLfs = !state.GitLfsExecutablePath.IsInitialized || state.GitLfsInstallationPath == state.GitInstallationPath;
71+
if (isDefaultGitLfs)
72+
state.GitLfsExecutablePath = ProcessManager.FindExecutableInPath(installDetails.GitLfsExecutable, true, state.GitInstallationPath);
73+
8274
state = ValidateGitLfsVersion(state);
75+
8376
if (state.GitLfsIsValid)
84-
state.GitLfsInstallationPath = state.GitInstallationPath;
77+
{
78+
if (isDefaultGitLfs)
79+
state.GitLfsInstallationPath = state.GitInstallationPath;
80+
else
81+
state.GitLfsInstallationPath = state.GitLfsExecutablePath.Parent;
82+
}
83+
8584
return state;
8685
}
8786

88-
private GitInstallationState FindMacGit(GitInstallationState state)
87+
public GitInstallationState FindSystemGit(GitInstallationState state)
8988
{
9089
if (!state.GitIsValid)
9190
{
92-
var gitPath = new FindExecTask("git", cancellationToken).Configure(processManager, dontSetupGit: true)
91+
var gitPath = new FindExecTask("git", cancellationToken)
92+
.Configure(processManager, dontSetupGit: true)
9393
.Catch(e => true)
9494
.RunWithReturn(true);
9595
state.GitExecutablePath = gitPath;
@@ -107,17 +107,12 @@ private GitInstallationState FindMacGit(GitInstallationState state)
107107
state.GitLfsExecutablePath = gitLfsPath;
108108
state = ValidateGitLfsVersion(state);
109109
if (state.GitLfsIsValid)
110-
state.GitLfsInstallationPath = gitLfsPath.Parent.Parent;
111-
else
112-
{
113-
state.GitLfsInstallationPath = installDetails.GitInstallationPath;
114-
state.GitLfsExecutablePath = installDetails.GitLfsExecutablePath;
115-
}
110+
state.GitLfsInstallationPath = gitLfsPath.Parent;
116111
}
117112
return state;
118113
}
119114

120-
private GitInstallationState FindWindowsGit(GitInstallationState state)
115+
public GitInstallationState SetDefaultPaths(GitInstallationState state)
121116
{
122117
if (!state.GitIsValid)
123118
{
@@ -128,8 +123,11 @@ private GitInstallationState FindWindowsGit(GitInstallationState state)
128123

129124
if (!state.GitLfsIsValid)
130125
{
131-
state.GitLfsInstallationPath = installDetails.GitInstallationPath;
132126
state.GitLfsExecutablePath = installDetails.GitLfsExecutablePath;
127+
if (state.GitIsValid && state.GitInstallationPath != installDetails.GitInstallationPath)
128+
state.GitLfsInstallationPath = state.GitLfsExecutablePath.Parent;
129+
else
130+
state.GitLfsInstallationPath = installDetails.GitInstallationPath;
133131
state = ValidateGitLfsVersion(state);
134132
}
135133
return state;

src/GitHub.Api/Platform/DefaultEnvironment.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,26 @@ public NPath OctorunScriptPath
150150
}
151151
}
152152

153-
public bool IsCustomGitExecutable { get; set; }
154-
155-
public NPath GitInstallPath { get; set; }
156-
public NPath GitExecutablePath { get; set; }
153+
public bool IsCustomGitExecutable => GitInstallationState?.IsCustomGitPath ?? false;
154+
public NPath GitInstallPath => GitInstallationState?.GitInstallationPath ?? NPath.Default;
155+
public NPath GitExecutablePath => GitInstallationState?.GitExecutablePath ?? NPath.Default;
156+
public NPath GitLfsInstallPath => GitInstallationState?.GitLfsInstallationPath ?? NPath.Default;
157+
public NPath GitLfsExecutablePath => GitInstallationState?.GitLfsExecutablePath ?? NPath.Default;
158+
public GitInstaller.GitInstallationState GitInstallationState
159+
{
160+
get
161+
{
162+
return SystemSettings.Get<GitInstaller.GitInstallationState>(Constants.GitInstallationState, new GitInstaller.GitInstallationState());
163+
}
164+
set
165+
{
166+
if (value == null)
167+
SystemSettings.Unset(Constants.GitInstallationState);
168+
else
169+
SystemSettings.Set<GitInstaller.GitInstallationState>(Constants.GitInstallationState, value);
170+
}
171+
}
157172

158-
public NPath GitLfsInstallPath { get; set; }
159-
public NPath GitLfsExecutablePath { get; set; }
160173

161174
public NPath NodeJsExecutablePath
162175
{

src/GitHub.Api/Platform/IEnvironment.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ public interface IEnvironment
1212

1313
string Path { get; set; }
1414
string NewLine { get; }
15-
bool IsCustomGitExecutable { get; set; }
16-
NPath GitExecutablePath { get; set; }
15+
GitInstaller.GitInstallationState GitInstallationState { get; set; }
16+
bool IsCustomGitExecutable { get; }
17+
NPath GitExecutablePath { get; }
18+
NPath GitInstallPath { get; }
19+
NPath GitLfsInstallPath { get; }
20+
NPath GitLfsExecutablePath { get; }
1721
NPath NodeJsExecutablePath { get; }
1822
NPath OctorunScriptPath { get; set; }
1923
bool IsWindows { get; }
@@ -26,9 +30,6 @@ public interface IEnvironment
2630
NPath UnityProjectPath { get; }
2731
NPath ExtensionInstallPath { get; }
2832
NPath RepositoryPath { get; }
29-
NPath GitInstallPath { get; set; }
30-
NPath GitLfsInstallPath { get; set; }
31-
NPath GitLfsExecutablePath { get; set; }
3233
NPath UserCachePath { get; set; }
3334
NPath SystemCachePath { get; set; }
3435
NPath LogPath { get; }

src/GitHub.Api/Platform/Settings.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class BaseSettings : ISettings
2424
class JsonBackedSettings : BaseSettings
2525
{
2626
private string cachePath;
27-
private Dictionary<string, object> cacheData;
27+
protected Dictionary<string, object> cacheData;
2828
private Action<string> dirCreate;
2929
private Func<string, bool> dirExists;
3030
private Action<string> fileDelete;
@@ -82,7 +82,12 @@ public override string Get(string key, string fallback = "")
8282
}
8383
}
8484

85-
if (!(value is T))
85+
if (value == null && fallback != null)
86+
{
87+
value = fallback;
88+
cacheData[key] = fallback;
89+
}
90+
else if (!(value is T))
8691
{
8792
try
8893
{
@@ -147,7 +152,7 @@ public override void Rename(string oldKey, string newKey)
147152
SaveToCache(cachePath);
148153
}
149154

150-
private void LoadFromCache(string path)
155+
protected virtual void LoadFromCache(string path)
151156
{
152157
EnsureCachePath(path);
153158

@@ -191,7 +196,7 @@ private void LoadFromCache(string path)
191196
}
192197
}
193198

194-
private bool SaveToCache(string path)
199+
protected virtual bool SaveToCache(string path)
195200
{
196201
EnsureCachePath(path);
197202

src/GitHub.Api/Primitives/TheVersion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ public bool Equals(TheVersion other)
191191
{
192192
if (lhs.Version == rhs.Version)
193193
return false;
194-
if (lhs.Version == null)
194+
if (String.IsNullOrEmpty(lhs.Version))
195195
return false;
196-
if (rhs.Version == null)
196+
if (String.IsNullOrEmpty(rhs.Version))
197197
return true;
198198

199199
for (var i = 0; i < PART_COUNT; i++)

src/UnityExtension/Assets/Editor/GitHub.Unity/EntryPoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private static void Initialize()
6464
}
6565

6666
LogHelper.LogAdapter = new MultipleLogAdapter(new FileLogAdapter(logPath)
67-
//, new UnityLogAdapter()
67+
, new UnityLogAdapter()
6868
);
6969
LogHelper.Info("Initializing GitHubForUnity:'v{0}' Unity:'v{1}'", ApplicationInfo.Version, Environment.UnityVersion);
7070

0 commit comments

Comments
 (0)