Skip to content

Commit e31aed4

Browse files
committed
Adds & updates compare with merge base commands
- Adds 'Compare with Common (Merge) Base' command to review the changes if the selected branch were to be merged - Renames 'Compare Ancestry with Working Tree' to 'Compare Common (Merge) Base with Working Tree' for consistent terminology and better user understanding - Fixes issue with broken ancestor comparison
1 parent 933fd2b commit e31aed4

File tree

4 files changed

+79
-21
lines changed

4 files changed

+79
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
88

99
### Added
1010

11+
- Adds a _Compare with Common (Merge) Base_ command to branches in the _Commit Graph_ and views to review the changes if the selected branch were to be merged by comparing the common ancestor (merge base) with the current branch to the selected branch
12+
- Adds a _Stash All Changes_ command to Source Control repository toolbar (off by default)
1113
- Adds the repository name as a prefix to worktree name when adding to the current workspace
1214
- Adds a better message when stashing only untracked files without including untracked files
13-
- Adds a _Stash All Changes_ command to Source Control repository toolbar (off by default)
1415

1516
### Changed
1617

1718
- Re-adds _Add to Workspace_ option when creating a worktree — closes [#3160](https://github.com/gitkraken/vscode-gitlens/issues/3160)
1819
- Changes _Commit Graph_ date style to default to the default date style — refs [#3153](https://github.com/gitkraken/vscode-gitlens/issues/3153)
20+
- Renames the _Compare Ancestry with Working Tree_ command on branches to _Compare Common (Merge) Base with Working Tree_ for better clarity
1921
- Improves _File Blame_ annotations performance and layout accuracy with certain character sets
2022
- Improves string formatting performance
2123

@@ -25,6 +27,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
2527
- Fixes [#3152](https://github.com/gitkraken/vscode-gitlens/issues/3152) - Fixes double encoding of redirect URLs during account sign-in which affects certain environments
2628
- Fixes [#3153](https://github.com/gitkraken/vscode-gitlens/issues/3153) - `gitlens.defaultDateStyle` not working in Commit Details view
2729
- Fixes the _Open Pull Request Changes_ & _Compare Pull Request_ commands to scope the changes only to the pull request
30+
- Fixes broken _Compare Common (Merge) Base with Working Tree_ (previously _Compare Ancestry with Working Tree_)
2831
- Fixes issue when switching to a worktree via branch switch when there are multiple repos in the workspace
2932

3033
## [14.8.2] - 2024-02-16

package.json

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6743,7 +6743,12 @@
67436743
},
67446744
{
67456745
"command": "gitlens.views.compareAncestryWithWorking",
6746-
"title": "Compare Ancestry with Working Tree",
6746+
"title": "Compare Common (Merge) Base with Working Tree",
6747+
"category": "GitLens"
6748+
},
6749+
{
6750+
"command": "gitlens.views.compareWithMergeBase",
6751+
"title": "Compare with Common (Merge) Base",
67476752
"category": "GitLens"
67486753
},
67496754
{
@@ -8399,7 +8404,12 @@
83998404
},
84008405
{
84018406
"command": "gitlens.graph.compareAncestryWithWorking",
8402-
"title": "Compare Ancestry with Working Tree",
8407+
"title": "Compare Common (Merge) Base with Working Tree",
8408+
"category": "GitLens"
8409+
},
8410+
{
8411+
"command": "gitlens.graph.compareWithMergeBase",
8412+
"title": "Compare with Common (Merge) Base",
84038413
"category": "GitLens"
84048414
},
84058415
{
@@ -10038,6 +10048,10 @@
1003810048
"command": "gitlens.views.compareAncestryWithWorking",
1003910049
"when": "false"
1004010050
},
10051+
{
10052+
"command": "gitlens.views.compareWithMergeBase",
10053+
"when": "false"
10054+
},
1004110055
{
1004210056
"command": "gitlens.views.compareWithHead",
1004310057
"when": "false"
@@ -11182,6 +11196,10 @@
1118211196
"command": "gitlens.graph.compareAncestryWithWorking",
1118311197
"when": "false"
1118411198
},
11199+
{
11200+
"command": "gitlens.graph.compareWithMergeBase",
11201+
"when": "false"
11202+
},
1118511203
{
1118611204
"command": "gitlens.graph.compareWithHead",
1118711205
"when": "false"
@@ -12962,10 +12980,15 @@
1296212980
"group": "4_gitlens_compare@3"
1296312981
},
1296412982
{
12965-
"command": "gitlens.views.compareAncestryWithWorking",
12983+
"command": "gitlens.views.compareWithMergeBase",
1296612984
"when": "!gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
1296712985
"group": "4_gitlens_compare@4"
1296812986
},
12987+
{
12988+
"command": "gitlens.views.compareAncestryWithWorking",
12989+
"when": "!gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
12990+
"group": "4_gitlens_compare@5"
12991+
},
1296912992
{
1297012993
"command": "gitlens.views.compareWithSelected",
1297112994
"when": "!gitlens:hasVirtualFolders && viewItem =~ /gitlens:(branch|commit|stash|tag)\\b/ && gitlens:views:canCompare",
@@ -14573,10 +14596,15 @@
1457314596
"group": "4_gitlens_compare@3"
1457414597
},
1457514598
{
14576-
"command": "gitlens.graph.compareAncestryWithWorking",
14599+
"command": "gitlens.graph.compareWithMergeBase",
1457714600
"when": "!gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
1457814601
"group": "4_gitlens_compare@4"
1457914602
},
14603+
{
14604+
"command": "gitlens.graph.compareAncestryWithWorking",
14605+
"when": "!gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
14606+
"group": "4_gitlens_compare@5"
14607+
},
1458014608
{
1458114609
"command": "gitlens.graph.addAuthor",
1458214610
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:contributor\\b(?!.*?\\b\\+current\\b)/",

src/plus/webviews/graph/graphWebview.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
466466
this.host.registerWebviewCommand('gitlens.graph.compareWithUpstream', this.compareWithUpstream),
467467
this.host.registerWebviewCommand('gitlens.graph.compareWithHead', this.compareHeadWith),
468468
this.host.registerWebviewCommand('gitlens.graph.compareWithWorking', this.compareWorkingWith),
469+
this.host.registerWebviewCommand('gitlens.graph.compareWithMergeBase', this.compareWithMergeBase),
469470
this.host.registerWebviewCommand(
470471
'gitlens.graph.compareAncestryWithWorking',
471472
this.compareAncestryWithWorking,
@@ -2748,14 +2749,10 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
27482749
const commonAncestor = await this.container.git.getMergeBase(ref.repoPath, branch.ref, ref.ref);
27492750
if (commonAncestor == null) return undefined;
27502751

2751-
return this.container.searchAndCompareView.compare(
2752-
ref.repoPath,
2753-
{
2754-
ref: commonAncestor,
2755-
label: `ancestry with ${ref.ref} (${shortenRevision(commonAncestor)})`,
2756-
},
2757-
'',
2758-
);
2752+
return this.container.searchAndCompareView.compare(ref.repoPath, '', {
2753+
ref: commonAncestor,
2754+
label: `${branch.ref} (${shortenRevision(commonAncestor)})`,
2755+
});
27592756
}
27602757

27612758
@debug()
@@ -2766,6 +2763,23 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
27662763
return this.container.searchAndCompareView.compare(ref.repoPath, 'HEAD', ref.ref);
27672764
}
27682765

2766+
@debug()
2767+
private async compareWithMergeBase(item?: GraphItemContext) {
2768+
const ref = this.getGraphItemRef(item);
2769+
if (ref == null) return Promise.resolve();
2770+
2771+
const branch = await this.container.git.getBranch(ref.repoPath);
2772+
if (branch == null) return undefined;
2773+
2774+
const commonAncestor = await this.container.git.getMergeBase(ref.repoPath, branch.ref, ref.ref);
2775+
if (commonAncestor == null) return undefined;
2776+
2777+
return this.container.searchAndCompareView.compare(ref.repoPath, ref.ref, {
2778+
ref: commonAncestor,
2779+
label: `${branch.ref} (${shortenRevision(commonAncestor)})`,
2780+
});
2781+
}
2782+
27692783
@debug()
27702784
private compareWithUpstream(item?: GraphItemContext) {
27712785
if (isGraphItemRefContext(item, 'branch')) {

src/views/viewCommands.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export class ViewCommands {
255255

256256
registerViewCommand('gitlens.views.compareAncestryWithWorking', this.compareAncestryWithWorking, this);
257257
registerViewCommand('gitlens.views.compareWithHead', this.compareHeadWith, this);
258+
registerViewCommand('gitlens.views.compareWithMergeBase', this.compareWithMergeBase, this);
258259
registerViewCommand('gitlens.views.compareWithUpstream', this.compareWithUpstream, this);
259260
registerViewCommand('gitlens.views.compareWithSelected', this.compareWithSelected, this);
260261
registerViewCommand('gitlens.views.selectForCompare', this.selectForCompare, this);
@@ -930,6 +931,22 @@ export class ViewCommands {
930931
return this.container.searchAndCompareView.compare(node.repoPath, 'HEAD', node.ref);
931932
}
932933

934+
@log()
935+
private async compareWithMergeBase(node: BranchNode) {
936+
if (!node.is('branch')) return Promise.resolve();
937+
938+
const branch = await this.container.git.getBranch(node.repoPath);
939+
if (branch == null) return undefined;
940+
941+
const commonAncestor = await this.container.git.getMergeBase(node.repoPath, branch.ref, node.ref.ref);
942+
if (commonAncestor == null) return undefined;
943+
944+
return this.container.searchAndCompareView.compare(node.repoPath, node.ref.ref, {
945+
ref: commonAncestor,
946+
label: `${branch.ref} (${shortenRevision(commonAncestor)})`,
947+
});
948+
}
949+
933950
@log()
934951
private compareWithUpstream(node: BranchNode) {
935952
if (!node.is('branch') || node.branch.upstream == null) return Promise.resolve();
@@ -958,14 +975,10 @@ export class ViewCommands {
958975
const commonAncestor = await this.container.git.getMergeBase(node.repoPath, branch.ref, node.ref.ref);
959976
if (commonAncestor == null) return undefined;
960977

961-
return this.container.searchAndCompareView.compare(
962-
node.repoPath,
963-
{
964-
ref: commonAncestor,
965-
label: `ancestry with ${node.ref.ref} (${shortenRevision(commonAncestor)})`,
966-
},
967-
'',
968-
);
978+
return this.container.searchAndCompareView.compare(node.repoPath, '', {
979+
ref: commonAncestor,
980+
label: `${branch.ref} (${shortenRevision(commonAncestor)})`,
981+
});
969982
}
970983

971984
@log()

0 commit comments

Comments
 (0)