Skip to content

Commit 2c3fad5

Browse files
committed
Fixes #1161, #1157 - re-adds file comparison
1 parent 90bf772 commit 2c3fad5

File tree

4 files changed

+78
-8
lines changed

4 files changed

+78
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [Unreleased]
8+
9+
### Fixed
10+
11+
- Fixes [#1161](https://github.com/eamodio/vscode-gitlens/issues/1161) - Compare file differences between branches
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
13+
714
## [11.0.3] - 2020-11-22
815

916
### Fixed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ The _Commits_ view lists all of the commits on the current branch, and additiona
252252
- a toggle to change the file layout: list, tree, auto
253253
- a branch comparison tool (**Compare <current branch> with <branch, tag, or ref>**) — [optionally](#commits-view-settings- 'Jump to the Commits view settings') shows a comparison of the current branch (or working tree) to a user-selected reference
254254
- **Behind** — lists the commits that are missing from the current branch (i.e. behind) but exist in the selected reference
255-
- **# files changed** — lists all of the files changed between the compared references
255+
- **# files changed** — lists all of the files changed in the behind commits
256256
- **Ahead** — lists the commits that the current branch has (i.e. ahead) but are missing in the selected reference
257-
- **# files changed** — lists all of the files changed between the compared references
257+
- **# files changed** — lists all of the files changed in the ahead commits
258+
- **# files changed** — lists all of the files changed between the compared references
258259
- the current branch status — shows the upstream status of the current branch
259260
- **Publish <current branch> to <remote>** — shown when the current branch has not been published to a remote
260261
- **Up to date with <remote>** — shown when the current branch is up to date with the upstream remote
@@ -302,9 +303,10 @@ The _Branches_ view lists all of the local branches, and additionally provides,
302303
- _Yellow dot_ — both unpublished and un-pulled changes
303304
- a branch comparison tool (**Compare <branch> with <branch, tag, or ref>**) — [optionally](#branches-view-settings- 'Jump to the Branches view settings') shows a comparison of the branch to a user-selected reference
304305
- **Behind** — lists the commits that are missing from the branch (i.e. behind) but exist in the selected reference
305-
- **# files changed** — lists all of the files changed between the compared references
306+
- **# files changed** — lists all of the files changed in the behind commits
306307
- **Ahead** — lists the commits that the branch has (i.e. ahead) but are missing in the selected reference
307-
- **# files changed** — lists all of the files changed between the compared references
308+
- **# files changed** — lists all of the files changed in the ahead commits
309+
- **# files changed** — lists all of the files changed between the compared references
308310
- the branch status — shows the upstream status of the branch
309311
- **Publish <branch> to <remote>** — shown when the current branch has not been published to a remote
310312
- **Changes to push to <remote>** — lists of all the files changed in the unpublished commits when the branch has (unpublished) commits that waiting to be pushed to the upstream remote
@@ -396,9 +398,10 @@ The _Search & Compare_ view lists pinnable (saved) results for searching commit
396398
- _Show Commit_ command (`gitlens.showQuickCommitDetails`)
397399
- pinnable comparison — shows a comparison of the two user-selected references
398400
- **Behind** — lists the commits that are missing from the branch (i.e. behind) but exist in the selected reference
399-
- **# files changed** — lists all of the files changed between the compared references
401+
- **# files changed** — lists all of the files changed in the behind commits
400402
- **Ahead** — lists the commits that the branch has (i.e. ahead) but are missing in the selected reference
401-
- **# files changed** — lists all of the files changed between the compared references
403+
- **# files changed** — lists all of the files changed in the ahead commits
404+
- **# files changed** — lists all of the files changed between the compared references
402405
- Comparision results can be provided by the following commands
403406
- _Compare with Upstream_ command (`gitlens.views.compareWithUpstream`)
404407
- _Compare with Working Tree_ command (`gitlens.views.compareWithWorking`)

src/views/nodes/compareBranchNode.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CommandQuickPickItem, ReferencePicker } from '../../quickpicks';
1111
import { RepositoriesView } from '../repositoriesView';
1212
import { RepositoryNode } from './repositoryNode';
1313
import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode';
14-
import { FilesQueryResults } from './resultsFilesNode';
14+
import { FilesQueryResults, ResultsFilesNode } from './resultsFilesNode';
1515
import { debug, gate, log, Strings } from '../../system';
1616
import { ContextValues, ViewNode } from './viewNode';
1717

@@ -115,6 +115,18 @@ export class CompareBranchNode extends ViewNode<BranchesView | CommitsView | Rep
115115
expand: false,
116116
},
117117
),
118+
new ResultsFilesNode(
119+
this.view,
120+
this,
121+
this.uri.repoPath!,
122+
this.branch.ref,
123+
this.compareWithWorkingTree ? '' : this._compareWith.ref || 'HEAD',
124+
this.getFilesQuery.bind(this),
125+
undefined,
126+
{
127+
expand: false,
128+
},
129+
),
118130
];
119131
}
120132
return this._children;
@@ -289,6 +301,24 @@ export class CompareBranchNode extends ViewNode<BranchesView | CommitsView | Rep
289301
};
290302
}
291303

304+
private async getFilesQuery(): Promise<FilesQueryResults> {
305+
let comparison;
306+
if (this._compareWith!.ref === '') {
307+
comparison = this.branch.ref;
308+
} else if (this.compareWithWorkingTree) {
309+
comparison = this._compareWith!.ref;
310+
} else {
311+
comparison = `${this._compareWith!.ref}..${this.branch.ref}`;
312+
}
313+
314+
const files = await Container.git.getDiffStatus(this.uri.repoPath!, comparison);
315+
316+
return {
317+
label: `${Strings.pluralize('file', files?.length ?? 0, { zero: 'No' })} changed`,
318+
files: files,
319+
};
320+
}
321+
292322
private loadCompareWith() {
293323
const comparisons = Container.context.workspaceState.get<BranchComparisons>(WorkspaceState.BranchComparisons);
294324

src/views/nodes/compareResultsNode.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GitRevision } from '../../git/git';
66
import { GitUri } from '../../git/gitUri';
77
import { debug, gate, log, Strings } from '../../system';
88
import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode';
9-
import { FilesQueryResults } from './resultsFilesNode';
9+
import { FilesQueryResults, ResultsFilesNode } from './resultsFilesNode';
1010
import { ContextValues, ViewNode } from './viewNode';
1111
import { RepositoryNode } from './repositoryNode';
1212
import { SearchAndCompareView } from '../searchAndCompareView';
@@ -121,6 +121,18 @@ export class CompareResultsNode extends ViewNode<SearchAndCompareView> {
121121
expand: false,
122122
},
123123
),
124+
new ResultsFilesNode(
125+
this.view,
126+
this,
127+
this.uri.repoPath!,
128+
this._ref.ref,
129+
this._compareWith.ref,
130+
this.getFilesQuery.bind(this),
131+
undefined,
132+
{
133+
expand: false,
134+
},
135+
),
124136
];
125137
}
126138
return this._children;
@@ -292,6 +304,24 @@ export class CompareResultsNode extends ViewNode<SearchAndCompareView> {
292304
};
293305
}
294306

307+
private async getFilesQuery(): Promise<FilesQueryResults> {
308+
let comparison;
309+
if (this._compareWith.ref === '') {
310+
comparison = this._ref.ref;
311+
} else if (this._ref.ref === '') {
312+
comparison = this._compareWith.ref;
313+
} else {
314+
comparison = `${this._compareWith.ref}..${this._ref.ref}`;
315+
}
316+
317+
const files = await Container.git.getDiffStatus(this.uri.repoPath!, comparison);
318+
319+
return {
320+
label: `${Strings.pluralize('file', files?.length ?? 0, { zero: 'No' })} changed`,
321+
files: files,
322+
};
323+
}
324+
295325
private updatePinned() {
296326
return this.view.updatePinned(this.getPinnableId(), {
297327
type: 'comparison',

0 commit comments

Comments
 (0)