diff --git a/CHANGELOG.md b/CHANGELOG.md index 1710ae9..632fd1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Changed - Improves autolink URL generation by improving the "best" remote detection — refs [#2425](https://github.com/gitkraken/vscode-gitlens/issues/2425) +- Improves preserving the ref names in deeplinks to comparisons ### Fixed diff --git a/src/commands/base.ts b/src/commands/base.ts index bd351df..6d29bda 100644 --- a/src/commands/base.ts +++ b/src/commands/base.ts @@ -9,7 +9,7 @@ import type { } from 'vscode'; import { commands, Disposable, Uri, window } from 'vscode'; import type { ActionContext } from '../api/gitlens'; -import type { Commands } from '../constants'; +import type { Commands, StoredNamedRef } from '../constants'; import type { GitBranch } from '../git/models/branch'; import { isBranch } from '../git/models/branch'; import type { GitCommit, GitStashCommit } from '../git/models/commit'; @@ -159,16 +159,16 @@ export function isCommandContextViewNodeHasFileRefs(context: CommandContext): co ); } -export function isCommandContextViewNodeHasComparison( - context: CommandContext, -): context is CommandViewNodeContext & { node: ViewNode & { _ref: { ref: string }; _compareWith: { ref: string } } } { +export function isCommandContextViewNodeHasComparison(context: CommandContext): context is CommandViewNodeContext & { + node: ViewNode & { compareRef: StoredNamedRef; compareWithRef: StoredNamedRef }; +} { if (context.type !== 'viewItem') return false; return ( - typeof (context.node as ViewNode & { _ref: { ref: string }; _compareWith: { ref: string } })._ref?.ref === - 'string' && - typeof (context.node as ViewNode & { _ref: { ref: string }; _compareWith: { ref: string } })._compareWith - ?.ref === 'string' + typeof (context.node as ViewNode & { compareRef: StoredNamedRef; compareWithRef: StoredNamedRef }).compareRef + ?.ref === 'string' && + typeof (context.node as ViewNode & { compareRef: StoredNamedRef; compareWithRef: StoredNamedRef }) + .compareWithRef?.ref === 'string' ); } diff --git a/src/commands/copyDeepLink.ts b/src/commands/copyDeepLink.ts index 0b0cb1b..4c492c1 100644 --- a/src/commands/copyDeepLink.ts +++ b/src/commands/copyDeepLink.ts @@ -1,4 +1,5 @@ import type { TextEditor, Uri } from 'vscode'; +import type { StoredNamedRef } from '../constants'; import { Commands } from '../constants'; import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; @@ -23,8 +24,8 @@ import { export interface CopyDeepLinkCommandArgs { refOrRepoPath?: GitReference | string; - compareRef?: string; - compareWithRef?: string; + compareRef?: StoredNamedRef; + compareWithRef?: StoredNamedRef; remote?: string; prePickRemote?: boolean; } @@ -54,8 +55,8 @@ export class CopyDeepLinkCommand extends ActiveEditorCommand { } else if (isCommandContextViewNodeHasComparison(context)) { args = { refOrRepoPath: context.node.uri.fsPath, - compareRef: context.node._ref.ref, - compareWithRef: context.node._compareWith.ref, + compareRef: context.node.compareRef, + compareWithRef: context.node.compareWithRef, }; } } diff --git a/src/uris/deepLinks/deepLinkService.ts b/src/uris/deepLinks/deepLinkService.ts index 82f3ea6..0dffdaf 100644 --- a/src/uris/deepLinks/deepLinkService.ts +++ b/src/uris/deepLinks/deepLinkService.ts @@ -1,5 +1,5 @@ import { Disposable, env, EventEmitter, ProgressLocation, Uri, window, workspace } from 'vscode'; -import type { StoredDeepLinkContext } from '../../constants'; +import type { StoredDeepLinkContext, StoredNamedRef } from '../../constants'; import { Commands } from '../../constants'; import type { Container } from '../../container'; import { getBranchNameWithoutRemote } from '../../git/models/branch'; @@ -691,14 +691,14 @@ export class DeepLinkService implements Disposable { async copyDeepLinkUrl( repoPath: string, remoteUrl: string, - compareRef?: string, - compareWithRef?: string, + compareRef?: StoredNamedRef, + compareWithRef?: StoredNamedRef, ): Promise; async copyDeepLinkUrl( refOrRepoPath: string | GitReference, remoteUrl: string, - compareRef?: string, - compareWithRef?: string, + compareRef?: StoredNamedRef, + compareWithRef?: StoredNamedRef, ): Promise { const url = await (typeof refOrRepoPath === 'string' ? this.generateDeepLinkUrl(refOrRepoPath, remoteUrl, compareRef, compareWithRef) @@ -710,14 +710,14 @@ export class DeepLinkService implements Disposable { async generateDeepLinkUrl( repoPath: string, remoteUrl: string, - compareRef?: string, - compareWithRef?: string, + compareRef?: StoredNamedRef, + compareWithRef?: StoredNamedRef, ): Promise; async generateDeepLinkUrl( refOrRepoPath: string | GitReference, remoteUrl: string, - compareRef?: string, - compareWithRef?: string, + compareRef?: StoredNamedRef, + compareWithRef?: StoredNamedRef, ): Promise { const repoPath = typeof refOrRepoPath !== 'string' ? refOrRepoPath.repoPath : refOrRepoPath; let repoId; @@ -751,8 +751,8 @@ export class DeepLinkService implements Disposable { if (compareRef != null && compareWithRef != null) { targetType = DeepLinkType.Comparison; - targetId = compareRef; - compareWithTargetId = compareWithRef; + targetId = compareRef.label ?? compareRef.ref; + compareWithTargetId = compareWithRef.label ?? compareWithRef.ref; } const schemeOverride = configuration.get('deepLinks.schemeOverride'); diff --git a/src/views/nodes/compareResultsNode.ts b/src/views/nodes/compareResultsNode.ts index df181a5..7d2d915 100644 --- a/src/views/nodes/compareResultsNode.ts +++ b/src/views/nodes/compareResultsNode.ts @@ -60,6 +60,14 @@ export class CompareResultsNode extends ViewNode { return !this.pinned; } + get compareRef(): StoredNamedRef { + return this._ref; + } + + get compareWithRef(): StoredNamedRef { + return this._compareWith; + } + private readonly _order: number = Date.now(); get order(): number { return this._pinned || this._order;