From 2c3fad5d9903660e82724bf99270700a5f18c2a7 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 22 Nov 2020 22:43:54 -0500 Subject: [PATCH] Fixes #1161, #1157 - re-adds file comparison --- CHANGELOG.md | 7 +++++++ README.md | 15 +++++++++------ src/views/nodes/compareBranchNode.ts | 32 +++++++++++++++++++++++++++++++- src/views/nodes/compareResultsNode.ts | 32 +++++++++++++++++++++++++++++++- 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d493ab1..39b1af0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Fixed + +- Fixes [#1161](https://github.com/eamodio/vscode-gitlens/issues/1161) - Compare file differences between branches +- 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.3] - 2020-11-22 ### Fixed diff --git a/README.md b/README.md index 70a6393..08812d8 100644 --- a/README.md +++ b/README.md @@ -252,9 +252,10 @@ The _Commits_ view lists all of the commits on the current branch, and additiona - a toggle to change the file layout: list, tree, auto - 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 - **Behind** — lists the commits that are missing from the current branch (i.e. behind) but exist in the selected reference - - **# files changed** — lists all of the files changed between the compared references + - **# files changed** — lists all of the files changed in the behind commits - **Ahead** — lists the commits that the current branch has (i.e. ahead) but are missing in the selected reference - - **# files changed** — lists all of the files changed between the compared references + - **# files changed** — lists all of the files changed in the ahead commits + - **# files changed** — lists all of the files changed between the compared references - the current branch status — shows the upstream status of the current branch - **Publish <current branch> to <remote>** — shown when the current branch has not been published to a remote - **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, - _Yellow dot_ — both unpublished and un-pulled changes - 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 - **Behind** — lists the commits that are missing from the branch (i.e. behind) but exist in the selected reference - - **# files changed** — lists all of the files changed between the compared references + - **# files changed** — lists all of the files changed in the behind commits - **Ahead** — lists the commits that the branch has (i.e. ahead) but are missing in the selected reference - - **# files changed** — lists all of the files changed between the compared references + - **# files changed** — lists all of the files changed in the ahead commits + - **# files changed** — lists all of the files changed between the compared references - the branch status — shows the upstream status of the branch - **Publish <branch> to <remote>** — shown when the current branch has not been published to a remote - **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 - _Show Commit_ command (`gitlens.showQuickCommitDetails`) - pinnable comparison — shows a comparison of the two user-selected references - **Behind** — lists the commits that are missing from the branch (i.e. behind) but exist in the selected reference - - **# files changed** — lists all of the files changed between the compared references + - **# files changed** — lists all of the files changed in the behind commits - **Ahead** — lists the commits that the branch has (i.e. ahead) but are missing in the selected reference - - **# files changed** — lists all of the files changed between the compared references + - **# files changed** — lists all of the files changed in the ahead commits + - **# files changed** — lists all of the files changed between the compared references - Comparision results can be provided by the following commands - _Compare with Upstream_ command (`gitlens.views.compareWithUpstream`) - _Compare with Working Tree_ command (`gitlens.views.compareWithWorking`) diff --git a/src/views/nodes/compareBranchNode.ts b/src/views/nodes/compareBranchNode.ts index 9accc2b..574b02b 100644 --- a/src/views/nodes/compareBranchNode.ts +++ b/src/views/nodes/compareBranchNode.ts @@ -11,7 +11,7 @@ import { CommandQuickPickItem, ReferencePicker } from '../../quickpicks'; import { RepositoriesView } from '../repositoriesView'; import { RepositoryNode } from './repositoryNode'; import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode'; -import { FilesQueryResults } from './resultsFilesNode'; +import { FilesQueryResults, ResultsFilesNode } from './resultsFilesNode'; import { debug, gate, log, Strings } from '../../system'; import { ContextValues, ViewNode } from './viewNode'; @@ -115,6 +115,18 @@ export class CompareBranchNode extends ViewNode { + let comparison; + if (this._compareWith!.ref === '') { + comparison = this.branch.ref; + } else if (this.compareWithWorkingTree) { + comparison = this._compareWith!.ref; + } else { + comparison = `${this._compareWith!.ref}..${this.branch.ref}`; + } + + const files = await Container.git.getDiffStatus(this.uri.repoPath!, comparison); + + return { + label: `${Strings.pluralize('file', files?.length ?? 0, { zero: 'No' })} changed`, + files: files, + }; + } + private loadCompareWith() { const comparisons = Container.context.workspaceState.get(WorkspaceState.BranchComparisons); diff --git a/src/views/nodes/compareResultsNode.ts b/src/views/nodes/compareResultsNode.ts index c1c3b74..e36f4a5 100644 --- a/src/views/nodes/compareResultsNode.ts +++ b/src/views/nodes/compareResultsNode.ts @@ -6,7 +6,7 @@ import { GitRevision } from '../../git/git'; import { GitUri } from '../../git/gitUri'; import { debug, gate, log, Strings } from '../../system'; import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode'; -import { FilesQueryResults } from './resultsFilesNode'; +import { FilesQueryResults, ResultsFilesNode } from './resultsFilesNode'; import { ContextValues, ViewNode } from './viewNode'; import { RepositoryNode } from './repositoryNode'; import { SearchAndCompareView } from '../searchAndCompareView'; @@ -121,6 +121,18 @@ export class CompareResultsNode extends ViewNode { expand: false, }, ), + new ResultsFilesNode( + this.view, + this, + this.uri.repoPath!, + this._ref.ref, + this._compareWith.ref, + this.getFilesQuery.bind(this), + undefined, + { + expand: false, + }, + ), ]; } return this._children; @@ -292,6 +304,24 @@ export class CompareResultsNode extends ViewNode { }; } + private async getFilesQuery(): Promise { + let comparison; + if (this._compareWith.ref === '') { + comparison = this._ref.ref; + } else if (this._ref.ref === '') { + comparison = this._compareWith.ref; + } else { + comparison = `${this._compareWith.ref}..${this._ref.ref}`; + } + + const files = await Container.git.getDiffStatus(this.uri.repoPath!, comparison); + + return { + label: `${Strings.pluralize('file', files?.length ?? 0, { zero: 'No' })} changed`, + files: files, + }; + } + private updatePinned() { return this.view.updatePinned(this.getPinnableId(), { type: 'comparison',