@@ -67,12 +67,10 @@ public PullRequestSessionManager(
6767 this . modelServiceFactory = modelServiceFactory ;
6868
6969 Observable . FromEventPattern ( teamExplorerContext , nameof ( teamExplorerContext . StatusChanged ) )
70- . StartWith ( ( EventPattern < object > ) null )
7170 . ObserveOn ( RxApp . MainThreadScheduler )
72- . Subscribe ( _ => RepoChanged ( teamExplorerContext . ActiveRepository ) . Forget ( ) ) ;
71+ . Subscribe ( _ => StatusChanged ( ) . Forget ( ) ) ;
7372
7473 teamExplorerContext . WhenAnyValue ( x => x . ActiveRepository )
75- . Skip ( 1 )
7674 . ObserveOn ( RxApp . MainThreadScheduler )
7775 . Subscribe ( x => RepoChanged ( x ) . Forget ( ) ) ;
7876 }
@@ -159,8 +157,8 @@ public async Task<IPullRequestSession> GetSession(IPullRequestModel pullRequest)
159157 {
160158 // The branch for the PR was not previously marked with the PR number in the git
161159 // config so we didn't pick up that the current branch is a PR branch. That has
162- // now been corrected, so call RepoChanged to make sure everything is up-to-date.
163- await RepoChanged ( repository ) ;
160+ // now been corrected, so call StatusChanged to make sure everything is up-to-date.
161+ await StatusChanged ( ) ;
164162 }
165163
166164 return await GetSessionInternal ( pullRequest ) ;
@@ -191,28 +189,23 @@ public PullRequestTextBufferInfo GetTextBufferInfo(ITextBuffer buffer)
191189
192190 async Task RepoChanged ( ILocalRepositoryModel localRepositoryModel )
193191 {
194- try
195- {
196- if ( localRepositoryModel != repository )
197- {
198- repository = localRepositoryModel ;
199- CurrentSession = null ;
200- sessions . Clear ( ) ;
201-
202- if ( localRepositoryModel == null )
203- {
204- return ;
205- }
192+ repository = localRepositoryModel ;
193+ CurrentSession = null ;
194+ sessions . Clear ( ) ;
206195
207- if ( string . IsNullOrWhiteSpace ( localRepositoryModel . CloneUrl ) )
208- {
209- return ;
210- }
211- }
196+ if ( localRepositoryModel != null )
197+ {
198+ await StatusChanged ( ) ;
199+ }
200+ }
212201
202+ async Task StatusChanged ( )
203+ {
204+ try
205+ {
213206 var session = CurrentSession ;
214207
215- var pr = await service . GetPullRequestForCurrentBranch ( localRepositoryModel ) . FirstOrDefaultAsync ( ) ;
208+ var pr = await service . GetPullRequestForCurrentBranch ( repository ) . FirstOrDefaultAsync ( ) ;
216209 if ( pr != null )
217210 {
218211 var changePR =
@@ -222,7 +215,7 @@ async Task RepoChanged(ILocalRepositoryModel localRepositoryModel)
222215 if ( changePR )
223216 {
224217 var modelService = await connectionManager . GetModelService ( repository , modelServiceFactory ) ;
225- var pullRequest = await modelService ? . GetPullRequest ( pr . Item1 , localRepositoryModel . Name , pr . Item2 ) ;
218+ var pullRequest = await modelService ? . GetPullRequest ( pr . Item1 , repository . Name , pr . Item2 ) ;
226219 if ( pullRequest != null )
227220 {
228221 var newSession = await GetSessionInternal ( pullRequest ) ;
0 commit comments