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

Commit 80cc01a

Browse files
committed
Merge shana/fix-fix-fix into releases/0.30
2 parents 8b3af31 + f71f68a commit 80cc01a

File tree

9 files changed

+53
-63
lines changed

9 files changed

+53
-63
lines changed

src/GitHub.Api/Application/ApplicationInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace GitHub.Unity
44
static partial class ApplicationInfo
55
{
66
#if DEBUG
7-
public const string ApplicationName = "GitHubUnityDebug";
7+
public const string ApplicationName = "GitHub for Unity Debug";
88
public const string ApplicationProvider = "GitHub";
99
#else
1010
public const string ApplicationName = "GitHubUnity";

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,15 @@ public void Run(bool firstRun)
8484
if (path.IsInitialized)
8585
return;
8686

87-
Logger.Trace("No git path found in settings");
87+
Logger.Trace("Using portable git");
8888

89-
var gitInstaller = new GitInstaller(Environment, CancellationToken);
89+
var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager);
9090

91-
// if successful, continue with environment initialization, otherwise try to find an existing git installation
9291
var task = gitInstaller.SetupGitIfNeeded();
9392
task.Progress(progressReporter.UpdateProgress);
9493
task.OnEnd += (thisTask, result, success, exception) =>
9594
{
96-
thisTask.Then(initEnvironmentTask, taskIsTopOfChain: true);
95+
thisTask.GetEndOfChain().Then(initEnvironmentTask, taskIsTopOfChain: true);
9796
};
9897

9998
// append installer task to top chain

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,62 @@ class GitInstaller
1010
private readonly CancellationToken cancellationToken;
1111

1212
private readonly IEnvironment environment;
13+
private readonly IProcessManager processManager;
1314
private readonly GitInstallDetails installDetails;
1415
private readonly IZipHelper sharpZipLibHelper;
1516

1617
GitInstallationState installationState;
1718
ITask<NPath> installationTask;
1819

19-
public GitInstaller(IEnvironment environment, CancellationToken cancellationToken,
20+
public GitInstaller(IEnvironment environment, IProcessManager processManager,
21+
ITaskManager taskManager,
2022
GitInstallDetails installDetails = null)
2123
{
2224
this.environment = environment;
25+
this.processManager = processManager;
2326
this.sharpZipLibHelper = ZipHelper.Instance;
24-
this.cancellationToken = cancellationToken;
27+
this.cancellationToken = taskManager.Token;
2528
this.installDetails = installDetails ?? new GitInstallDetails(environment.UserCachePath, environment.IsWindows);
2629
}
2730

2831
public ITask<NPath> SetupGitIfNeeded()
2932
{
3033
//Logger.Trace("SetupGitIfNeeded");
3134

32-
installationTask = new FuncTask<NPath>(cancellationToken, (_) => installDetails.GitExecutablePath)
35+
installationTask = new FuncTask<NPath, NPath>(cancellationToken, (success, path) =>
36+
{
37+
return path;
38+
})
3339
{ Name = "Git Installation - Complete" };
3440
installationTask.OnStart += thisTask => thisTask.UpdateProgress(0, 100);
3541
installationTask.OnEnd += (thisTask, result, success, exception) => thisTask.UpdateProgress(100, 100);
3642

43+
ITask<NPath> startTask = null;
3744
if (!environment.IsWindows)
3845
{
39-
return new FindExecTask("git", cancellationToken)
40-
.Then(installationTask, taskIsTopOfChain: true);
41-
}
42-
43-
var startTask = new FuncTask<NPath>(cancellationToken, () =>
46+
startTask = new FindExecTask("git", cancellationToken)
47+
.Configure(processManager);
48+
// we should doublecheck that system git is usable here
49+
installationState = new GitInstallationState
4450
{
45-
installationState = VerifyGitInstallation();
46-
if (!installationState.GitIsValid && !installationState.GitLfsIsValid)
47-
installationState = GrabZipFromResources(installationState);
48-
else
49-
Logger.Trace("SetupGitIfNeeded: Skipped");
50-
return installDetails.GitExecutablePath;
51-
})
51+
GitIsValid = true,
52+
GitLfsIsValid = true
53+
};
54+
}
55+
else
56+
{
57+
startTask = new FuncTask<NPath>(cancellationToken, () =>
58+
{
59+
installationState = VerifyGitInstallation();
60+
if (!installationState.GitIsValid && !installationState.GitLfsIsValid)
61+
installationState = GrabZipFromResources(installationState);
62+
else
63+
Logger.Trace("SetupGitIfNeeded: Skipped");
64+
return installDetails.GitExecutablePath;
65+
})
5266
{ Name = "Git Installation - Extract" };
5367

68+
}
5469

5570
startTask.OnEnd += (thisTask, path, success, exception) =>
5671
{

src/GitHub.Api/Installer/UnzipTask.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class UnzipTask : TaskBase<NPath>
99
private readonly NPath extractedPath;
1010
private readonly IZipHelper zipHelper;
1111
private readonly IFileSystem fileSystem;
12-
private readonly string expectedMD5;
1312

1413
public UnzipTask(CancellationToken token, NPath archiveFilePath, NPath extractedPath,
1514
IZipHelper zipHelper, IFileSystem fileSystem)

src/tests/IntegrationTests/BaseIntegrationTest.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,22 @@ protected void SetupGit(NPath pathToSetupGitInto, string testName)
152152
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", zipArchivesPath, Environment);
153153
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip.md5", zipArchivesPath, Environment);
154154

155-
var gitInstaller = new GitInstaller(Environment, TaskManager.Token, installDetails);
155+
var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager, installDetails);
156156

157157
NPath? result = null;
158158
Exception ex = null;
159159

160160
var setupTask = gitInstaller.SetupGitIfNeeded();
161-
setupTask.OnEnd += (thisTask, path, success, exception) => {
162-
result = path;
163-
ex = exception;
164-
autoResetEvent.Set();
161+
setupTask.OnEnd += (thisTask, _, __, ___) => {
162+
((ITask<NPath>)thisTask.GetEndOfChain()).OnEnd += (t, path, success, exception) =>
163+
{
164+
result = path;
165+
ex = exception;
166+
autoResetEvent.Set();
167+
};
165168
};
166-
167-
if (!autoResetEvent.WaitOne(TimeSpan.FromMinutes(1)))
169+
setupTask.Start();
170+
if (!autoResetEvent.WaitOne(TimeSpan.FromMinutes(5)))
168171
throw new TimeoutException($"Test setup unzipping {zipArchivesPath} to {pathToSetupGitInto} timed out");
169172

170173
if (result == null)
@@ -197,7 +200,7 @@ public virtual void TestFixtureTearDown()
197200
[SetUp]
198201
public virtual void OnSetup()
199202
{
200-
TestBasePath = NPath.CreateTempDirectory("integration-tests");
203+
TestBasePath = NPath.CreateTempDirectory("integration tests");
201204
NPath.FileSystem.SetCurrentDirectory(TestBasePath);
202205
TestRepoMasterCleanUnsynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_unsync");
203206
TestRepoMasterCleanUnsynchronizedRussianLanguage = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_sync_with_russian_language");

src/tests/IntegrationTests/Installer/GitInstallerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public void GitInstallTest()
4949

5050
TestBasePath.Combine("git").CreateDirectory();
5151

52-
var gitInstaller = new GitInstaller(Environment, CancellationToken.None, installDetails);
52+
var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager, installDetails);
5353
var startTask = gitInstaller.SetupGitIfNeeded();
54-
var endTask = new FuncTask<NPath, NPath>(CancellationToken.None, (s, path) => path);
54+
var endTask = new FuncTask<NPath, NPath>(TaskManager.Token, (s, path) => path);
5555
startTask.OnEnd += (thisTask, path, success, exception) => thisTask.GetEndOfChain().Then(endTask);
5656
startTask.Start();
5757
NPath? resultPath = null;

src/tests/IntegrationTests/IntegrationTestEnvironment.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class IntegrationTestEnvironment : IEnvironment
1212
private static readonly ILogging logger = LogHelper.GetLogger<IntegrationTestEnvironment>();
1313
private readonly bool enableTrace;
1414

15-
private readonly NPath integrationTestEnvironmentPath;
16-
1715
private DefaultEnvironment defaultEnvironment;
1816

1917
public IntegrationTestEnvironment(ICacheContainer cacheContainer,
@@ -26,13 +24,10 @@ public IntegrationTestEnvironment(ICacheContainer cacheContainer,
2624
defaultEnvironment = new DefaultEnvironment(cacheContainer);
2725
defaultEnvironment.FileSystem.SetCurrentDirectory(repoPath);
2826
environmentPath = environmentPath ??
29-
defaultEnvironment.GetSpecialFolder(Environment.SpecialFolder.LocalApplicationData)
30-
.ToNPath()
31-
.EnsureDirectoryExists(ApplicationInfo.ApplicationName + "-IntegrationTests");
27+
defaultEnvironment.UserCachePath.EnsureDirectoryExists("IntegrationTests");
3228

33-
integrationTestEnvironmentPath = environmentPath.Value;
34-
UserCachePath = integrationTestEnvironmentPath.Combine("User");
35-
SystemCachePath = integrationTestEnvironmentPath.Combine("System");
29+
UserCachePath = environmentPath.Value.Combine("User");
30+
SystemCachePath = environmentPath.Value.Combine("System");
3631

3732
var installPath = solutionDirectory.Parent.Parent.Combine("src", "GitHub.Api");
3833

@@ -76,7 +71,7 @@ public string GetEnvironmentVariable(string v)
7671

7772
public string GetSpecialFolder(Environment.SpecialFolder folder)
7873
{
79-
var ensureDirectoryExists = integrationTestEnvironmentPath.EnsureDirectoryExists(folder.ToString());
74+
var ensureDirectoryExists = UserCachePath.Parent.EnsureDirectoryExists(folder.ToString());
8075
var specialFolderPath = ensureDirectoryExists.ToString();
8176

8277
if (enableTrace)
@@ -87,7 +82,7 @@ public string GetSpecialFolder(Environment.SpecialFolder folder)
8782
return specialFolderPath;
8883
}
8984

90-
public string UserProfilePath => integrationTestEnvironmentPath.CreateDirectory("user-profile-path");
85+
public string UserProfilePath => UserCachePath.Parent.CreateDirectory("user profile path");
9186

9287
public NPath Path => Environment.GetEnvironmentVariable("PATH").ToNPath();
9388
public string NewLine => Environment.NewLine;

src/tests/IntegrationTests/UnzipTaskTests.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,5 @@ public async Task UnzipWorks()
3636

3737
extractedPath.DirectoryExists().Should().BeTrue();
3838
}
39-
40-
[Test]
41-
public void FailsWhenMD5Incorrect()
42-
{
43-
InitializeTaskManager();
44-
45-
var cacheContainer = Substitute.For<ICacheContainer>();
46-
Environment = new IntegrationTestEnvironment(cacheContainer, TestBasePath, SolutionDirectory);
47-
48-
var destinationPath = TestBasePath.Combine("gitlfs_zip").CreateDirectory();
49-
var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", destinationPath, Environment);
50-
51-
var extractedPath = TestBasePath.Combine("gitlfs_zip_extracted").CreateDirectory();
52-
53-
var unzipTask = new UnzipTask(CancellationToken.None, archiveFilePath, extractedPath,
54-
ZipHelper.Instance, Environment.FileSystem);
55-
56-
Assert.Throws<UnzipException>(async () => await unzipTask.StartAwait());
57-
58-
extractedPath.DirectoryExists().Should().BeFalse();
59-
}
6039
}
6140
}

src/tests/TaskSystemIntegrationTests/Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void OneTimeSetup()
4343
TaskManager.UIScheduler = new SynchronizationContextTaskScheduler(syncContext);
4444

4545
var env = new DefaultEnvironment();
46-
TestBasePath = NPath.CreateTempDirectory("integration-tests");
46+
TestBasePath = NPath.CreateTempDirectory("integration tests");
4747
env.FileSystem.SetCurrentDirectory(TestBasePath);
4848

4949
var repo = Substitute.For<IRepository>();

0 commit comments

Comments
 (0)