private static bool SetGitCredential(ITeamExplorerUtils teamExplorer)
 {
     if (CredentialsStore.Default.CurrentAccount != null)
     {
         if (!CsrGitUtils.StoreCredential(
                 CsrGitUtils.CsrUrlAuthority,
                 CredentialsStore.Default.CurrentAccount.RefreshToken,
                 CsrGitUtils.StoreCredentialPathOption.UrlHost))
         {
             teamExplorer.ShowError(Resources.GitInitilizationFailedMessage);
             return(s_gitInited = false);
         }
     }
     return(true);
 }
Exemplo n.º 2
0
        private async Task CloneAsync()
        {
            if (IsDefaultLocation(LocalPath) && !Directory.Exists(s_defaultLocalPath))
            {
                Directory.CreateDirectory(s_defaultLocalPath);
            }

            // If OkCommand is enabled, SelectedRepository and LocalPath is valid
            string destPath = Path.Combine(LocalPath, SelectedRepository.GetRepoName());

            if (!CsrGitUtils.StoreCredential(
                    SelectedRepository.Url,
                    CredentialsStore.Default.CurrentAccount.RefreshToken,
                    CsrGitUtils.StoreCredentialPathOption.UrlPath))
            {
                UserPromptUtils.Default.ErrorPrompt(
                    message: Resources.CsrCloneFailedToSetCredentialMessage,
                    title: Resources.UiDefaultPromptTitle);
                return;
            }

            try
            {
                var           watch     = Stopwatch.StartNew();
                GitRepository localRepo = await CsrGitUtils.CloneAsync(SelectedRepository.Url, destPath);

                Result = new CloneDialogResult
                {
                    RepoItem        = new RepoItemViewModel(SelectedRepository, localRepo.Root),
                    JustCreatedRepo = _newReposList.Contains(SelectedRepository.Name)
                };
                _closeOwnerFunc();
                EventsReporterWrapper.ReportEvent(
                    CsrClonedEvent.Create(CommandStatus.Success, watch.Elapsed));
            }
            catch (GitCommandException)
            {
                UserPromptUtils.Default.ErrorPrompt(
                    message: Resources.CsrCloneFailedMessage,
                    title: Resources.UiDefaultPromptTitle);
                EventsReporterWrapper.ReportEvent(CsrClonedEvent.Create(CommandStatus.Failure));
                return;
            }
        }