Example #1
0
 public GitInstallationState(GitInstallDetails defaults)
 {
     GitInstallationPath    = defaults.GitInstallationPath;
     GitExecutablePath      = defaults.GitExecutablePath;
     GitLfsInstallationPath = defaults.GitInstallationPath;
     GitLfsExecutablePath   = defaults.GitLfsExecutablePath;
 }
Example #2
0
 public GitInstaller(IPlatform platform,
                     GitInstallationState state       = null,
                     GitInstallDetails installDetails = null,
                     CancellationToken token          = default)
     : base(platform.TaskManager, token)
 {
     this.platform                = platform;
     this.currentState            = state;
     this.sharpZipLibHelper       = ZipHelper.Instance;
     this.cancellationToken       = token;
     this.installDetails          = installDetails ?? new GitInstallDetails(platform.Environment.UserCachePath, platform.Environment);
     progressReporter.OnProgress += progress.UpdateProgress;
 }
Example #3
0
 public GitInstaller(IGitEnvironment environment, IProcessManager processManager,
                     CancellationToken token,
                     GitInstallationState state       = null,
                     GitInstallDetails installDetails = null)
     : base(token)
 {
     this.environment             = environment;
     this.processManager          = processManager;
     this.state                   = state;
     this.sharpZipLibHelper       = ZipHelper.Instance;
     this.installDetails          = installDetails ?? new GitInstallDetails(environment.UserCachePath, environment);
     progressReporter.OnProgress += progress.UpdateProgress;
 }
        protected void InitializePlatform(NPath repoPath, NPath?environmentPath, bool enableEnvironmentTrace, bool setupGit = true)
        {
            InitializeTaskManager();
            InitializeEnvironment(repoPath, environmentPath, enableEnvironmentTrace);

            Platform       = new Platform(Environment);
            ProcessManager = new ProcessManager(Environment, GitEnvironment, TaskManager.Token);

            Platform.Initialize(ProcessManager, TaskManager);

            if (setupGit)
            {
                var autoResetEvent = new AutoResetEvent(false);

                var applicationDataPath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath();
                var installDetails      = new GitInstallDetails(applicationDataPath, true);

                var zipArchivesPath   = TestBasePath.Combine("ZipArchives").CreateDirectory();
                var gitArchivePath    = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", zipArchivesPath, Environment);
                var gitLfsArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", zipArchivesPath, Environment);

                var gitInstaller = new GitInstaller(Environment, TaskManager.Token, installDetails, gitArchivePath, gitLfsArchivePath);

                NPath?    result = null;
                Exception ex     = null;

                gitInstaller.SetupGitIfNeeded(new ActionTask <NPath>(TaskManager.Token, (b, path) => {
                    result = path;
                    autoResetEvent.Set();
                }),
                                              new ActionTask(TaskManager.Token, (b, exception) => {
                    ex = exception;
                    autoResetEvent.Set();
                }));

                autoResetEvent.WaitOne();

                if (result == null)
                {
                    if (ex != null)
                    {
                        throw ex;
                    }

                    throw new Exception("Did not install git");
                }

                Environment.GitExecutablePath = result.Value;
                GitClient = new GitClient(Environment, ProcessManager, TaskManager.Token);
            }
        }
Example #5
0
        public void GitInstallTest()
        {
            var gitInstallationPath = TestBasePath.Combine("GitInstall").CreateDirectory();

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

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

            //var gitArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", zipArchivesPath, Environment);
            //var gitLfsArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", zipArchivesPath, Environment);

            var gitInstaller = new GitInstaller(Environment, CancellationToken.None, installDetails);

            var autoResetEvent = new AutoResetEvent(false);

            bool?     result     = null;
            NPath     resultPath = null;
            Exception ex         = null;

            gitInstaller.SetupGitIfNeeded(new ActionTask <NPath>(CancellationToken.None, (b, path) => {
                result     = true;
                resultPath = path;
                autoResetEvent.Set();
            }),
                                          new ActionTask(CancellationToken.None, (b, exception) => {
                result = false;
                ex     = exception;
                autoResetEvent.Set();
            }));

            autoResetEvent.WaitOne();

            result.HasValue.Should().BeTrue();
            result.Value.Should().BeTrue();
            resultPath.Should().NotBeNull();
            ex.Should().BeNull();
        }