Exemplo n.º 1
0
        public void GitLfsIsInstalledIfMissingWithCustomGitPath()
        {
            var tempZipExtractPath = TestBasePath.Combine("Temp", "git_zip_extract_zip_paths");
            var customGitInstall   = TestBasePath.Combine("CustomGitInstall").Combine(GitInstaller.GitInstallDetails.GitDirectory);

            var gitZipUri  = new UriString($"http://localhost:{server.Port}/unity/git/windows/git-slim.zip");
            var downloader = new Downloader(Environment.FileSystem);

            downloader.QueueDownload(gitZipUri, tempZipExtractPath);
            downloader.RunSynchronously();

            var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory();

            ZipHelper.Instance.Extract(tempZipExtractPath.Combine(gitZipUri.Filename), gitExtractPath, TaskManager.Token, null);
            var source = gitExtractPath;
            var target = customGitInstall;

            target.DeleteIfExists();
            target.EnsureParentDirectoryExists();
            source.Move(target);
            var gitExec = customGitInstall.Combine("cmd/git.exe");

            var state = new GitInstaller.GitInstallationState();

            state.GitExecutablePath          = gitExec;
            Environment.GitInstallationState = state;

            var defaultGitInstall = TestBasePath.Combine("DefaultInstall");

            var installDetails = new GitInstaller.GitInstallDetails(defaultGitInstall, DefaultEnvironment.OnWindows)
            {
                GitPackageFeed    = "http://nope",
                GitLfsPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitLfsPackageName}",
            };

            var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager.Token, installDetails: installDetails);

            state = gitInstaller.SetupGitIfNeeded();
            state.Should().NotBeNull();

            var gitLfsBasePath = defaultGitInstall.Combine(GitInstaller.GitInstallDetails.GitLfsDirectory);
            var gitLfsExec     = gitLfsBasePath.Combine("git-lfs.exe");

            state.GitInstallationPath.Should().Be(customGitInstall);
            state.GitExecutablePath.Should().Be(gitExec);
            state.GitLfsInstallationPath.Should().Be(gitLfsExec.Parent);
            state.GitLfsExecutablePath.Should().Be(gitLfsExec);
            gitLfsExec.FileExists().Should().BeTrue();

            Environment.GitInstallationState = state;

            var procTask = new SimpleProcessTask(TaskManager.Token, "something")
                           .Configure(ProcessManager);
            var pathList = procTask.Process.StartInfo.EnvironmentVariables["PATH"].ToNPathList(Environment).TakeWhile(x => x != "END");

            pathList.First().Should().Be(gitLfsExec.Parent);
            pathList.Skip(1).First().Should().Be(gitExec.Parent);
        }
Exemplo n.º 2
0
        public void GitInstallWindows()
        {
            var gitInstallationPath = TestBasePath.Combine("GitInstall").CreateDirectory();

            var installDetails = new GitInstaller.GitInstallDetails(gitInstallationPath, DefaultEnvironment.OnWindows)
            {
                GitZipMd5Url    = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitZipMd5Url).Filename}",
                GitZipUrl       = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitZipUrl).Filename}",
                GitLfsZipMd5Url = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitLfsZipMd5Url).Filename}",
                GitLfsZipUrl    = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitLfsZipUrl).Filename}",
            };

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

            var zipHelper = Substitute.For <IZipHelper>();

            zipHelper.Extract(Arg.Any <string>(), Arg.Do <string>(x =>
            {
                var n = x.ToNPath();
                n.EnsureDirectoryExists();
                if (n.FileName == "git-lfs")
                {
                    n.Combine("git-lfs" + Environment.ExecutableExtension).WriteAllText("");
                }
            }), Arg.Any <CancellationToken>(), Arg.Any <Func <long, long, bool> >()).Returns(true);
            ZipHelper.Instance = zipHelper;
            var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager, installDetails);

            TaskCompletionSource <GitInstaller.GitInstallationState> end = new TaskCompletionSource <GitInstaller.GitInstallationState>();
            var startTask = gitInstaller.SetupGitIfNeeded().Finally((_, state) => end.TrySetResult(state));

            startTask.Start();
            GitInstaller.GitInstallationState result = null;
            Assert.DoesNotThrow(async() => result = await end.Task);
            result.Should().NotBeNull();

            Assert.AreEqual(gitInstallationPath.Combine(installDetails.PackageNameWithVersion), result.GitInstallationPath);
            result.GitExecutablePath.Should().Be(gitInstallationPath.Combine(installDetails.PackageNameWithVersion, "cmd", "git" + Environment.ExecutableExtension));
            result.GitLfsExecutablePath.Should().Be(gitInstallationPath.Combine(installDetails.PackageNameWithVersion, "mingw32", "libexec", "git-core", "git-lfs" + Environment.ExecutableExtension));

            var isCustomGitExec = result.GitExecutablePath != result.GitExecutablePath;

            Environment.GitExecutablePath    = result.GitExecutablePath;
            Environment.GitLfsExecutablePath = result.GitLfsExecutablePath;

            Environment.IsCustomGitExecutable = isCustomGitExec;

            var procTask = new SimpleProcessTask(TaskManager.Token, "something")
                           .Configure(ProcessManager);

            procTask.Process.StartInfo.EnvironmentVariables["PATH"].Should().StartWith(gitInstallationPath.ToString());
        }
Exemplo n.º 3
0
        public void GitInstallWindows()
        {
            using (var test = StartTest(withHttpServer: true))
            {
                var gitInstallationPath = test.TestPath.Combine("GitInstall").CreateDirectory();

                var manifestFeed   = $"http://localhost:{test.HttpServer.Port}/git/{GitInstaller.GitInstallDetails.ManifestName}";
                var installDetails = new GitInstaller.GitInstallDetails(gitInstallationPath, test.Environment)
                {
                    GitManifestFeed = manifestFeed
                };

                test.TestPath.Combine("git").CreateDirectory();

                var gitInstaller = new GitInstaller(test.Platform, installDetails: installDetails);

                var zipHelper = Substitute.For <IZipHelper>();
                zipHelper.Extract(Arg.Any <string>(), Arg.Do <string>(x =>
                {
                    var n = x.ToSPath();
                    n.EnsureDirectoryExists();
                    if (n.FileName == "git")
                    {
                        n.Combine("git" + test.Environment.ExecutableExtension).WriteAllText("");
                    }
                }), Arg.Any <Action <string, long> >(), Arg.Any <Func <long, long, string, bool> >(), Arg.Any <Func <string, bool> >(), Arg.Any <CancellationToken>()).Returns(true);

                GitInstaller.GitInstallationState state = null;
                try
                {
                    ZipHelper.Instance = zipHelper;
                    state = gitInstaller.RunSynchronously();
                }
                finally
                {
                    ZipHelper.Instance = null;
                }

                state.Should().NotBeNull();

                Assert.AreEqual(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitDirectory), state.GitInstallationPath);
                state.GitExecutablePath.Should().Be(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitDirectory,
                                                                                "cmd", "git" + test.Environment.ExecutableExtension));

                test.Environment.GitInstallationState = state;

                var procTask = new NativeProcessTask(test.TaskManager, test.ProcessManager, test.GitProcessEnvironment, "something", null);
                procTask.Wrapper.StartInfo.EnvironmentVariables["PATH"].Should().StartWith(gitInstallationPath.ToString());
            }
        }
Exemplo n.º 4
0
        //[Test]
        public void GitInstallMac()
        {
            var filesystem = Substitute.For <IFileSystem>();

            DefaultEnvironment.OnMac     = true;
            DefaultEnvironment.OnWindows = false;

            var gitInstallationPath = TestBasePath.Combine("GitInstall").CreateDirectory();

            var installDetails = new GitInstaller.GitInstallDetails(gitInstallationPath, Environment.IsWindows)
            {
                GitZipMd5Url    = $"http://localhost:{server.Port}/{new Uri(GitInstaller.GitInstallDetails.DefaultGitZipMd5Url).AbsolutePath}",
                GitZipUrl       = $"http://localhost:{server.Port}/{new Uri(GitInstaller.GitInstallDetails.DefaultGitZipUrl).AbsolutePath}",
                GitLfsZipMd5Url = $"http://localhost:{server.Port}/{new Uri(GitInstaller.GitInstallDetails.DefaultGitLfsZipMd5Url).AbsolutePath}",
                GitLfsZipUrl    = $"http://localhost:{server.Port}/{new Uri(GitInstaller.GitInstallDetails.DefaultGitLfsZipUrl).AbsolutePath}",
            };

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

            var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager, installDetails);
            var startTask    = gitInstaller.SetupGitIfNeeded();
            var endTask      = new FuncTask <GitInstaller.GitInstallationState, GitInstaller.GitInstallationState>(TaskManager.Token, (s, state) => state);

            startTask.OnEnd += (thisTask, path, success, exception) => thisTask.GetEndOfChain().Then(endTask);
            startTask.Start();
            GitInstaller.GitInstallationState result = null;
            Assert.DoesNotThrow(async() => result = await endTask.Task);
            result.Should().NotBeNull();

            Assert.AreEqual(gitInstallationPath.Combine(installDetails.PackageNameWithVersion), result.GitInstallationPath);
            result.GitExecutablePath.Should().Be(gitInstallationPath.Combine("bin", "git" + Environment.ExecutableExtension));
            result.GitLfsExecutablePath.Should().Be(gitInstallationPath.Combine(installDetails.PackageNameWithVersion, "libexec", "git-core", "git-lfs" + Environment.ExecutableExtension));

            var isCustomGitExec = result.GitExecutablePath != result.GitExecutablePath;

            Environment.GitExecutablePath    = result.GitExecutablePath;
            Environment.GitLfsExecutablePath = result.GitLfsExecutablePath;

            Environment.IsCustomGitExecutable = isCustomGitExec;

            var procTask = new SimpleProcessTask(TaskManager.Token, "something")
                           .Configure(ProcessManager);

            procTask.Process.StartInfo.EnvironmentVariables["PATH"].Should().StartWith(gitInstallationPath.ToString());
        }