コード例 #1
0
        async Task RepoChanged(ILocalRepositoryModel repository)
        {
            try
            {
                await ThreadingHelper.SwitchToMainThreadAsync();
                await EnsureLoggedIn(repository);

                if (repository != this.repository)
                {
                    this.repository = repository;
                    CurrentSession  = null;
                    sessions.Clear();
                }

                if (string.IsNullOrWhiteSpace(repository?.CloneUrl))
                {
                    return;
                }

                var modelService = hosts.LookupHost(HostAddress.Create(repository.CloneUrl))?.ModelService;
                var session      = CurrentSession;

                if (modelService != null)
                {
                    var pr = await service.GetPullRequestForCurrentBranch(repository).FirstOrDefaultAsync();

                    if (pr?.Item1 != (CurrentSession?.PullRequest.Base.RepositoryCloneUrl.Owner) &&
                        pr?.Item2 != (CurrentSession?.PullRequest.Number))
                    {
                        var pullRequest = await GetPullRequestForTip(modelService, repository);

                        if (pullRequest != null)
                        {
                            var newSession = await GetSessionInternal(pullRequest);

                            if (newSession != null)
                            {
                                newSession.IsCheckedOut = true;
                            }
                            session = newSession;
                        }
                    }
                }
                else
                {
                    session = null;
                }

                CurrentSession = session;
            }
            catch
            {
                // TODO: Log
            }
        }
コード例 #2
0
        async Task RepoChanged(ILocalRepositoryModel localRepositoryModel)
        {
            try
            {
                await ThreadingHelper.SwitchToMainThreadAsync();

                if (localRepositoryModel != repository)
                {
                    repository     = localRepositoryModel;
                    CurrentSession = null;
                    sessions.Clear();
                }

                if (string.IsNullOrWhiteSpace(localRepositoryModel?.CloneUrl))
                {
                    return;
                }

                var modelService = await connectionManager.GetModelService(repository, modelServiceFactory);

                var session = CurrentSession;

                if (modelService != null)
                {
                    var pr = await service.GetPullRequestForCurrentBranch(localRepositoryModel).FirstOrDefaultAsync();

                    if (pr?.Item1 != (CurrentSession?.PullRequest.Base.RepositoryCloneUrl.Owner) &&
                        pr?.Item2 != (CurrentSession?.PullRequest.Number))
                    {
                        var pullRequest = await GetPullRequestForTip(modelService, localRepositoryModel);

                        if (pullRequest != null)
                        {
                            var newSession = await GetSessionInternal(pullRequest);

                            if (newSession != null)
                            {
                                newSession.IsCheckedOut = true;
                            }
                            session = newSession;
                        }
                    }
                }
                else
                {
                    session = null;
                }

                CurrentSession = session;
            }
            catch (Exception e)
            {
                log.Error(e, "Error changing repository");
            }
        }
コード例 #3
0
        async Task StatusChanged()
        {
            var session = CurrentSession;

            var pr = await service.GetPullRequestForCurrentBranch(repository).FirstOrDefaultAsync();

            if (pr != null)
            {
                var changePR =
                    pr.Item1 != (session?.PullRequest.BaseRepositoryOwner) ||
                    pr.Item2 != (session?.PullRequest.Number);

                if (changePR)
                {
                    var newSession = await GetSessionInternal(pr.Item1, repository.Name, pr.Item2);

                    if (newSession != null)
                    {
                        newSession.IsCheckedOut = true;
                    }
                    session = newSession;
                }
            }
            else
            {
                session = null;
            }

            CurrentSession = session;
            initialized.TrySetResult(null);
        }
コード例 #4
0
        async Task RepoChanged(ILocalRepositoryModel repository)
        {
            try
            {
                await EnsureLoggedIn(repository);

                if (repository != this.repository)
                {
                    this.repository = repository;
                    CurrentSession  = null;
                    sessions.Clear();
                }

                var modelService = hosts.LookupHost(HostAddress.Create(repository.CloneUrl))?.ModelService;
                var session      = CurrentSession;

                if (modelService != null)
                {
                    var number = await service.GetPullRequestForCurrentBranch(repository).FirstOrDefaultAsync();

                    if (number != (CurrentSession?.PullRequest.Number ?? 0))
                    {
                        var pullRequest = await GetPullRequestForTip(modelService, repository);

                        if (pullRequest != null)
                        {
                            var newSession = await GetSessionInternal(pullRequest);;
                            if (newSession != null)
                            {
                                newSession.IsCheckedOut = true;
                            }
                            session = newSession;
                        }
                    }
                }
                else
                {
                    session = null;
                }

                CurrentSession = session;
            }
            catch
            {
                // TODO: Log
            }
        }
コード例 #5
0
        async Task StatusChanged()
        {
            try
            {
                var session = CurrentSession;

                var pr = await service.GetPullRequestForCurrentBranch(repository).FirstOrDefaultAsync();

                if (pr != null)
                {
                    var changePR =
                        pr.Item1 != (session?.PullRequest.Base.RepositoryCloneUrl.Owner) ||
                        pr.Item2 != (session?.PullRequest.Number);

                    if (changePR)
                    {
                        var modelService = await connectionManager.GetModelService(repository, modelServiceFactory);

                        var pullRequest = await modelService?.GetPullRequest(pr.Item1, repository.Name, pr.Item2);

                        if (pullRequest != null)
                        {
                            var newSession = await GetSessionInternal(pullRequest);

                            if (newSession != null)
                            {
                                newSession.IsCheckedOut = true;
                            }
                            session = newSession;
                        }
                    }
                }
                else
                {
                    session = null;
                }

                CurrentSession = session;
                initialized.TrySetResult(null);
            }
            catch (Exception e)
            {
                log.Error(e, "Error changing repository");
            }
        }
コード例 #6
0
        async void Refresh()
        {
            try
            {
                var repo            = gitExt.ActiveRepositories?.FirstOrDefault();
                var newSolutionPath = dte.Solution?.FullName;

                if (repo == null && newSolutionPath == solutionPath)
                {
                    // Ignore when ActiveRepositories is empty and solution hasn't changed.
                    // https://github.com/github/VisualStudio/issues/1421
                    log.Debug("Ignoring no ActiveRepository when solution hasn't changed");
                }
                else
                {
                    var newRepositoryPath = repo?.LocalPath;
                    var newCloneUrl       = repo?.CloneUrl;
                    var newBranchName     = repo?.CurrentBranch?.Name;
                    var newHeadSha        = repo?.CurrentBranch?.Sha;
                    var newTrackedSha     = repo?.CurrentBranch?.TrackedSha;
                    var newPullRequest    = repo != null ? await pullRequestService.GetPullRequestForCurrentBranch(repo) : null;

                    if (newRepositoryPath != repositoryPath)
                    {
                        log.Debug("ActiveRepository changed to {CloneUrl} @ {Path}", repo?.CloneUrl, newRepositoryPath);
                        ActiveRepository = repo;
                    }
                    else if (newCloneUrl != cloneUrl)
                    {
                        log.Debug("ActiveRepository changed to {CloneUrl} @ {Path}", repo?.CloneUrl, newRepositoryPath);
                        ActiveRepository = repo;
                    }
                    else if (newBranchName != branchName)
                    {
                        log.Debug("Fire StatusChanged event when BranchName changes for ActiveRepository");
                        StatusChanged?.Invoke(this, EventArgs.Empty);
                    }
                    else if (newHeadSha != headSha)
                    {
                        log.Debug("Fire StatusChanged event when HeadSha changes for ActiveRepository");
                        StatusChanged?.Invoke(this, EventArgs.Empty);
                    }
                    else if (newTrackedSha != trackedSha)
                    {
                        log.Debug("Fire StatusChanged event when TrackedSha changes for ActiveRepository");
                        StatusChanged?.Invoke(this, EventArgs.Empty);
                    }
                    else if (newPullRequest != pullRequest)
                    {
                        log.Debug("Fire StatusChanged event when PullRequest changes for ActiveRepository");
                        StatusChanged?.Invoke(this, EventArgs.Empty);
                    }

                    repositoryPath = newRepositoryPath;
                    cloneUrl       = newCloneUrl;
                    branchName     = newBranchName;
                    headSha        = newHeadSha;
                    solutionPath   = newSolutionPath;
                    trackedSha     = newTrackedSha;
                    pullRequest    = newPullRequest;
                }
            }
            catch (Exception e)
            {
                log.Error(e, "Refreshing active repository");
            }
        }