Skip to content

Commit 13a03da

Browse files
committed
Fixes #1157 - branch compare with working tree off
1 parent d3ec702 commit 13a03da

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

CHANGELOG.md

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

1111
- Fixes [#1150](https://github.com/eamodio/vscode-gitlens/issues/1150) - Cannot read property 'provider' of undefined
12+
- 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
1213

1314
## [11.0.0] - 2020-11-14
1415

src/views/nodes/compareBranchNode.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,30 @@ export class CompareBranchNode extends ViewNode<BranchesView | CommitsView | Rep
223223
}
224224

225225
private async getAheadFilesQuery(): Promise<FilesQueryResults> {
226-
const files = await Container.git.getDiffStatus(
227-
this.uri.repoPath!,
228-
this.compareWithWorkingTree
229-
? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
230-
this._compareWith?.ref || 'HEAD'
231-
: // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
232-
GitRevision.createRange(this._compareWith?.ref || 'HEAD', this.branch.ref, '...'),
226+
let files = await Container.git.getDiffStatus(
227+
this.repoPath,
228+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
229+
GitRevision.createRange(this._compareWith?.ref || 'HEAD', this.branch.ref || 'HEAD', '...'),
233230
);
234231

232+
if (this.compareWithWorkingTree) {
233+
const workingFiles = await Container.git.getDiffStatus(this.repoPath, 'HEAD');
234+
if (workingFiles != null) {
235+
if (files != null) {
236+
for (const wf of workingFiles) {
237+
const index = files.findIndex(f => f.fileName === wf.fileName);
238+
if (index !== -1) {
239+
files.splice(index, 1, wf);
240+
} else {
241+
files.push(wf);
242+
}
243+
}
244+
} else {
245+
files = workingFiles;
246+
}
247+
}
248+
}
249+
235250
return {
236251
label: `${Strings.pluralize('file', files?.length ?? 0, { zero: 'No' })} changed`,
237252
files: files,

0 commit comments

Comments
 (0)