Skip to content

Commit

Permalink
Adds compare "selection" to Graph
Browse files Browse the repository at this point in the history
 - Only works for 2 selected commits
  • Loading branch information
eamodio committed Dec 18, 2024
1 parent 9e592b7 commit 420a1c8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
13 changes: 13 additions & 0 deletions contributions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,19 @@
]
}
},
"gitlens.graph.compareSelectedCommits.multi": {
"label": "Compare Selected Commits",
"icon": "$(compare-changes)",
"menus": {
"webview/context": [
{
"when": "webviewItems =~ /gitlens:commit\\b/ && listDoubleSelection",
"group": "4_gitlens_compare",
"order": 2
}
]
}
},
"gitlens.graph.compareWithHead": {
"label": "Compare to/from HEAD",
"icon": "$(compare-changes)",
Expand Down
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6401,6 +6401,11 @@
"title": "Compare with HEAD",
"icon": "$(compare-changes)"
},
{
"command": "gitlens.graph.compareSelectedCommits.multi",
"title": "Compare Selected Commits",
"icon": "$(compare-changes)"
},
{
"command": "gitlens.graph.compareWithHead",
"title": "Compare to/from HEAD",
Expand Down Expand Up @@ -10353,6 +10358,10 @@
"command": "gitlens.graph.compareBranchWithHead",
"when": "false"
},
{
"command": "gitlens.graph.compareSelectedCommits.multi",
"when": "false"
},
{
"command": "gitlens.graph.compareWithHead",
"when": "false"
Expand Down Expand Up @@ -18502,6 +18511,11 @@
"command": "gitlens.graph.openCommitOnRemote.multi",
"when": "webviewItems =~ /gitlens:commit\\b/ && listMultiSelection && gitlens:repos:withRemotes",
"group": "3_gitlens_explore@2"
},
{
"command": "gitlens.graph.compareSelectedCommits.multi",
"when": "webviewItems =~ /gitlens:commit\\b/ && listDoubleSelection",
"group": "4_gitlens_compare@2"
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion src/constants.commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,8 @@ type GraphWebviewCommands = `graph.${
| 'openWorktree'
| 'openWorktreeInNewWindow'
| 'copyWorkingChangesToWorktree'
| 'generateCommitMessage'}`;
| 'generateCommitMessage'
| 'compareSelectedCommits.multi'}`;

type TimelineWebviewCommands = `timeline.${'refresh' | 'split'}`;

Expand Down
14 changes: 13 additions & 1 deletion src/plus/webviews/graph/graphWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,12 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
this.copyWorkingChangesToWorktree,
),
this.host.registerWebviewCommand('gitlens.graph.generateCommitMessage', this.generateCommitMessage),

this.host.registerWebviewCommand('gitlens.graph.compareSelectedCommits.multi', this.compareSelectedCommits),
);

return commands;
}

onWindowFocusChanged(focused: boolean): void {
this.isWindowFocused = focused;
}
Expand Down Expand Up @@ -3222,6 +3223,17 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
});
}

@log()
private async compareSelectedCommits(item?: GraphItemContext) {
const { selection } = this.getGraphItemRefs(item, 'revision');
if (selection == null || selection.length !== 2) return Promise.resolve();

const [commit1, commit2] = selection;
const [ref1, ref2] = await getOrderedComparisonRefs(this.container, commit1.repoPath, commit1.ref, commit2.ref);

return this.container.views.searchAndCompare.compare(commit1.repoPath, ref1, ref2);
}

@log()
private copyDeepLinkToBranch(item?: GraphItemContext) {
if (isGraphItemRefContext(item, 'branch')) {
Expand Down

0 comments on commit 420a1c8

Please sign in to comment.