Пример #1
0
        /// <summary>
        /// Initialize environment after finding where git is. This needs to run on the main thread
        /// </summary>
        /// <param name="gitExecutablePath"></param>
        private void InitializeEnvironment(NPath gitExecutablePath)
        {
            var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
                                .ThenInUI(InitializeUI);

            Environment.GitExecutablePath = gitExecutablePath;
            Environment.User.Initialize(GitClient);

            if (Environment.IsWindows)
            {
                GitClient
                .GetConfig("credential.helper", GitConfigSource.Global)
                .Then((b, credentialHelper) => {
                    if (!string.IsNullOrEmpty(credentialHelper))
                    {
                        Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
                        afterGitSetup.Start();
                    }
                    else
                    {
                        Logger.Warning("No Windows CredentialHeloper found: Setting to wincred");

                        GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global)
                        .Then(afterGitSetup)
                        .Start();
                    }
                })
                .Start();
            }
            else
            {
                afterGitSetup.Start();
            }
        }
Пример #2
0
        public void SetupGitIfNeeded(ActionTask <NPath> onSuccess, ITask onFailure)
        {
            Logger.Trace("SetupGitIfNeeded");

            if (!environment.IsWindows)
            {
                onFailure.Start();
                return;
            }

            new ActionTask(cancellationToken, () => {
                if (IsGitExtracted())
                {
                    Logger.Trace("SetupGitIfNeeded: Skipped");
                    onSuccess.PreviousResult = installDetails.GitExecutablePath;
                    onSuccess.Start();
                }
                else
                {
                    ExtractPortableGit(onSuccess, onFailure);
                }
            }).Start();
        }
Пример #3
0
        public void Run(bool firstRun)
        {
            Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
            isBusy = true;

            var endTask = new ActionTask <GitInstaller.GitInstallationState>(CancellationToken,
                                                                             (_, state) => InitializeEnvironment(state))
            {
                Affinity = TaskAffinity.UI
            };

            ITask <string> setExistingEnvironmentPath;

            if (Environment.IsMac)
            {
                setExistingEnvironmentPath = new SimpleProcessTask(CancellationToken, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
                                             .Configure(ProcessManager, dontSetupGit: true)
                                             .Catch(e => true) // make sure this doesn't throw if the task fails
                                             .Then((success, path) => success ? path?.Split(new[] { "\"" }, StringSplitOptions.None)[1] : null);
            }
            else
            {
                setExistingEnvironmentPath = new FuncTask <string>(CancellationToken, () => null);
            }

            setExistingEnvironmentPath.OnEnd += (t, path, success, ex) =>
            {
                if (path != null)
                {
                    Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path);
                    Environment.Path = path;
                }
            };

            var setupOctorun          = new OctorunInstaller(Environment, TaskManager).SetupOctorunIfNeeded();
            var setOctorunEnvironment = new ActionTask <NPath>(CancellationToken,
                                                               (s, octorunPath) => Environment.OctorunScriptPath = octorunPath);

            var getGitFromSettings = new FuncTask <NPath>(CancellationToken, () =>
            {
                var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
                if (gitExecutablePath.HasValue && gitExecutablePath.Value.FileExists()) // we have a git path
                {
                    Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
                    return(gitExecutablePath.Value);
                }
                return(NPath.Default);
            });

            getGitFromSettings.OnEnd += (t, path, _, __) =>
            {
                if (path.IsInitialized)
                {
                    var state = new GitInstaller.GitInstallationState {
                        GitExecutablePath = path,
                        GitIsValid        = true
                    };
                    endTask.PreviousResult = state;
                    endTask.Start();
                    return;
                }
                Logger.Trace("Using portable git");

                var setupGit = new GitInstaller(Environment, ProcessManager, TaskManager).SetupGitIfNeeded();
                t.Then(setupGit);
                setupGit.Finally((s, state) =>
                {
                    endTask.PreviousResult = state;
                    endTask.Start();
                });
                setupGit.Progress(progressReporter.UpdateProgress);
                // append installer task to top chain
            };

            var setupChain = setExistingEnvironmentPath.Then(setupOctorun);

            setupChain.OnEnd += (t, path, _, __) =>
            {
                t.GetEndOfChain().Then(setOctorunEnvironment).Then(getGitFromSettings);
            };

            setupChain.Start();
        }