Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 47430fd

Browse files
committed
Add workaround for out of date CurrentBranch issue
It appears VSGitExt.ActiveRepositoriesChanged is fired before the local repository has actually changed its branch. This means we can't read the branch information immediately!
1 parent 473fa48 commit 47430fd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/GitHub.App/ViewModels/GitHubPane/PullRequestDetailViewModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public sealed class PullRequestDetailViewModel : PanePageViewModelBase, IPullReq
3939
readonly ITeamExplorerContext teamExplorerContext;
4040
readonly ISyncSubmodulesCommand syncSubmodulesCommand;
4141
readonly IViewViewModelFactory viewViewModelFactory;
42+
readonly IGitService gitService;
4243
IModelService modelService;
4344
PullRequestDetailModel model;
4445
IActorViewModel author;
@@ -77,7 +78,8 @@ public PullRequestDetailViewModel(
7778
ITeamExplorerContext teamExplorerContext,
7879
IPullRequestFilesViewModel files,
7980
ISyncSubmodulesCommand syncSubmodulesCommand,
80-
IViewViewModelFactory viewViewModelFactory)
81+
IViewViewModelFactory viewViewModelFactory,
82+
IGitService gitService)
8183
{
8284
Guard.ArgumentNotNull(pullRequestsService, nameof(pullRequestsService));
8385
Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
@@ -86,6 +88,7 @@ public PullRequestDetailViewModel(
8688
Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext));
8789
Guard.ArgumentNotNull(syncSubmodulesCommand, nameof(syncSubmodulesCommand));
8890
Guard.ArgumentNotNull(viewViewModelFactory, nameof(viewViewModelFactory));
91+
Guard.ArgumentNotNull(gitService, nameof(gitService));
8992

9093
this.pullRequestsService = pullRequestsService;
9194
this.sessionManager = sessionManager;
@@ -94,6 +97,7 @@ public PullRequestDetailViewModel(
9497
this.teamExplorerContext = teamExplorerContext;
9598
this.syncSubmodulesCommand = syncSubmodulesCommand;
9699
this.viewViewModelFactory = viewViewModelFactory;
100+
this.gitService = gitService;
97101
Files = files;
98102

99103
Checkout = ReactiveCommand.CreateFromObservable(
@@ -401,6 +405,8 @@ public async Task Load(PullRequestDetailModel pullRequest)
401405

402406
var localBranches = await pullRequestsService.GetLocalBranches(LocalRepository, pullRequest).ToList();
403407

408+
// HACK: This is only necessary because the CurrentBranch is being read too early
409+
gitService.Refresh(LocalRepository);
404410
IsCheckedOut = localBranches.Contains(LocalRepository.CurrentBranch);
405411

406412
if (IsCheckedOut)

test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestDetailViewModelTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,8 @@ static Tuple<PullRequestDetailViewModel, IPullRequestService> CreateTargetAndSer
607607
Substitute.For<ITeamExplorerContext>(),
608608
Substitute.For<IPullRequestFilesViewModel>(),
609609
Substitute.For<ISyncSubmodulesCommand>(),
610-
Substitute.For<IViewViewModelFactory>());
610+
Substitute.For<IViewViewModelFactory>(),
611+
Substitute.For<IGitService>());
611612
vm.InitializeAsync(repository, Substitute.For<IConnection>(), "owner", "repo", 1).Wait();
612613

613614
return Tuple.Create(vm, pullRequestService);

0 commit comments

Comments
 (0)