Browse Source

Fixes comparison commands on File/Line History

main
Eric Amodio 1 year ago
parent
commit
a91e61aa79
2 changed files with 49 additions and 25 deletions
  1. +4
    -2
      src/commands/base.ts
  2. +45
    -23
      src/views/viewCommands.ts

+ 4
- 2
src/commands/base.ts View File

@ -23,7 +23,7 @@ import type { GitTag } from '../git/models/tag';
import { isTag } from '../git/models/tag';
import { registerCommand } from '../system/command';
import { sequentialize } from '../system/function';
import { ViewNode, ViewRefNode } from '../views/nodes/viewNode';
import { ViewNode, ViewRefFileNode, ViewRefNode } from '../views/nodes/viewNode';
export function getCommandUri(uri?: Uri, editor?: TextEditor): Uri | undefined {
// Always use the editor.uri (if we have one), so we are correct for a split diff
@ -162,7 +162,9 @@ export function isCommandContextViewNodeHasFileRefs(context: CommandContext): co
export function isCommandContextViewNodeHasRef(
context: CommandContext,
): context is CommandViewNodeContext & { node: ViewNode & { ref: GitReference } } {
return context.type === 'viewItem' && context.node instanceof ViewRefNode;
return (
context.type === 'viewItem' && context.node instanceof ViewRefNode && context.node instanceof ViewRefFileNode
);
}
export function isCommandContextViewNodeHasRemote(

+ 45
- 23
src/views/viewCommands.ts View File

@ -376,9 +376,9 @@ export class ViewCommands {
}
@debug()
private async createBranch(node?: ViewRefNode | BranchesNode | BranchTrackingStatusNode) {
private async createBranch(node?: ViewRefNode | ViewRefFileNode | BranchesNode | BranchTrackingStatusNode) {
let from =
node instanceof ViewRefNode
node instanceof ViewRefNode || node instanceof ViewRefFileNode
? node?.ref
: node instanceof BranchTrackingStatusNode
? node.branch
@ -426,9 +426,9 @@ export class ViewCommands {
}
@debug()
private async createTag(node?: ViewRefNode | TagsNode | BranchTrackingStatusNode) {
private async createTag(node?: ViewRefNode | ViewRefFileNode | TagsNode | BranchTrackingStatusNode) {
let from =
node instanceof ViewRefNode
node instanceof ViewRefNode || node instanceof ViewRefFileNode
? node?.ref
: node instanceof BranchTrackingStatusNode
? node.branch
@ -887,8 +887,12 @@ export class ViewCommands {
}
@debug()
private compareHeadWith(node: ViewRefNode) {
if (!(node instanceof ViewRefNode)) return Promise.resolve();
private compareHeadWith(node: ViewRefNode | ViewRefFileNode) {
if (!(node instanceof ViewRefNode) && !(node instanceof ViewRefFileNode)) return Promise.resolve();
if (node instanceof ViewRefFileNode) {
return this.compareFileWith(node.repoPath, node.uri, node.ref.ref, undefined, 'HEAD');
}
return this.container.searchAndCompareView.compare(node.repoPath, 'HEAD', node.ref);
}
@ -902,8 +906,12 @@ export class ViewCommands {
}
@debug()
private compareWorkingWith(node: ViewRefNode) {
if (!(node instanceof ViewRefNode)) return Promise.resolve();
private compareWorkingWith(node: ViewRefNode | ViewRefFileNode) {
if (!(node instanceof ViewRefNode) && !(node instanceof ViewRefFileNode)) return Promise.resolve();
if (node instanceof ViewRefFileNode) {
return this.compareFileWith(node.repoPath, node.uri, node.ref.ref, undefined, '');
}
return this.container.searchAndCompareView.compare(node.repoPath, '', node.ref);
}
@ -929,19 +937,43 @@ export class ViewCommands {
}
@debug()
private compareWithSelected(node: ViewRefNode) {
if (!(node instanceof ViewRefNode)) return;
private compareWithSelected(node: ViewRefNode | ViewRefFileNode) {
if (!(node instanceof ViewRefNode) && !(node instanceof ViewRefFileNode)) return;
this.container.searchAndCompareView.compareWithSelected(node.repoPath, node.ref);
}
@debug()
private selectForCompare(node: ViewRefNode) {
if (!(node instanceof ViewRefNode)) return;
private selectForCompare(node: ViewRefNode | ViewRefFileNode) {
if (!(node instanceof ViewRefNode) && !(node instanceof ViewRefFileNode)) return;
this.container.searchAndCompareView.selectForCompare(node.repoPath, node.ref);
}
private async compareFileWith(
repoPath: string,
lhsUri: Uri,
lhsRef: string,
rhsUri: Uri | undefined,
rhsRef: string,
) {
if (rhsUri == null) {
rhsUri = await this.container.git.getWorkingUri(repoPath, lhsUri);
}
return executeCommand<DiffWithCommandArgs>(Commands.DiffWith, {
repoPath: repoPath,
lhs: {
sha: lhsRef,
uri: lhsUri,
},
rhs: {
sha: rhsRef,
uri: rhsUri ?? lhsUri,
},
});
}
@debug()
private compareFileWithSelected(node: ViewRefFileNode) {
if (this._selectedFile == null || !(node instanceof ViewRefFileNode) || node.ref == null) {
@ -958,17 +990,7 @@ export class ViewCommands {
this._selectedFile = undefined;
void setContext('gitlens:views:canCompare:file', false);
return executeCommand<DiffWithCommandArgs>(Commands.DiffWith, {
repoPath: selected.repoPath,
lhs: {
sha: selected.ref,
uri: selected.uri!,
},
rhs: {
sha: node.ref.ref,
uri: node.uri,
},
});
return this.compareFileWith(selected.repoPath!, selected.uri!, selected.ref, node.uri, node.ref.ref);
}
private _selectedFile: CompareSelectedInfo | undefined;

Loading…
Cancel
Save