Skip to content

Commit

Permalink
Fixes #1157 - branch compare with working tree off
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 16, 2020
1 parent d3ec702 commit 13a03da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed

- Fixes [#1150](https://github.com/eamodio/vscode-gitlens/issues/1150) - Cannot read property 'provider' of undefined
- Fixes [#1157](https://github.com/eamodio/vscode-gitlens/issues/1157) - GitLens report `X files changed` when comparing working tree with a branch having identical files

## [11.0.0] - 2020-11-14

Expand Down
29 changes: 22 additions & 7 deletions src/views/nodes/compareBranchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,30 @@ export class CompareBranchNode extends ViewNode<BranchesView | CommitsView | Rep
}

private async getAheadFilesQuery(): Promise<FilesQueryResults> {
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._compareWith?.ref || 'HEAD', this.branch.ref, '...'),
let files = await Container.git.getDiffStatus(
this.repoPath,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
GitRevision.createRange(this._compareWith?.ref || 'HEAD', this.branch.ref || 'HEAD', '...'),
);

if (this.compareWithWorkingTree) {
const workingFiles = await Container.git.getDiffStatus(this.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,
Expand Down

0 comments on commit 13a03da

Please sign in to comment.