Пример #1
0
 private void MaybeUpdateData()
 {
     if (refresh)
     {
         installationState = Environment.GitInstallationState;
         gitPath           = installationState.GitExecutablePath;
         gitLfsPath        = installationState.GitLfsExecutablePath;
         installDetails    = new GitInstaller.GitInstallDetails(Environment.UserCachePath, Environment);
         refresh           = false;
     }
 }
        public void SetupGit(GitInstaller.GitInstallationState state)
        {
            if (!state.GitIsValid || !state.GitLfsIsValid)
            {
                if (!state.GitExecutablePath.IsInitialized)
                {
                    Logger.Warning(Localization.GitNotFound);
                }
                else if (!state.GitLfsExecutablePath.IsInitialized)
                {
                    Logger.Warning(Localization.GitLFSNotFound);
                }
                else if (state.GitVersion < Constants.MinimumGitVersion)
                {
                    Logger.Warning(String.Format(Localization.GitVersionTooLow, state.GitExecutablePath, state.GitVersion, Constants.MinimumGitVersion));
                }
                else if (state.GitLfsVersion < Constants.MinimumGitLfsVersion)
                {
                    Logger.Warning(String.Format(Localization.GitLfsVersionTooLow, state.GitLfsExecutablePath, state.GitLfsVersion, Constants.MinimumGitLfsVersion));
                }
                return;
            }

            Environment.GitInstallationState = state;
            Environment.User.Initialize(GitClient);

            if (firstRun)
            {
                if (Environment.RepositoryPath.IsInitialized)
                {
                    UpdateMergeSettings();

                    GitClient.LfsInstall()
                    .Catch(e =>
                    {
                        Logger.Error(e, "Error running lfs install");
                        return(true);
                    })
                    .RunSynchronously();
                }

                if (Environment.IsWindows)
                {
                    var credentialHelper = GitClient.GetConfig("credential.helper", GitConfigSource.Global)
                                           .Catch(e =>
                    {
                        Logger.Error(e, "Error getting the credential helper");
                        return(true);
                    }).RunSynchronously();

                    if (string.IsNullOrEmpty(credentialHelper))
                    {
                        Logger.Warning("No Windows CredentialHelper found: Setting to wincred");
                        GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global)
                        .Catch(e =>
                        {
                            Logger.Error(e, "Error setting the credential helper");
                            return(true);
                        })
                        .RunSynchronously();
                    }
                }
            }
        }
Пример #3
0
        private void ValidateAndSetGitInstallPath()
        {
            if (resetToBundled)
            {
                TaskManager.With(() => {
                    var state        = Environment.GitDefaultInstallation.GetDefaults();
                    var gitInstaller = new GitInstaller(Platform, state);
                    state            = gitInstaller.RunSynchronously();
                    if (state.GitIsValid && state.GitLfsIsValid)
                    {
                        Manager.SetupGit(state);
                        Manager.RestartRepository();
                    }
                    return(state);
                }, "Setting up git... ")
                .FinallyInUI((success, exception, state) =>
                {
                    if (!success)
                    {
                        Logger.Error(exception, ErrorInstallingInternalGit);
                        errorMessage = ErrorValidatingGitPath;
                    }
                    else
                    {
                        refresh = true;
                    }
                    isBusy           = false;
                    resetToBundled   = false;
                    resetToSystem    = false;
                    changingManually = false;
                    Redraw();
                }).Start();
            }
            else
            {
                var newState = new GitInstaller.GitInstallationState();
                newState.GitExecutablePath    = gitPath.ToSPath();
                newState.GitLfsExecutablePath = gitLfsPath.ToSPath();
                var installer = new GitInstaller(Platform, newState);
                installer.Progress(UpdateProgress);

                TaskManager.With(() =>
                {
                    return(installer.RunSynchronously());
                })
                .Then(state =>
                {
                    if (state.GitIsValid && state.GitLfsIsValid)
                    {
                        Manager.SetupGit(state);
                        Manager.RestartRepository();
                    }
                    return(state);
                })
                .FinallyInUI((success, ex, state) =>
                {
                    if (!success)
                    {
                        Logger.Error(ex, ErrorValidatingGitPath);
                        return;
                    }

                    if (!state.GitIsValid || !state.GitLfsIsValid)
                    {
                        var errorMessageStringBuilder = new StringBuilder();
                        Logger.Warning(
                            "Software versions do not meet minimums Git:{0} (Minimum:{1}) GitLfs:{2} (Minimum:{3})",
                            state.GitVersion, Constants.MinimumGitVersion, state.GitLfsVersion,
                            Constants.MinimumGitLfsVersion);

                        if (state.GitVersion == TheVersion.Default)
                        {
                            errorMessageStringBuilder.Append(ErrorGitNotFoundMessage);
                        }
                        else if (state.GitLfsVersion == TheVersion.Default)
                        {
                            errorMessageStringBuilder.Append(ErrorGitLfsNotFoundMessage);
                        }
                        else
                        {
                            if (state.GitVersion < Constants.MinimumGitVersion)
                            {
                                errorMessageStringBuilder.AppendFormat(ErrorMinimumGitVersionMessageFormat,
                                                                       state.GitVersion, Constants.MinimumGitVersion);
                            }

                            if (state.GitLfsVersion < Constants.MinimumGitLfsVersion)
                            {
                                if (errorMessageStringBuilder.Length > 0)
                                {
                                    errorMessageStringBuilder.Append(Environment.NewLine);
                                }

                                errorMessageStringBuilder.AppendFormat(ErrorMinimumGitLfsVersionMessageFormat,
                                                                       state.GitLfsVersion, Constants.MinimumGitLfsVersion);
                            }
                        }

                        errorMessage = errorMessageStringBuilder.ToString();
                    }
                    else
                    {
                        Logger.Trace("Software versions meet minimums Git:{0} GitLfs:{1}",
                                     state.GitVersion,
                                     state.GitLfsVersion);

                        refresh = true;
                    }
                    isBusy           = false;
                    resetToBundled   = false;
                    resetToSystem    = false;
                    changingManually = false;
                    Redraw();
                }).Start();
            }
        }