From 1ff294190f142a631cd20c6ca64eb859c8cca4c0 Mon Sep 17 00:00:00 2001 From: Ramin Tadayon Date: Mon, 17 Jul 2023 17:29:10 -0700 Subject: [PATCH] Allows for working tree in comparison in deeplinks --- CHANGELOG.md | 1 + src/uris/deepLinks/deepLinkService.ts | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 632fd1c..208945a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Fixes [#2744](https://github.com/gitkraken/vscode-gitlens/issues/2744) - GH enterprise access with focus view - Fixes deeplink comparison ordering for a better experience +- Fixes deeplinks to comparisons with working tree not resolving ## [14.1.0] - 2023-07-13 diff --git a/src/uris/deepLinks/deepLinkService.ts b/src/uris/deepLinks/deepLinkService.ts index 0dffdaf..eb1317e 100644 --- a/src/uris/deepLinks/deepLinkService.ts +++ b/src/uris/deepLinks/deepLinkService.ts @@ -56,13 +56,13 @@ export class DeepLinkService implements Disposable { return; } - if (link.type !== DeepLinkType.Repository && !link.targetId) { + if (link.type !== DeepLinkType.Repository && link.targetId == null) { void window.showErrorMessage('Unable to resolve link'); Logger.warn(`Unable to resolve link - no target id provided: ${uri.toString()}`); return; } - if (link.type === DeepLinkType.Comparison && !link.secondaryTargetId) { + if (link.type === DeepLinkType.Comparison && link.secondaryTargetId == null) { void window.showErrorMessage('Unable to resolve link'); Logger.warn(`Unable to resolve link - no secondary target id provided: ${uri.toString()}`); return; @@ -187,16 +187,21 @@ export class DeepLinkService implements Disposable { targetId: string, secondaryTargetId: string, ): Promise<[string, string] | undefined> { - // try treating each id as a commit sha first, then a branch if that fails, then a tag if that fails + // try treating each id as a commit sha first, then a branch if that fails, then a tag if that fails. + // Note: a blank target id will be treated as 'Working Tree' and will resolve to a blank Sha. const sha1 = - (await this.getShaForCommit(targetId)) ?? - (await this.getShaForBranch(targetId)) ?? - (await this.getShaForTag(targetId)); + targetId === '' + ? targetId + : (await this.getShaForCommit(targetId)) ?? + (await this.getShaForBranch(targetId)) ?? + (await this.getShaForTag(targetId)); if (sha1 == null) return undefined; const sha2 = - (await this.getShaForCommit(secondaryTargetId)) ?? - (await this.getShaForBranch(secondaryTargetId)) ?? - (await this.getShaForTag(secondaryTargetId)); + secondaryTargetId === '' + ? secondaryTargetId + : (await this.getShaForCommit(secondaryTargetId)) ?? + (await this.getShaForBranch(secondaryTargetId)) ?? + (await this.getShaForTag(secondaryTargetId)); if (sha2 == null) return undefined; return [sha1, sha2]; } @@ -663,7 +668,7 @@ export class DeepLinkService implements Disposable { break; } - if (!targetSha || !secondaryTargetSha) { + if (targetSha == null || secondaryTargetSha == null) { action = DeepLinkServiceAction.DeepLinkErrored; message = 'Missing target or secondary target.'; break; @@ -671,10 +676,10 @@ export class DeepLinkService implements Disposable { await this.container.searchAndCompareView.compare( repo.path, - isSha(secondaryTargetSha) + secondaryTargetSha === '' || isSha(secondaryTargetSha) ? secondaryTargetSha : { label: secondaryTargetSha, ref: secondaryTargetSha }, - isSha(targetSha) ? targetSha : { label: targetSha, ref: targetSha }, + targetSha === '' || isSha(targetSha) ? targetSha : { label: targetSha, ref: targetSha }, ); action = DeepLinkServiceAction.DeepLinkResolved; break;