Selaa lähdekoodia

Reverses refs for consistent comparisons

main
Eric Amodio 5 vuotta sitten
vanhempi
commit
c27681d24f
4 muutettua tiedostoa jossa 43 lisäystä ja 46 poistoa
  1. +4
    -0
      CHANGELOG.md
  2. +2
    -3
      src/commands/diffDirectory.ts
  3. +1
    -1
      src/views/nodes/compareBranchNode.ts
  4. +36
    -42
      src/views/nodes/compareResultsNode.ts

+ 4
- 0
CHANGELOG.md Näytä tiedosto

@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## [Unreleased]
### Changed
- Reverses the order of comparisons in the _Compare_ view for consistent comparisons results
### Fixed
- Fixes [#812](https://github.com/eamodio/vscode-gitlens/issues/812) - Regression in 9.9.2: Clicking changed file in Repository Browser opens diff view between WorkingTree <-> WorkingTree, not index

+ 2
- 3
src/commands/diffDirectory.ts Näytä tiedosto

@ -32,7 +32,7 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
]);
}
protected preExecute(context: CommandContext, args: DiffDirectoryCommandArgs = {}) {
protected async preExecute(context: CommandContext, args: DiffDirectoryCommandArgs = {}) {
switch (context.command) {
case Commands.DiffDirectoryWithHead:
args.ref1 = 'HEAD';
@ -41,8 +41,7 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
case Commands.ViewsOpenDirectoryDiff:
if (context.type === 'viewItem' && context.node instanceof CompareResultsNode) {
args.ref1 = context.node.ref1.ref;
args.ref2 = context.node.ref2.ref;
[args.ref1, args.ref2] = await context.node.getDiffRefs();
}
break;

+ 1
- 1
src/views/nodes/compareBranchNode.ts Näytä tiedosto

@ -40,7 +40,7 @@ export class CompareBranchNode extends ViewNode {
if (this._compareWith === undefined) return [];
if (this._children === undefined) {
let ref1 = (this._compareWith && this._compareWith.ref) || 'HEAD';
let ref1 = this._compareWith.ref || 'HEAD';
if (this.comparisonNotation === '..') {
ref1 = (await Container.git.getMergeBase(this.branch.repoPath, ref1, this.branch.ref)) || ref1;
}

+ 36
- 42
src/views/nodes/compareResultsNode.ts Näytä tiedosto

@ -18,8 +18,8 @@ export class CompareResultsNode extends SubscribeableViewNode {
constructor(
view: CompareView,
public readonly repoPath: string,
private _ref1: NamedRef,
private _ref2: NamedRef,
private _ref: NamedRef,
private _compareWith: NamedRef,
private _pinned: boolean = false,
private _comparisonNotation?: '...' | '..'
) {
@ -28,33 +28,16 @@ export class CompareResultsNode extends SubscribeableViewNode {
}
get id(): string {
return `gitlens:repository(${this.repoPath}):compare(${this._ref1.ref}:${this._ref2.ref})|${this._instanceId}`;
}
get label() {
return `Comparing ${this._ref1.label ||
GitService.shortenSha(this._ref1.ref, { working: 'Working Tree' })} to ${this._ref2.label ||
GitService.shortenSha(this._ref2.ref, { working: 'Working Tree' })}`;
return `gitlens:repository(${this.repoPath}):compare(${this._ref.ref}:${this._compareWith.ref})|${this._instanceId}`;
}
get pinned(): boolean {
return this._pinned;
}
get ref1(): NamedRef {
return this._ref1;
}
get ref2(): NamedRef {
return this._ref2;
}
async getChildren(): Promise<ViewNode[]> {
if (this._children === undefined) {
let ref1 = this._ref1.ref;
if (this.comparisonNotation === '..') {
ref1 = (await Container.git.getMergeBase(this.repoPath, ref1, this._ref2.ref)) || ref1;
}
const [ref1, ref2] = await this.getDiffRefs();
this._children = [
new ResultsCommitsNode(
@ -68,14 +51,7 @@ export class CompareResultsNode extends SubscribeableViewNode {
includeDescription: true
}
),
new ResultsFilesNode(
this.view,
this,
this.uri.repoPath!,
ref1,
this._ref2.ref,
this.getFilesQuery.bind(this)
)
new ResultsFilesNode(this.view, this, this.uri.repoPath!, ref1, ref2, this.getFilesQuery.bind(this))
];
}
return this._children;
@ -88,7 +64,11 @@ export class CompareResultsNode extends SubscribeableViewNode {
description = (repo && repo.formattedName) || this.uri.repoPath;
}
const item = new TreeItem(this.label, this._state || TreeItemCollapsibleState.Collapsed);
const item = new TreeItem(
`Comparing ${this._ref.label || GitService.shortenSha(this._ref.ref, { working: 'Working Tree' })} to ${this
._compareWith.label || GitService.shortenSha(this._compareWith.ref, { working: 'Working Tree' })}`,
this._state || TreeItemCollapsibleState.Collapsed
);
item.contextValue = `${ResourceType.CompareResults}+${
this.comparisonNotation === '..' ? 'twodot' : 'threedot'
}`;
@ -111,14 +91,28 @@ export class CompareResultsNode extends SubscribeableViewNode {
return !this._pinned;
}
@gate()
@debug()
async getDiffRefs(): Promise<[string, string]> {
if (this.comparisonNotation === '..') {
return [
(await Container.git.getMergeBase(this.repoPath, this._compareWith.ref, this._ref.ref)) ||
this._compareWith.ref,
this._ref.ref
];
}
return [this._compareWith.ref, this._ref.ref];
}
@log()
async pin() {
if (this._pinned) return;
await this.view.updatePinnedComparison(this.getPinnableId(), {
path: this.repoPath,
ref1: this.ref1,
ref2: this.ref2,
ref1: this._ref,
ref2: this._compareWith,
notation: this._comparisonNotation
});
@ -141,8 +135,8 @@ export class CompareResultsNode extends SubscribeableViewNode {
if (this._pinned) {
await this.view.updatePinnedComparison(this.getPinnableId(), {
path: this.repoPath,
ref1: this.ref1,
ref2: this.ref2,
ref1: this._ref,
ref2: this._compareWith,
notation: this._comparisonNotation
});
}
@ -156,17 +150,17 @@ export class CompareResultsNode extends SubscribeableViewNode {
// Save the current id so we can update it later
const currentId = this.getPinnableId();
const ref1 = this._ref1;
this._ref1 = this._ref2;
this._ref2 = ref1;
const ref1 = this._ref;
this._ref = this._compareWith;
this._compareWith = ref1;
// If we were pinned, remove the existing pin and save a new one
if (this._pinned) {
await this.view.updatePinnedComparison(currentId);
await this.view.updatePinnedComparison(this.getPinnableId(), {
path: this.repoPath,
ref1: this.ref1,
ref2: this.ref2,
ref1: this._ref,
ref2: this._compareWith,
notation: this._comparisonNotation
});
}
@ -203,7 +197,7 @@ export class CompareResultsNode extends SubscribeableViewNode {
private async getCommitsQuery(maxCount: number | undefined): Promise<CommitsQueryResults> {
const log = await Container.git.getLog(this.uri.repoPath!, {
maxCount: maxCount,
ref: `${this._ref1.ref}${this.comparisonNotation}${this._ref2.ref || 'HEAD'}`
ref: `${this._compareWith.ref || 'HEAD'}${this.comparisonNotation}${this._ref.ref}`
});
const count = log !== undefined ? log.count : 0;
@ -218,7 +212,7 @@ export class CompareResultsNode extends SubscribeableViewNode {
private async getFilesQuery(): Promise<FilesQueryResults> {
const diff = await Container.git.getDiffStatus(
this.uri.repoPath!,
`${this._ref1.ref}${this.diffComparisonNotation}${this._ref2.ref || 'HEAD'}`
`${this._compareWith.ref || 'HEAD'}${this.diffComparisonNotation}${this._ref.ref || 'HEAD'}`
);
return {
@ -228,6 +222,6 @@ export class CompareResultsNode extends SubscribeableViewNode {
}
private getPinnableId() {
return Strings.sha1(`${this.repoPath}|${this.ref1.ref}|${this.ref2.ref}`);
return Strings.sha1(`${this.repoPath}|${this._ref.ref}|${this._compareWith.ref}`);
}
}

Ladataan…
Peruuta
Tallenna