From 2448e7d6efc57f48e1970a90ea9fe6966b8e9abb Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 6 Nov 2020 01:41:28 -0500 Subject: [PATCH] Fixes ahead/behind with working tree --- src/views/nodes/compareBranchNode.ts | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/src/views/nodes/compareBranchNode.ts b/src/views/nodes/compareBranchNode.ts index a36d459..fd52d2f 100644 --- a/src/views/nodes/compareBranchNode.ts +++ b/src/views/nodes/compareBranchNode.ts @@ -223,30 +223,15 @@ export class CompareBranchNode extends ViewNode { - let files = await Container.git.getDiffStatus( + const files = await Container.git.getDiffStatus( this.uri.repoPath!, - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - GitRevision.createRange(this._compareWith?.ref || 'HEAD', this.branch.ref, '...'), + this.compareWithWorkingTree + ? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + this._compareWith?.ref || 'HEAD' + : // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + GitRevision.createRange(this._compareWith?.ref || 'HEAD', this.branch.ref, '...'), ); - if (this.compareWithWorkingTree) { - const workingFiles = await Container.git.getDiffStatus(this.uri.repoPath!, 'HEAD'); - if (workingFiles != null) { - if (files != null) { - for (const wf of workingFiles) { - const index = files.findIndex(f => f.fileName === wf.fileName); - if (index !== -1) { - files.splice(index, 1, wf); - } else { - files.push(wf); - } - } - } else { - files = workingFiles; - } - } - } - return { label: `${Strings.pluralize('file', files?.length ?? 0, { zero: 'No' })} changed`, files: files, @@ -256,11 +241,8 @@ export class CompareBranchNode extends ViewNode { const files = await Container.git.getDiffStatus( this.uri.repoPath!, - this.compareWithWorkingTree - ? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - this._compareWith?.ref || 'HEAD' - : // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - GitRevision.createRange(this.branch.ref, this._compareWith?.ref || 'HEAD', '...'), + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + GitRevision.createRange(this.branch.ref, this._compareWith?.ref || 'HEAD', '...'), ); return {