Skip to content

Commit d527da7

Browse files
committed
Improves ref names in comparison deeplinks
1 parent fd5d57f commit d527da7

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1313
### Changed
1414

1515
- Improves autolink URL generation by improving the "best" remote detection — refs [#2425](https://github.com/gitkraken/vscode-gitlens/issues/2425)
16+
- Improves preserving the ref names in deeplinks to comparisons
1617

1718
### Fixed
1819

src/commands/base.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
} from 'vscode';
1010
import { commands, Disposable, Uri, window } from 'vscode';
1111
import type { ActionContext } from '../api/gitlens';
12-
import type { Commands } from '../constants';
12+
import type { Commands, StoredNamedRef } from '../constants';
1313
import type { GitBranch } from '../git/models/branch';
1414
import { isBranch } from '../git/models/branch';
1515
import type { GitCommit, GitStashCommit } from '../git/models/commit';
@@ -159,16 +159,16 @@ export function isCommandContextViewNodeHasFileRefs(context: CommandContext): co
159159
);
160160
}
161161

162-
export function isCommandContextViewNodeHasComparison(
163-
context: CommandContext,
164-
): context is CommandViewNodeContext & { node: ViewNode & { _ref: { ref: string }; _compareWith: { ref: string } } } {
162+
export function isCommandContextViewNodeHasComparison(context: CommandContext): context is CommandViewNodeContext & {
163+
node: ViewNode & { compareRef: StoredNamedRef; compareWithRef: StoredNamedRef };
164+
} {
165165
if (context.type !== 'viewItem') return false;
166166

167167
return (
168-
typeof (context.node as ViewNode & { _ref: { ref: string }; _compareWith: { ref: string } })._ref?.ref ===
169-
'string' &&
170-
typeof (context.node as ViewNode & { _ref: { ref: string }; _compareWith: { ref: string } })._compareWith
171-
?.ref === 'string'
168+
typeof (context.node as ViewNode & { compareRef: StoredNamedRef; compareWithRef: StoredNamedRef }).compareRef
169+
?.ref === 'string' &&
170+
typeof (context.node as ViewNode & { compareRef: StoredNamedRef; compareWithRef: StoredNamedRef })
171+
.compareWithRef?.ref === 'string'
172172
);
173173
}
174174

src/commands/copyDeepLink.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { TextEditor, Uri } from 'vscode';
2+
import type { StoredNamedRef } from '../constants';
23
import { Commands } from '../constants';
34
import type { Container } from '../container';
45
import { GitUri } from '../git/gitUri';
@@ -23,8 +24,8 @@ import {
2324

2425
export interface CopyDeepLinkCommandArgs {
2526
refOrRepoPath?: GitReference | string;
26-
compareRef?: string;
27-
compareWithRef?: string;
27+
compareRef?: StoredNamedRef;
28+
compareWithRef?: StoredNamedRef;
2829
remote?: string;
2930
prePickRemote?: boolean;
3031
}
@@ -54,8 +55,8 @@ export class CopyDeepLinkCommand extends ActiveEditorCommand {
5455
} else if (isCommandContextViewNodeHasComparison(context)) {
5556
args = {
5657
refOrRepoPath: context.node.uri.fsPath,
57-
compareRef: context.node._ref.ref,
58-
compareWithRef: context.node._compareWith.ref,
58+
compareRef: context.node.compareRef,
59+
compareWithRef: context.node.compareWithRef,
5960
};
6061
}
6162
}

src/uris/deepLinks/deepLinkService.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Disposable, env, EventEmitter, ProgressLocation, Uri, window, workspace } from 'vscode';
2-
import type { StoredDeepLinkContext } from '../../constants';
2+
import type { StoredDeepLinkContext, StoredNamedRef } from '../../constants';
33
import { Commands } from '../../constants';
44
import type { Container } from '../../container';
55
import { getBranchNameWithoutRemote } from '../../git/models/branch';
@@ -691,14 +691,14 @@ export class DeepLinkService implements Disposable {
691691
async copyDeepLinkUrl(
692692
repoPath: string,
693693
remoteUrl: string,
694-
compareRef?: string,
695-
compareWithRef?: string,
694+
compareRef?: StoredNamedRef,
695+
compareWithRef?: StoredNamedRef,
696696
): Promise<void>;
697697
async copyDeepLinkUrl(
698698
refOrRepoPath: string | GitReference,
699699
remoteUrl: string,
700-
compareRef?: string,
701-
compareWithRef?: string,
700+
compareRef?: StoredNamedRef,
701+
compareWithRef?: StoredNamedRef,
702702
): Promise<void> {
703703
const url = await (typeof refOrRepoPath === 'string'
704704
? this.generateDeepLinkUrl(refOrRepoPath, remoteUrl, compareRef, compareWithRef)
@@ -710,14 +710,14 @@ export class DeepLinkService implements Disposable {
710710
async generateDeepLinkUrl(
711711
repoPath: string,
712712
remoteUrl: string,
713-
compareRef?: string,
714-
compareWithRef?: string,
713+
compareRef?: StoredNamedRef,
714+
compareWithRef?: StoredNamedRef,
715715
): Promise<URL>;
716716
async generateDeepLinkUrl(
717717
refOrRepoPath: string | GitReference,
718718
remoteUrl: string,
719-
compareRef?: string,
720-
compareWithRef?: string,
719+
compareRef?: StoredNamedRef,
720+
compareWithRef?: StoredNamedRef,
721721
): Promise<URL> {
722722
const repoPath = typeof refOrRepoPath !== 'string' ? refOrRepoPath.repoPath : refOrRepoPath;
723723
let repoId;
@@ -751,8 +751,8 @@ export class DeepLinkService implements Disposable {
751751

752752
if (compareRef != null && compareWithRef != null) {
753753
targetType = DeepLinkType.Comparison;
754-
targetId = compareRef;
755-
compareWithTargetId = compareWithRef;
754+
targetId = compareRef.label ?? compareRef.ref;
755+
compareWithTargetId = compareWithRef.label ?? compareWithRef.ref;
756756
}
757757

758758
const schemeOverride = configuration.get('deepLinks.schemeOverride');

src/views/nodes/compareResultsNode.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ export class CompareResultsNode extends ViewNode<SearchAndCompareView> {
6060
return !this.pinned;
6161
}
6262

63+
get compareRef(): StoredNamedRef {
64+
return this._ref;
65+
}
66+
67+
get compareWithRef(): StoredNamedRef {
68+
return this._compareWith;
69+
}
70+
6371
private readonly _order: number = Date.now();
6472
get order(): number {
6573
return this._pinned || this._order;

0 commit comments

Comments
 (0)