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

Commit 5b2c0ba

Browse files
authored
Merge pull request #460 from github/fixes/455-source-branch-does-not-exist-remotely
Correctly validate source branch in PR creation.
2 parents c14da9b + 9d1a07a commit 5b2c0ba

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/GitHub.App/ViewModels/PullRequestCreationViewModel.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@
1313
using GitHub.Extensions;
1414
using NullGuard;
1515
using GitHub.App;
16+
using System.Reactive.Subjects;
17+
using System.Reactive;
18+
using System.Diagnostics.CodeAnalysis;
1619
using Octokit;
1720

1821
namespace GitHub.ViewModels
1922
{
2023
[ExportViewModel(ViewType = UIViewType.PRCreation)]
2124
[PartCreationPolicy(CreationPolicy.NonShared)]
25+
[SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable")]
2226
public class PullRequestCreationViewModel : BaseViewModel, IPullRequestCreationViewModel
2327
{
2428
readonly IRepositoryHost repositoryHost;
2529
readonly ISimpleRepositoryModel activeRepo;
30+
readonly Subject<Unit> initializationComplete = new Subject<Unit>();
31+
bool initialized;
2632

2733
[ImportingConstructor]
2834
PullRequestCreationViewModel(
@@ -53,7 +59,9 @@ public PullRequestCreationViewModel(IRepositoryHost repositoryHost, ISimpleRepos
5359

5460
var branchObs = this.WhenAny(
5561
x => x.SourceBranch,
56-
source => source.Value);
62+
source => source.Value)
63+
.Where(_ => initialized)
64+
.Merge(initializationComplete.Select(_ => SourceBranch));
5765

5866
BranchValidator = ReactivePropertyValidator.ForObservable(branchObs)
5967
.IfTrue(x => x == null, Resources.PullRequestSourceBranchDoesNotExist)
@@ -86,12 +94,18 @@ public PullRequestCreationViewModel(IRepositoryHost repositoryHost, ISimpleRepos
8694

8795
public override void Initialize([AllowNull] ViewWithData data)
8896
{
97+
initialized = false;
8998
base.Initialize(data);
9099

91100
repositoryHost.ModelService.GetBranches(activeRepo)
92101
.ToReadOnlyList()
93102
.ObserveOn(RxApp.MainThreadScheduler)
94-
.Subscribe(x => Branches = x);
103+
.Subscribe(x =>
104+
{
105+
Branches = x;
106+
initialized = true;
107+
initializationComplete.OnNext(Unit.Default);
108+
});
95109
}
96110

97111
IBranch sourceBranch;

0 commit comments

Comments
 (0)