@@ -72,6 +72,7 @@ export class DeepLinkService implements Disposable {
7272 this . _disposables . push (
7373 this . _onDeepLinkProgressUpdated ,
7474 container . uri . onDidReceiveUri ( async ( uri : Uri ) => this . processDeepLinkUri ( uri ) ) ,
75+ container . storage . onDidChangeSecrets ( this . onDidChangeStorage , this ) ,
7576 ) ;
7677
7778 void this . container . storage . getSecret ( 'deepLinks:pending' ) . then ( pendingDeepLink => {
@@ -86,6 +87,28 @@ export class DeepLinkService implements Disposable {
8687 Disposable . from ( ...this . _disposables ) . dispose ( ) ;
8788 }
8889
90+ private async onDidChangeStorage ( e : SecretStorageChangeEvent ) : Promise < void > {
91+ if ( e . key === 'deepLinks:pending' ) {
92+ const pendingDeepLinkStored = await this . container . storage . getSecret ( 'deepLinks:pending' ) ;
93+ if ( pendingDeepLinkStored == null ) return ;
94+
95+ const pendingDeepLink = JSON . parse ( pendingDeepLinkStored ) as StoredDeepLinkContext ;
96+ if ( pendingDeepLink ?. url == null ) return ;
97+
98+ const link = parseDeepLinkUri ( Uri . parse ( pendingDeepLink . url ) ) ;
99+ if ( link == null ) return ;
100+
101+ // TODO: See if we can remove this condition without breaking other link flows
102+ if ( link . action !== DeepLinkActionType . DeleteBranch ) return ;
103+
104+ // see if there is a matching repo in the current window
105+ await this . findMatchingRepositoryFromCurrentWindow ( link . repoPath , link . remoteUrl , link . mainId , true ) ;
106+ if ( this . _context . repo != null ) {
107+ void this . processPendingDeepLink ( pendingDeepLink ) ;
108+ }
109+ }
110+ }
111+
89112 private resetContext ( ) {
90113 this . _context = {
91114 state : DeepLinkServiceState . Idle ,
@@ -207,14 +230,24 @@ export class DeepLinkService implements Disposable {
207230 repoPath : string | undefined ,
208231 remoteUrl : string | undefined ,
209232 repoId : string | undefined ,
233+ openOnly : boolean = false ,
210234 ) : Promise < void > {
211235 if ( repoPath != null ) {
212236 const repoOpenUri = maybeUri ( repoPath ) ? Uri . parse ( repoPath ) : repoPath ;
213237 try {
214- const openRepo = await this . container . git . getOrOpenRepository ( repoOpenUri , { detectNested : false } ) ;
215- if ( openRepo != null ) {
216- this . _context . repo = openRepo ;
217- return ;
238+ if ( openOnly ) {
239+ for ( const repo of this . container . git . openRepositories ) {
240+ if ( repo . path === repoPath || repo . uri . fsPath === repoPath ) {
241+ this . _context . repo = repo ;
242+ return ;
243+ }
244+ }
245+ } else {
246+ const openRepo = await this . container . git . getOrOpenRepository ( repoOpenUri , { detectNested : false } ) ;
247+ if ( openRepo != null ) {
248+ this . _context . repo = openRepo ;
249+ return ;
250+ }
218251 }
219252 } catch { }
220253 }
@@ -227,7 +260,7 @@ export class DeepLinkService implements Disposable {
227260
228261 // Try to match a repo using the remote URL first, since that saves us some steps.
229262 // As a fallback, try to match using the repo id.
230- for ( const repo of this . container . git . repositories ) {
263+ for ( const repo of openOnly ? this . container . git . openRepositories : this . container . git . repositories ) {
231264 if ( repoPath != null && normalizePath ( repo . path . toLowerCase ( ) ) === normalizePath ( repoPath . toLowerCase ( ) ) ) {
232265 this . _context . repo = repo ;
233266 return ;
0 commit comments