diff --git a/extensions/git/package.json b/extensions/git/package.json index d18cdba8057..754cf5758ac 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -495,6 +495,16 @@ "title": "%command.timelineCopyCommitMessage%", "category": "Git" }, + { + "command": "git.timeline.selectForCompare", + "title": "%command.timelineSelectForCompare%", + "category": "Git" + }, + { + "command": "git.timeline.compareWithSelected", + "title": "%command.timelineCompareWithSelected%", + "category": "Git" + }, { "command": "git.rebaseAbort", "title": "%command.rebaseAbort%", @@ -874,6 +884,18 @@ { "command": "git.timeline.copyCommitMessage", "when": "false" + }, + { + "command": "git.timeline.selectForCompare", + "when": "false" + }, + { + "command": "git.timeline.compareWithSelected", + "when": "false" + }, + { + "command": "git.timeline.compareSelected", + "when": "false" } ], "scm/title": [ @@ -1349,17 +1371,27 @@ { "command": "git.timeline.openDiff", "group": "1_actions", - "when": "config.git.enabled && !git.missing && timelineItem =~ /git:file\\b/" + "when": "config.git.enabled && !git.missing && timelineItem =~ /git:file\\b/ && !listMultiSelection" + }, + { + "command": "git.timeline.compareWithSelected", + "group": "3_compare@1", + "when": "config.git.enabled && !git.missing && git.timeline.selectedForCompare && timelineItem =~ /git:file\\b/ && !listMultiSelection" + }, + { + "command": "git.timeline.selectForCompare", + "group": "3_compare@2", + "when": "config.git.enabled && !git.missing && timelineItem =~ /git:file\\b/ && !listMultiSelection" }, { "command": "git.timeline.copyCommitId", "group": "5_copy@1", - "when": "config.git.enabled && !git.missing && timelineItem =~ /git:file:commit\\b/" + "when": "config.git.enabled && !git.missing && timelineItem =~ /git:file:commit\\b/ && !listMultiSelection" }, { "command": "git.timeline.copyCommitMessage", "group": "5_copy@2", - "when": "config.git.enabled && !git.missing && timelineItem =~ /git:file:commit\\b/" + "when": "config.git.enabled && !git.missing && timelineItem =~ /git:file:commit\\b/ && !listMultiSelection" } ], "git.commit": [ diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 394a326c0a7..3eac8e0783e 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -90,6 +90,8 @@ "command.timelineOpenDiff": "Open Changes", "command.timelineCopyCommitId": "Copy Commit ID", "command.timelineCopyCommitMessage": "Copy Commit Message", + "command.timelineSelectForCompare": "Select for Compare", + "command.timelineCompareWithSelected": "Compare with Selected", "config.enabled": "Whether git is enabled.", "config.path": "Path and filename of the git executable, e.g. `C:\\Program Files\\Git\\bin\\git.exe` (Windows). This can also be an array of string values containing multiple paths to look up.", "config.autoRepositoryDetection": "Configures when repositories should be automatically detected.", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index aabea31a725..9ded16f3e77 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -2669,6 +2669,52 @@ export class CommandCenter { env.clipboard.writeText(item.message); } + private _selectedForCompare: { uri: Uri, item: GitTimelineItem } | undefined; + + @command('git.timeline.selectForCompare', { repository: false }) + async timelineSelectForCompare(item: TimelineItem, uri: Uri | undefined, _source: string) { + if (!GitTimelineItem.is(item) || !uri) { + return; + } + + this._selectedForCompare = { uri, item }; + await commands.executeCommand('setContext', 'git.timeline.selectedForCompare', true); + } + + @command('git.timeline.compareWithSelected', { repository: false }) + async timelineCompareWithSelected(item: TimelineItem, uri: Uri | undefined, _source: string) { + if (!GitTimelineItem.is(item) || !uri || !this._selectedForCompare || uri.toString() !== this._selectedForCompare.uri.toString()) { + return; + } + + const { item: selected } = this._selectedForCompare; + + const basename = path.basename(uri.fsPath); + let leftTitle; + if ((selected.previousRef === 'HEAD' || selected.previousRef === '~') && selected.ref === '') { + leftTitle = localize('git.title.workingTree', '{0} (Working Tree)', basename); + } + else if (selected.previousRef === 'HEAD' && selected.ref === '~') { + leftTitle = localize('git.title.index', '{0} (Index)', basename); + } else { + leftTitle = localize('git.title.ref', '{0} ({1})', basename, selected.shortRef); + } + + let rightTitle; + if ((item.previousRef === 'HEAD' || item.previousRef === '~') && item.ref === '') { + rightTitle = localize('git.title.workingTree', '{0} (Working Tree)', basename); + } + else if (item.previousRef === 'HEAD' && item.ref === '~') { + rightTitle = localize('git.title.index', '{0} (Index)', basename); + } else { + rightTitle = localize('git.title.ref', '{0} ({1})', basename, item.shortRef); + } + + + const title = localize('git.title.diff', '{0} ⟷ {1}', leftTitle, rightTitle); + await commands.executeCommand('vscode.diff', selected.ref === '' ? uri : toGitUri(uri, selected.ref), item.ref === '' ? uri : toGitUri(uri, item.ref), title); + } + @command('git.rebaseAbort', { repository: true }) async rebaseAbort(repository: Repository): Promise { if (repository.rebaseCommit) { diff --git a/src/vs/workbench/contrib/timeline/browser/timelinePane.ts b/src/vs/workbench/contrib/timeline/browser/timelinePane.ts index a0b5aa73388..d98dba05b91 100644 --- a/src/vs/workbench/contrib/timeline/browser/timelinePane.ts +++ b/src/vs/workbench/contrib/timeline/browser/timelinePane.ts @@ -908,7 +908,6 @@ export class TimelinePane extends ViewPane { item = selection[0]; } - // const item = e.element; if (item === null) { return; } @@ -923,8 +922,6 @@ export class TimelinePane extends ViewPane { } this.commandService.executeCommand(item.command.id, ...args); - - // this.commandService.executeCommand(item.command.id, ...(item.command.arguments || [])); } } else if (isLoadMoreCommand(item)) {