@@ -4,7 +4,7 @@ import { Commands } from '../../constants.commands';
44import type { StoredDeepLinkContext , StoredNamedRef } from '../../constants.storage' ;
55import type { Container } from '../../container' ;
66import { executeGitCommand } from '../../git/actions' ;
7- import { openFileAtRevision } from '../../git/actions/commit' ;
7+ import { openComparisonChanges , openFileAtRevision } from '../../git/actions/commit' ;
88import type { GitBranch } from '../../git/models/branch' ;
99import { getBranchNameWithoutRemote } from '../../git/models/branch' ;
1010import type { GitCommit } from '../../git/models/commit' ;
@@ -19,6 +19,7 @@ import { missingRepositoryId } from '../../gk/models/repositoryIdentities';
1919import { ensureAccount , ensurePaidPlan } from '../../plus/utils' ;
2020import type { ShowInCommitGraphCommandArgs } from '../../plus/webviews/graph/protocol' ;
2121import { createQuickPickSeparator } from '../../quickpicks/items/common' ;
22+ import { debug } from '../../system/decorators/log' ;
2223import { once } from '../../system/event' ;
2324import { Logger } from '../../system/logger' ;
2425import { normalizePath } from '../../system/path' ;
@@ -68,10 +69,7 @@ export class DeepLinkService implements Disposable {
6869 this . _disposables . push ( container . uri . onDidReceiveUri ( async ( uri : Uri ) => this . processDeepLinkUri ( uri ) ) ) ;
6970
7071 const pendingDeepLink = this . container . storage . get ( 'deepLinks:pending' ) ;
71- if ( pendingDeepLink != null ) {
72- void this . container . storage . delete ( 'deepLinks:pending' ) ;
73- void this . processPendingDeepLink ( pendingDeepLink ) ;
74- }
72+ void this . processPendingDeepLink ( pendingDeepLink ) ;
7573 }
7674
7775 dispose ( ) {
@@ -241,9 +239,11 @@ export class DeepLinkService implements Disposable {
241239 }
242240 }
243241
244- private async processPendingDeepLink ( pendingDeepLink : StoredDeepLinkContext ) {
245- if ( pendingDeepLink . url == null ) return ;
246-
242+ @debug ( )
243+ private async processPendingDeepLink ( pendingDeepLink : StoredDeepLinkContext | undefined ) {
244+ if ( pendingDeepLink == null ) return ;
245+ void this . container . storage . delete ( 'deepLinks:pending' ) ;
246+ if ( pendingDeepLink ?. url == null ) return ;
247247 const link = parseDeepLinkUri ( Uri . parse ( pendingDeepLink . url ) ) ;
248248 if ( link == null ) return ;
249249
@@ -509,6 +509,7 @@ export class DeepLinkService implements Disposable {
509509 // TODO @axosoft -ramint: Move all the logic for matching a repo, prompting to add repo, matching remote, etc. for a target (branch, PR, etc.)
510510 // to a separate service where it can be used outside of the context of deep linking. Then the deep link service should leverage it,
511511 // and we should stop using deep links to process things like Launchpad switch actions, Open in Worktree command, etc.
512+ @debug ( )
512513 private async processDeepLink (
513514 initialAction : DeepLinkServiceAction = DeepLinkServiceAction . DeepLinkEventFired ,
514515 useProgress : boolean = true ,
@@ -1078,7 +1079,6 @@ export class DeepLinkService implements Disposable {
10781079 }
10791080 case DeepLinkServiceState . GoToTarget : {
10801081 // Need to re-fetch the remotes in case we opened in a new window
1081-
10821082 if ( targetType === DeepLinkType . Repository ) {
10831083 if (
10841084 this . _context . action === DeepLinkActionType . Switch ||
@@ -1321,9 +1321,25 @@ export class DeepLinkService implements Disposable {
13211321 state : this . _context . state ,
13221322 } ;
13231323
1324+ // Form a new link URL with PR info stripped out in case we are opening an existing PR worktree,
1325+ // in which case we do not want to advance to the "Open All PR Changes" step in the flow.
1326+ // We should only advance to that step if a worktree is newly created in the flow.
1327+ const oldUrl = Uri . parse ( this . _context . url ?? '' ) . toString ( true ) ;
1328+ const urlParams = new URL ( oldUrl ) . searchParams ;
1329+ urlParams . delete ( 'prId' ) ;
1330+ urlParams . delete ( 'prTitle' ) ;
1331+ urlParams . delete ( 'prBaseRef' ) ;
1332+ urlParams . delete ( 'prHeadRef' ) ;
1333+ const newUrlParams = urlParams . toString ( ) ;
1334+ const nonPrUrl =
1335+ newUrlParams . length > 0 ? `${ oldUrl . split ( '?' ) [ 0 ] } ?${ newUrlParams } ` : oldUrl . split ( '?' ) [ 0 ] ;
1336+
13241337 // Storing link info in case the switch causes a new window to open
1325- const onWorkspaceChanging = async ( ) =>
1326- this . container . storage . store ( 'deepLinks:pending' , pendingDeepLink ) ;
1338+ const onWorkspaceChanging = async ( isNewWorktree ?: boolean ) =>
1339+ this . container . storage . store (
1340+ 'deepLinks:pending' ,
1341+ isNewWorktree ? pendingDeepLink : { ...pendingDeepLink , url : nonPrUrl } ,
1342+ ) ;
13271343
13281344 await executeGitCommand ( {
13291345 command : 'switch' ,
@@ -1373,7 +1389,6 @@ export class DeepLinkService implements Disposable {
13731389 case DeepLinkServiceState . OpenInspect : {
13741390 // If we arrive at this step, clear any stored data used for the "new window" option
13751391 await this . container . storage . delete ( 'deepLinks:pending' ) ;
1376-
13771392 if ( ! repo ) {
13781393 action = DeepLinkServiceAction . DeepLinkErrored ;
13791394 message = 'Missing repository.' ;
@@ -1386,6 +1401,46 @@ export class DeepLinkService implements Disposable {
13861401 repository : repo ,
13871402 source : 'launchpad' ,
13881403 } satisfies ShowWipArgs ) ;
1404+ const { params } = this . _context ;
1405+ if (
1406+ this . _context . action === DeepLinkActionType . SwitchToPullRequestWorktree &&
1407+ params != null &&
1408+ ( params . get ( 'prId' ) != null || params . get ( 'prTitle' ) != null ) &&
1409+ params . get ( 'prBaseRef' ) != null &&
1410+ params . get ( 'prHeadRef' ) != null
1411+ ) {
1412+ action = DeepLinkServiceAction . OpenAllPrChanges ;
1413+ break ;
1414+ }
1415+
1416+ action = DeepLinkServiceAction . DeepLinkResolved ;
1417+ break ;
1418+ }
1419+ case DeepLinkServiceState . OpenAllPrChanges : {
1420+ const prId = this . _context . params ?. get ( 'prId' ) ;
1421+ const prHeadRef = this . _context . params ?. get ( 'prHeadRef' ) ;
1422+ const prBaseRef = this . _context . params ?. get ( 'prBaseRef' ) ;
1423+ const prTitle = this . _context . params ?. get ( 'prTitle' ) ;
1424+ if ( ! repoPath || ( ! prId && ! prTitle ) || ! prHeadRef || ! prBaseRef ) {
1425+ action = DeepLinkServiceAction . DeepLinkErrored ;
1426+ if ( ! repoPath ) {
1427+ message = 'No repository path was provided.' ;
1428+ } else if ( ! prId ) {
1429+ message = 'No pull request id provided.' ;
1430+ } else {
1431+ message = 'No pull request refs was provided.' ;
1432+ }
1433+ break ;
1434+ }
1435+ await openComparisonChanges (
1436+ this . container ,
1437+ {
1438+ repoPath : repoPath ,
1439+ lhs : prBaseRef ,
1440+ rhs : prHeadRef ,
1441+ } ,
1442+ { title : `Changes in Pull Request ${ prTitle ? `"${ prTitle } "` : `#${ prId } ` } ` } ,
1443+ ) ;
13891444 action = DeepLinkServiceAction . DeepLinkResolved ;
13901445 break ;
13911446 }
0 commit comments