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

Commit 21b5c6c

Browse files
committed
Validate git installations by version and fix setting up custom gits
Since we know which git and git lfs versions we want and we already check them in the settings view, switch to using version checks instead of md5 everywhere. If we find a good enough version, use it. Make sure we do update checks once a day for git and git lfs. Go and find lfs if we have a git custom path on all OSes Make sure we restart the repository manager and everything else that relies on git when we switch gits, since outputs may change.
1 parent 324c534 commit 21b5c6c

26 files changed

+228
-279
lines changed

generate-package.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,18 @@ if [ $# -lt 3 ]; then
55
exit 1
66
fi
77

8-
LFS_MD5="4294df6cbb467b8133553570450757c7"
9-
GIT_MD5="50570ed932559f294d1a1361801740b9"
10-
MD5=""
11-
128
URL="http://ghfvs-installer.github.com"
139
if [ $# -ge 4 ]; then
1410
URL=$4
1511
fi
1612

1713
if [ "$1" == "git" ]; then
18-
MD5=$GIT_MD5
1914
URL="$URL/unity/git"
2015
fi
2116
if [ "$1" == "lfs" ]; then
22-
MD5=$LFS_MD5
2317
URL="$URL/unity/git"
2418
fi
2519
if [ "$1" == "ghu" ]; then
26-
MD5=
2720
URL="$URL/unity/releases"
2821
fi
2922

@@ -46,4 +39,4 @@ if [ ! -e "$DIR/build/CommandLine/CommandLine.exe" ]; then
4639
>&2 xbuild /target:CommandLine "$DIR/GitHub.Unity.sln" /verbosity:minimal
4740
fi
4841

49-
"$EXEC""$DIR/build/CommandLine/CommandLine.exe" --gen-package --version "$2" --path "$3" --url "$URL" --md5 "$MD5" --rn "$RN" --msg "$MSG"
42+
"$EXEC""$DIR/build/CommandLine/CommandLine.exe" --gen-package --version "$2" --path "$3" --url "$URL" --rn "$RN" --msg "$MSG"

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,37 @@ public void Run()
6868
}
6969

7070
GitInstallationState state = new GitInstallationState();
71-
var runInstallers = firstRun;
72-
73-
if (!runInstallers)
71+
bool skipInstallers = false;
72+
state = SystemSettings.Get<GitInstallationState>(Constants.GitInstallationState) ?? state;
73+
var now = DateTimeOffset.Now;
74+
if (now.Date == state.GitLastCheckTime.Date && state.GitIsValid && state.GitLfsIsValid)
7475
{
75-
state = SystemSettings.Get<GitInstallationState>(Constants.GitInstallationState) ?? state;
76-
var now = DateTimeOffset.Now;
77-
runInstallers = now.Date != state.GitLastCheckTime.Date || (!(state.GitIsValid && state.GitLfsIsValid));
76+
// just check if the git/git lfs version is what we need
77+
if (firstRun)
78+
{
79+
var version = new GitVersionTask(token)
80+
.Configure(ProcessManager, state.GitExecutablePath, dontSetupGit: true)
81+
.Catch(e => true)
82+
.RunWithReturn(true);
83+
state.GitIsValid = version >= Constants.MinimumGitVersion;
84+
if (state.GitIsValid)
85+
{
86+
version = new GitLfsVersionTask(token)
87+
.Configure(ProcessManager, state.GitLfsExecutablePath, dontSetupGit: true)
88+
.Catch(e => true)
89+
.RunWithReturn(true);
90+
state.GitLfsIsValid = version >= Constants.MinimumGitLfsVersion;
91+
}
92+
}
7893
}
7994

80-
if (runInstallers)
95+
if (!skipInstallers)
8196
{
8297
Environment.OctorunScriptPath = new OctorunInstaller(Environment, TaskManager)
8398
.SetupOctorunIfNeeded();
8499

85-
state = new GitInstaller(Environment, ProcessManager, TaskManager, SystemSettings)
86-
{ Progress = progressReporter }
100+
state = new GitInstaller(Environment, ProcessManager, CancellationToken, SystemSettings)
101+
{ Progress = progressReporter }
87102
.SetupGitIfNeeded();
88103
}
89104

@@ -109,7 +124,7 @@ public void Run()
109124
thread.Start(CancellationToken);
110125
}
111126

112-
private void SetupGit(GitInstaller.GitInstallationState state)
127+
public void SetupGit(GitInstaller.GitInstallationState state)
113128
{
114129
if (!(state.GitIsValid && state.GitLfsIsValid))
115130
return;
@@ -201,6 +216,8 @@ public void RestartRepository()
201216
if (!Environment.RepositoryPath.IsInitialized)
202217
return;
203218

219+
repositoryManager?.Dispose();
220+
204221
repositoryManager = Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, Environment.FileSystem, Environment.RepositoryPath);
205222
repositoryManager.Initialize();
206223
Environment.Repository.Initialize(repositoryManager, TaskManager);

src/GitHub.Api/Application/IApplicationManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ public interface IApplicationManager : IDisposable
1919
IUsageTracker UsageTracker { get; }
2020
bool IsBusy { get; }
2121
void Run();
22-
void RestartRepository();
2322
void InitializeRepository();
2423
event Action<IProgress> OnProgress;
24+
void SetupGit(GitInstaller.GitInstallationState state);
25+
void RestartRepository();
2526
}
2627
}

src/GitHub.Api/Git/GitClient.cs

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
using GitHub.Logging;
22
using System;
33
using System.Collections.Generic;
4-
using System.Linq;
54
using System.Threading;
6-
using System.Threading.Tasks;
5+
using static GitHub.Unity.GitInstaller;
76

87
namespace GitHub.Unity
98
{
109
public interface IGitClient
1110
{
12-
ITask<ValidateGitInstallResult> ValidateGitInstall(NPath path, bool isCustomGit);
11+
ITask<GitInstallationState> ValidateGitInstall(ISettings settings, NPath path, bool isCustomGit);
1312
ITask<string> Init(IOutputProcessor<string> processor = null);
1413
ITask<string> LfsInstall(IOutputProcessor<string> processor = null);
1514
ITask<GitAheadBehindStatus> AheadBehindStatus(string gitRef, string otherRef, IOutputProcessor<GitAheadBehindStatus> processor = null);
@@ -35,11 +34,11 @@ public interface IGitClient
3534
ITask<string> DiscardAll(IOutputProcessor<string> processor = null);
3635
ITask<string> Remove(IList<string> files, IOutputProcessor<string> processor = null);
3736
ITask<string> AddAndCommit(IList<string> files, string message, string body, IOutputProcessor<string> processor = null);
38-
ITask<string> Lock(string file, IOutputProcessor<string> processor = null);
39-
ITask<string> Unlock(string file, bool force, IOutputProcessor<string> processor = null);
37+
ITask<string> Lock(NPath file, IOutputProcessor<string> processor = null);
38+
ITask<string> Unlock(NPath file, bool force, IOutputProcessor<string> processor = null);
4039
ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> processor = null);
41-
ITask<Version> Version(IOutputProcessor<Version> processor = null);
42-
ITask<Version> LfsVersion(IOutputProcessor<Version> processor = null);
40+
ITask<TheVersion> Version(IOutputProcessor<TheVersion> processor = null);
41+
ITask<TheVersion> LfsVersion(IOutputProcessor<TheVersion> processor = null);
4342
ITask<GitUser> SetConfigNameAndEmail(string username, string email);
4443
}
4544

@@ -58,31 +57,24 @@ public GitClient(IEnvironment environment, IProcessManager processManager, Cance
5857
this.cancellationToken = cancellationToken;
5958
}
6059

61-
public ITask<ValidateGitInstallResult> ValidateGitInstall(NPath path, bool isCustomGit)
60+
public ITask<GitInstallationState> ValidateGitInstall(ISettings settings, NPath path, bool isCustomGit)
6261
{
63-
Version gitVersion = null;
64-
Version gitLfsVersion = null;
65-
66-
var endTask = new FuncTask<ValidateGitInstallResult>(cancellationToken,
67-
() => new ValidateGitInstallResult(
68-
gitVersion?.CompareTo(Constants.MinimumGitVersion) >= 0 &&
69-
gitLfsVersion?.CompareTo(Constants.MinimumGitLfsVersion) >= 0,
70-
gitVersion, gitLfsVersion));
71-
72-
if (path.FileExists())
62+
return new FuncTask<GitInstallationState>(cancellationToken, () =>
7363
{
74-
var gitLfsVersionTask = new GitLfsVersionTask(cancellationToken)
75-
.Configure(processManager, path, dontSetupGit: isCustomGit);
76-
gitLfsVersionTask.OnEnd += (t, v, _, __) => gitLfsVersion = v;
77-
var gitVersionTask = new GitVersionTask(cancellationToken)
78-
.Configure(processManager, path, dontSetupGit: isCustomGit);
79-
gitVersionTask.OnEnd += (t, v, _, __) => gitVersion = v;
80-
81-
gitVersionTask
82-
.Then(gitLfsVersionTask)
83-
.Finally(endTask);
84-
}
85-
return endTask;
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+
});
8678
}
8779

8880
public ITask<string> Init(IOutputProcessor<string> processor = null)
@@ -115,13 +107,13 @@ public ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> process
115107
.Configure(processManager);
116108
}
117109

118-
public ITask<Version> Version(IOutputProcessor<Version> processor = null)
110+
public ITask<TheVersion> Version(IOutputProcessor<TheVersion> processor = null)
119111
{
120112
return new GitVersionTask(cancellationToken, processor)
121113
.Configure(processManager);
122114
}
123115

124-
public ITask<Version> LfsVersion(IOutputProcessor<Version> processor = null)
116+
public ITask<TheVersion> LfsVersion(IOutputProcessor<TheVersion> processor = null)
125117
{
126118
return new GitLfsVersionTask(cancellationToken, processor)
127119
.Configure(processManager);
@@ -318,14 +310,14 @@ public ITask<string> AddAndCommit(IList<string> files, string message, string bo
318310
.Configure(processManager));
319311
}
320312

321-
public ITask<string> Lock(string file,
313+
public ITask<string> Lock(NPath file,
322314
IOutputProcessor<string> processor = null)
323315
{
324316
return new GitLockTask(file, cancellationToken, processor)
325317
.Configure(processManager);
326318
}
327319

328-
public ITask<string> Unlock(string file, bool force,
320+
public ITask<string> Unlock(NPath file, bool force,
329321
IOutputProcessor<string> processor = null)
330322
{
331323
return new GitUnlockTask(file, force, cancellationToken, processor)

src/GitHub.Api/Git/IRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public interface IRepository : IEquatable<IRepository>, IDisposable
1818
ITask Push();
1919
ITask Fetch();
2020
ITask Revert(string changeset);
21-
ITask RequestLock(string file);
22-
ITask ReleaseLock(string file, bool force);
21+
ITask RequestLock(NPath file);
22+
ITask ReleaseLock(NPath file, bool force);
2323
ITask DiscardChanges(GitStatusEntry[] discardEntries);
2424
void CheckAndRaiseEventsIfCacheNewer(CacheType cacheType, CacheUpdateEvent cacheUpdateEvent);
2525

src/GitHub.Api/Git/Repository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public ITask SetupRemote(string remote, string remoteUrl)
116116
public ITask Push() => repositoryManager.Push(CurrentRemote.Value.Name, CurrentBranch?.Name);
117117
public ITask Fetch() => repositoryManager.Fetch(CurrentRemote.Value.Name);
118118
public ITask Revert(string changeset) => repositoryManager.Revert(changeset);
119-
public ITask RequestLock(string file) => repositoryManager.LockFile(file);
120-
public ITask ReleaseLock(string file, bool force) => repositoryManager.UnlockFile(file, force);
119+
public ITask RequestLock(NPath file) => repositoryManager.LockFile(file);
120+
public ITask ReleaseLock(NPath file, bool force) => repositoryManager.UnlockFile(file, force);
121121
public ITask DiscardChanges(GitStatusEntry[] gitStatusEntry) => repositoryManager.DiscardChanges(gitStatusEntry);
122122
public ITask RemoteAdd(string remote, string url) => repositoryManager.RemoteAdd(remote, url);
123123
public ITask RemoteRemove(string remote) => repositoryManager.RemoteRemove(remote);

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public interface IRepositoryManager : IDisposable
3434
ITask SwitchBranch(string branch);
3535
ITask DeleteBranch(string branch, bool deleteUnmerged = false);
3636
ITask CreateBranch(string branch, string baseBranch);
37-
ITask LockFile(string file);
38-
ITask UnlockFile(string file, bool force);
37+
ITask LockFile(NPath file);
38+
ITask UnlockFile(NPath file, bool force);
3939
ITask DiscardChanges(GitStatusEntry[] gitStatusEntries);
4040
void UpdateGitLog();
4141
void UpdateGitStatus();
@@ -255,13 +255,13 @@ public ITask CreateBranch(string branch, string baseBranch)
255255
return HookupHandlers(task, false);
256256
}
257257

258-
public ITask LockFile(string file)
258+
public ITask LockFile(NPath file)
259259
{
260260
var task = GitClient.Lock(file);
261261
return HookupHandlers(task, false).Then(UpdateLocks);
262262
}
263263

264-
public ITask UnlockFile(string file, bool force)
264+
public ITask UnlockFile(NPath file, bool force)
265265
{
266266
var task = GitClient.Unlock(file, force);
267267
return HookupHandlers(task, false).Then(UpdateLocks);

src/GitHub.Api/Git/Tasks/GitLfsVersionTask.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
namespace GitHub.Unity
55
{
6-
class GitLfsVersionTask : ProcessTask<Version>
6+
class GitLfsVersionTask : ProcessTask<TheVersion>
77
{
88
private const string TaskName = "git lfs version";
99

10-
public GitLfsVersionTask(CancellationToken token, IOutputProcessor<Version> processor = null)
10+
public GitLfsVersionTask(CancellationToken token, IOutputProcessor<TheVersion> processor = null)
1111
: base(token, processor ?? new LfsVersionOutputProcessor())
1212
{
1313
Name = TaskName;

src/GitHub.Api/Git/Tasks/GitUnlockTask.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class GitUnlockTask : ProcessTask<string>
88
private const string TaskName = "git lfs unlock";
99
private readonly string arguments;
1010

11-
public GitUnlockTask(string path, bool force,
11+
public GitUnlockTask(NPath path, bool force,
1212
CancellationToken token, IOutputProcessor<string> processor = null)
1313
: base(token, processor ?? new SimpleOutputProcessor())
1414
{
@@ -23,7 +23,7 @@ public GitUnlockTask(string path, bool force,
2323
}
2424

2525
stringBuilder.Append("\"");
26-
stringBuilder.Append(path);
26+
stringBuilder.Append(path.ToString(SlashMode.Forward));
2727
stringBuilder.Append("\"");
2828

2929
arguments = stringBuilder.ToString();

src/GitHub.Api/Git/Tasks/GitVersionTask.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
namespace GitHub.Unity
55
{
6-
class GitVersionTask : ProcessTask<Version>
6+
class GitVersionTask : ProcessTask<TheVersion>
77
{
88
private const string TaskName = "git --version";
99

10-
public GitVersionTask(CancellationToken token, IOutputProcessor<Version> processor = null)
10+
public GitVersionTask(CancellationToken token, IOutputProcessor<TheVersion> processor = null)
1111
: base(token, processor ?? new VersionOutputProcessor())
1212
{
1313
Name = TaskName;

0 commit comments

Comments
 (0)