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

Commit e5c3bf5

Browse files
committed
Only try to update git/lfs if it's not a custom/system installation
1 parent dea4762 commit e5c3bf5

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
4343
{
4444
if (environment.IsMac)
4545
state = FindGit(state);
46-
state = SetDefaultPaths(state);
4746
}
4847

49-
state = CheckForUpdates(state);
48+
state = SetDefaultPaths(state);
49+
state = CheckForGitUpdates(state);
5050

5151
if (state.GitIsValid && state.GitLfsIsValid)
5252
{
@@ -99,34 +99,34 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
9999
return state;
100100
}
101101

102-
private GitInstallationState FindGitLfs(GitInstallationState state)
102+
private GitInstallationState FindGit(GitInstallationState state)
103103
{
104-
if (!state.GitLfsIsValid)
104+
if (!state.GitIsValid)
105105
{
106-
var gitLfsPath = new FindExecTask("git-lfs", cancellationToken)
106+
var gitPath = new FindExecTask("git", cancellationToken)
107107
.Configure(processManager, dontSetupGit: true)
108108
.Catch(e => true)
109109
.RunWithReturn(true);
110-
state.GitLfsExecutablePath = gitLfsPath;
111-
state = ValidateGitLfsVersion(state);
112-
if (state.GitLfsIsValid)
113-
state.GitLfsInstallationPath = state.GitLfsExecutablePath.Parent;
110+
state.GitExecutablePath = gitPath;
111+
state = ValidateGitVersion(state);
112+
if (state.GitIsValid)
113+
state.GitInstallationPath = gitPath.Parent.Parent;
114114
}
115115
return state;
116116
}
117117

118-
private GitInstallationState FindGit(GitInstallationState state)
118+
private GitInstallationState FindGitLfs(GitInstallationState state)
119119
{
120-
if (!state.GitIsValid)
120+
if (!state.GitLfsIsValid)
121121
{
122-
var gitPath = new FindExecTask("git", cancellationToken)
122+
var gitLfsPath = new FindExecTask("git-lfs", cancellationToken)
123123
.Configure(processManager, dontSetupGit: true)
124124
.Catch(e => true)
125125
.RunWithReturn(true);
126-
state.GitExecutablePath = gitPath;
127-
state = ValidateGitVersion(state);
128-
if (state.GitIsValid)
129-
state.GitInstallationPath = gitPath.Parent.Parent;
126+
state.GitLfsExecutablePath = gitLfsPath;
127+
state = ValidateGitLfsVersion(state);
128+
if (state.GitLfsIsValid)
129+
state.GitLfsInstallationPath = state.GitLfsExecutablePath.Parent;
130130
}
131131
return state;
132132
}
@@ -181,29 +181,35 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
181181
return state;
182182
}
183183

184-
private GitInstallationState CheckForUpdates(GitInstallationState state)
184+
private GitInstallationState CheckForGitUpdates(GitInstallationState state)
185185
{
186-
state.GitPackage = Package.Load(environment, installDetails.GitPackageFeed);
187-
if (state.GitPackage != null)
186+
if (state.GitInstallationPath == installDetails.GitInstallationPath)
188187
{
189-
state.GitIsValid = state.GitVersion >= state.GitPackage.Version;
190-
if (state.GitIsValid)
188+
state.GitPackage = Package.Load(environment, installDetails.GitPackageFeed);
189+
if (state.GitPackage != null)
191190
{
192-
state.IsCustomGitPath = state.GitExecutablePath != installDetails.GitExecutablePath;
193-
}
194-
else
195-
{
196-
Logger.Trace($"{installDetails.GitExecutablePath} is out of date");
191+
state.GitIsValid = state.GitVersion >= state.GitPackage.Version;
192+
if (state.GitIsValid)
193+
{
194+
state.IsCustomGitPath = state.GitExecutablePath != installDetails.GitExecutablePath;
195+
}
196+
else
197+
{
198+
Logger.Trace($"{installDetails.GitExecutablePath} is out of date");
199+
}
197200
}
198201
}
199202

200-
state.GitLfsPackage = Package.Load(environment, installDetails.GitLfsPackageFeed);
201-
if (state.GitLfsPackage != null)
203+
if (state.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
202204
{
203-
state.GitLfsIsValid = state.GitLfsVersion >= state.GitLfsPackage.Version;
204-
if (!state.GitLfsIsValid)
205+
state.GitLfsPackage = Package.Load(environment, installDetails.GitLfsPackageFeed);
206+
if (state.GitLfsPackage != null)
205207
{
206-
Logger.Trace($"{installDetails.GitLfsExecutablePath} is out of date");
208+
state.GitLfsIsValid = state.GitLfsVersion >= state.GitLfsPackage.Version;
209+
if (!state.GitLfsIsValid)
210+
{
211+
Logger.Trace($"{installDetails.GitLfsExecutablePath} is out of date");
212+
}
207213
}
208214
}
209215
return state;
@@ -239,8 +245,7 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
239245
return state;
240246

241247
var downloader = new Downloader();
242-
downloader
243-
.Catch(e =>
248+
downloader.Catch(e =>
244249
{
245250
LogHelper.Trace(e, "Failed to download");
246251
return true;
@@ -261,11 +266,14 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
261266

262267
private GitInstallationState GrabZipFromResourcesIfNeeded(GitInstallationState state)
263268
{
264-
if (!state.GitZipExists && !state.GitIsValid)
269+
if (!state.GitZipExists && !state.GitIsValid && state.GitInstallationPath == installDetails.GitInstallationPath)
265270
AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.ZipPath, environment);
266271
state.GitZipExists = installDetails.GitZipPath.FileExists();
267272

268-
if (!state.GitLfsZipExists && !state.GitLfsIsValid)
273+
if (state.GitLfsInstallationPath != installDetails.GitLfsInstallationPath)
274+
return state;
275+
276+
if (!state.GitLfsZipExists && !state.GitLfsIsValid && state.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
269277
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", installDetails.ZipPath, environment);
270278
state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
271279
return state;

0 commit comments

Comments
 (0)