Skip to content

Commit 1ed9017

Browse files
committed
Closes #4779 adds arbitrary comparison support
- Adds "Select for Compare"/"Compare with Selected" to the Graph context menu for commits, stashes, branches, and tags
1 parent 07c3afc commit 1ed9017

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

contributions.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8234,6 +8234,18 @@
82348234
]
82358235
}
82368236
},
8237+
"gitlens.views.compareWithSelected:graph": {
8238+
"label": "Compare with Selected",
8239+
"menus": {
8240+
"webview/context": [
8241+
{
8242+
"when": "webviewItem =~ /gitlens:(branch|commit|stash|tag)\\b/ && !listMultiSelection && gitlens:views:canCompare",
8243+
"group": "4_gitlens_compare",
8244+
"order": 98
8245+
}
8246+
]
8247+
}
8248+
},
82378249
"gitlens.views.compareWithUpstream": {
82388250
"label": "Compare with Upstream",
82398251
"menus": {
@@ -15165,6 +15177,18 @@
1516515177
]
1516615178
}
1516715179
},
15180+
"gitlens.views.selectForCompare:graph": {
15181+
"label": "Select for Compare",
15182+
"menus": {
15183+
"webview/context": [
15184+
{
15185+
"when": "webviewItem =~ /gitlens:(branch|commit|stash|tag)\\b/ && !listMultiSelection",
15186+
"group": "4_gitlens_compare",
15187+
"order": 99
15188+
}
15189+
]
15190+
}
15191+
},
1516815192
"gitlens.views.setAsDefault": {
1516915193
"label": "Set as Default",
1517015194
"menus": {

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8971,6 +8971,10 @@
89718971
"command": "gitlens.views.compareWithSelected",
89728972
"title": "Compare with Selected"
89738973
},
8974+
{
8975+
"command": "gitlens.views.compareWithSelected:graph",
8976+
"title": "Compare with Selected"
8977+
},
89748978
{
89758979
"command": "gitlens.views.compareWithUpstream",
89768980
"title": "Compare with Upstream"
@@ -10571,6 +10575,10 @@
1057110575
"command": "gitlens.views.selectForCompare",
1057210576
"title": "Select for Compare"
1057310577
},
10578+
{
10579+
"command": "gitlens.views.selectForCompare:graph",
10580+
"title": "Select for Compare"
10581+
},
1057410582
{
1057510583
"command": "gitlens.views.setAsDefault",
1057610584
"title": "Set as Default"
@@ -13688,6 +13696,10 @@
1368813696
"command": "gitlens.views.compareWithSelected",
1368913697
"when": "false"
1369013698
},
13699+
{
13700+
"command": "gitlens.views.compareWithSelected:graph",
13701+
"when": "false"
13702+
},
1369113703
{
1369213704
"command": "gitlens.views.compareWithUpstream",
1369313705
"when": "false"
@@ -15024,6 +15036,10 @@
1502415036
"command": "gitlens.views.selectForCompare",
1502515037
"when": "false"
1502615038
},
15039+
{
15040+
"command": "gitlens.views.selectForCompare:graph",
15041+
"when": "false"
15042+
},
1502715043
{
1502815044
"command": "gitlens.views.setAsDefault",
1502915045
"when": "false"
@@ -24871,6 +24887,16 @@
2487124887
"when": "webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/ && !gitlens:hasVirtualFolders",
2487224888
"group": "4_gitlens_compare@5"
2487324889
},
24890+
{
24891+
"command": "gitlens.views.compareWithSelected:graph",
24892+
"when": "webviewItem =~ /gitlens:(branch|commit|stash|tag)\\b/ && !listMultiSelection && gitlens:views:canCompare",
24893+
"group": "4_gitlens_compare@98"
24894+
},
24895+
{
24896+
"command": "gitlens.views.selectForCompare:graph",
24897+
"when": "webviewItem =~ /gitlens:(branch|commit|stash|tag)\\b/ && !listMultiSelection",
24898+
"group": "4_gitlens_compare@99"
24899+
},
2487424900
{
2487524901
"submenu": "gitlens/share",
2487624902
"when": "webviewItem =~ /gitlens:(branch|commit|stash|tag|file\\b(?=.*?\\b\\+(committed|staged|unstaged)\\b))\\b/",

src/constants.commands.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ export type ContributedCommands =
398398
| 'gitlens.views.compareWithHead'
399399
| 'gitlens.views.compareWithMergeBase'
400400
| 'gitlens.views.compareWithSelected'
401+
| 'gitlens.views.compareWithSelected:graph'
401402
| 'gitlens.views.compareWithUpstream'
402403
| 'gitlens.views.compareWithWorking'
403404
| 'gitlens.views.contributors.attach'
@@ -723,6 +724,7 @@ export type ContributedCommands =
723724
| 'gitlens.views.selectFileForCompare:commitDetails'
724725
| 'gitlens.views.selectFileForCompare:graphDetails'
725726
| 'gitlens.views.selectForCompare'
727+
| 'gitlens.views.selectForCompare:graph'
726728
| 'gitlens.views.setAsDefault'
727729
| 'gitlens.views.setBranchComparisonToBranch'
728730
| 'gitlens.views.setBranchComparisonToWorking'

src/webviews/plus/graph/graphWebview.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ import {
126126
registerCommand,
127127
} from '../../../system/-webview/command';
128128
import { configuration } from '../../../system/-webview/configuration';
129-
import { getContext, onDidChangeContext } from '../../../system/-webview/context';
129+
import { getContext, onDidChangeContext, setContext } from '../../../system/-webview/context';
130130
import type { StorageChangeEvent } from '../../../system/-webview/storage';
131131
import { isDarkTheme, isLightTheme } from '../../../system/-webview/vscode';
132132
import type { OpenWorkspaceLocation } from '../../../system/-webview/vscode/workspaces';
@@ -639,6 +639,9 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
639639
this.compareAncestryWithWorking,
640640
),
641641

642+
this.host.registerWebviewCommand('gitlens.views.selectForCompare:graph', this.selectForCompare),
643+
this.host.registerWebviewCommand('gitlens.views.compareWithSelected:graph', this.compareWithSelected),
644+
642645
this.host.registerWebviewCommand('gitlens.graph.copy', this.copy),
643646
this.host.registerWebviewCommand('gitlens.graph.copyMessage', this.copyMessage),
644647
this.host.registerWebviewCommand('gitlens.graph.copySha', this.copySha),
@@ -4397,6 +4400,35 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
43974400
return this.container.views.searchAndCompare.compare(ref.repoPath, '', ref.ref);
43984401
}
43994402

4403+
@log()
4404+
private selectForCompare(item?: GraphItemContext) {
4405+
const ref = this.getGraphItemRef(item);
4406+
if (ref == null) return;
4407+
4408+
void setContext('gitlens:views:canCompare', { label: ref.name, ref: ref.ref, repoPath: ref.repoPath });
4409+
}
4410+
4411+
@log()
4412+
private compareWithSelected(item?: GraphItemContext) {
4413+
const ref = this.getGraphItemRef(item);
4414+
if (ref == null) return;
4415+
4416+
const selectedRef = getContext('gitlens:views:canCompare');
4417+
if (selectedRef == null) return;
4418+
4419+
void setContext('gitlens:views:canCompare', undefined);
4420+
4421+
if (selectedRef.repoPath !== ref.repoPath) {
4422+
this.selectForCompare(item);
4423+
return;
4424+
}
4425+
4426+
void this.container.views.searchAndCompare.compare(ref.repoPath, selectedRef, {
4427+
label: ref.name,
4428+
ref: ref.ref,
4429+
});
4430+
}
4431+
44004432
@log()
44014433
private copyWorkingChangesToWorktree(item?: GraphItemContext) {
44024434
const ref = this.getGraphItemRef(item);

0 commit comments

Comments
 (0)