Skip to content

Commit f955407

Browse files
authored
Git - add dedicated commands to view changes (microsoft#209942)
1 parent 5d77214 commit f955407

File tree

6 files changed

+90
-22
lines changed

6 files changed

+90
-22
lines changed

extensions/git/package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,27 @@
856856
"title": "%command.openRepositoriesInParentFolders%",
857857
"category": "Git"
858858
},
859+
{
860+
"command": "git.viewChanges",
861+
"title": "%command.viewChanges%",
862+
"icon": "$(diff-multiple)",
863+
"category": "Git",
864+
"enablement": "!operationInProgress"
865+
},
866+
{
867+
"command": "git.viewStagedChanges",
868+
"title": "%command.viewStagedChanges%",
869+
"icon": "$(diff-multiple)",
870+
"category": "Git",
871+
"enablement": "!operationInProgress"
872+
},
873+
{
874+
"command": "git.viewUntrackedChanges",
875+
"title": "%command.viewUntrackedChanges%",
876+
"icon": "$(diff-multiple)",
877+
"category": "Git",
878+
"enablement": "!operationInProgress"
879+
},
859880
{
860881
"command": "git.viewCommit",
861882
"title": "%command.viewCommit%",
@@ -1511,6 +1532,16 @@
15111532
"when": "scmProvider == git && scmResourceGroup == index",
15121533
"group": "inline@2"
15131534
},
1535+
{
1536+
"command": "git.viewStagedChanges",
1537+
"when": "scmProvider == git && scmResourceGroup == index && config.multiDiffEditor.experimental.enabled",
1538+
"group": "inline@1"
1539+
},
1540+
{
1541+
"command": "git.viewChanges",
1542+
"when": "scmProvider == git && scmResourceGroup == workingTree && config.multiDiffEditor.experimental.enabled",
1543+
"group": "inline@1"
1544+
},
15141545
{
15151546
"command": "git.cleanAll",
15161547
"when": "scmProvider == git && scmResourceGroup == workingTree && config.git.untrackedChanges == mixed",
@@ -1561,6 +1592,11 @@
15611592
"when": "scmProvider == git && scmResourceGroup == untracked",
15621593
"group": "1_modification"
15631594
},
1595+
{
1596+
"command": "git.viewUntrackedChanges",
1597+
"when": "scmProvider == git && scmResourceGroup == untracked && config.multiDiffEditor.experimental.enabled",
1598+
"group": "inline@1"
1599+
},
15641600
{
15651601
"command": "git.cleanAllUntracked",
15661602
"when": "scmProvider == git && scmResourceGroup == untracked",

extensions/git/package.nls.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
"command.timelineCompareWithSelected": "Compare with Selected",
119119
"command.manageUnsafeRepositories": "Manage Unsafe Repositories",
120120
"command.openRepositoriesInParentFolders": "Open Repositories In Parent Folders",
121+
"command.viewChanges": "View Changes",
122+
"command.viewStagedChanges": "View Staged Changes",
123+
"command.viewUntrackedChanges": "View Untracked Changes",
121124
"command.viewAllChanges": "View All Changes",
122125
"command.viewCommit": "View Commit",
123126
"command.api.getRepositories": "Get Repositories",

extensions/git/src/commands.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { uniqueNamesGenerator, adjectives, animals, colors, NumberDictionary } f
1111
import { ForcePushMode, GitErrorCodes, Ref, RefType, Status, CommitOptions, RemoteSourcePublisher, Remote } from './api/git';
1212
import { Git, Stash } from './git';
1313
import { Model } from './model';
14-
import { Repository, Resource, ResourceGroupType } from './repository';
14+
import { GitResourceGroup, Repository, Resource, ResourceGroupType } from './repository';
1515
import { DiffEditorSelectionHunkToolbarContext, applyLineChanges, getModifiedRange, intersectDiffWithRange, invertLineChange, toLineRanges } from './staging';
1616
import { fromGitUri, toGitUri, isGitUri, toMergeUris, toMultiFileDiffEditorUris } from './uri';
1717
import { dispose, grep, isDefined, isDescendant, pathEquals, relativePath } from './util';
@@ -4143,6 +4143,33 @@ export class CommandCenter {
41434143
}
41444144
}
41454145

4146+
@command('git.viewChanges', { repository: true })
4147+
async viewChanges(repository: Repository): Promise<void> {
4148+
await this._viewResourceGroupChanges(repository, repository.workingTreeGroup);
4149+
}
4150+
4151+
@command('git.viewStagedChanges', { repository: true })
4152+
async viewStagedChanges(repository: Repository): Promise<void> {
4153+
await this._viewResourceGroupChanges(repository, repository.indexGroup);
4154+
}
4155+
4156+
@command('git.viewUntrackedChanges', { repository: true })
4157+
async viewUnstagedChanges(repository: Repository): Promise<void> {
4158+
await this._viewResourceGroupChanges(repository, repository.untrackedGroup);
4159+
}
4160+
4161+
private async _viewResourceGroupChanges(repository: Repository, resourceGroup: GitResourceGroup): Promise<void> {
4162+
if (resourceGroup.resourceStates.length === 0) {
4163+
return;
4164+
}
4165+
4166+
await commands.executeCommand('_workbench.openScmMultiDiffEditor', {
4167+
title: `${repository.sourceControl.label}: ${resourceGroup.label}`,
4168+
repositoryUri: Uri.file(repository.root),
4169+
resourceGroupId: resourceGroup.id
4170+
});
4171+
}
4172+
41464173
@command('git.viewCommit', { repository: true })
41474174
async viewCommit(repository: Repository, historyItem: SourceControlHistoryItem): Promise<void> {
41484175
if (!repository || !historyItem) {

src/vs/workbench/browser/parts/editor/editorCommands.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,11 @@ function registerOpenEditorAPICommands(): void {
527527
label: options.title,
528528
});
529529
});
530+
531+
CommandsRegistry.registerCommand('_workbench.openScmMultiDiffEditor', async (accessor: ServicesAccessor, options: OpenScmMultiFileDiffEditorOptions) => {
532+
const commandService = accessor.get(ICommandService);
533+
await commandService.executeCommand('multiDiffEditor.openScmDiff', options.title, URI.revive(options.repositoryUri), options.resourceGroupId);
534+
});
530535
}
531536

532537
interface OpenMultiFileDiffEditorOptions {
@@ -535,6 +540,12 @@ interface OpenMultiFileDiffEditorOptions {
535540
resources?: { originalUri: UriComponents; modifiedUri: UriComponents }[];
536541
}
537542

543+
interface OpenScmMultiFileDiffEditorOptions {
544+
title: string;
545+
repositoryUri: UriComponents;
546+
resourceGroupId: string;
547+
}
548+
538549
function registerOpenEditorAtIndexCommands(): void {
539550
const openEditorAtIndex: ICommandHandler = (accessor: ServicesAccessor, editorIndex: number): void => {
540551
const editorService = accessor.get(IEditorService);

src/vs/workbench/contrib/multiDiffEditor/browser/scmMultiDiffSourceResolver.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Codicon } from 'vs/base/common/codicons';
76
import { Disposable } from 'vs/base/common/lifecycle';
87
import { observableFromEvent, waitForState } from 'vs/base/common/observable';
98
import { ValueWithChangeEventFromObservable } from 'vs/base/common/observableInternal/utils';
109
import { URI } from 'vs/base/common/uri';
1110
import { IMultiDiffEditorOptions } from 'vs/editor/browser/widget/multiDiffEditor/multiDiffEditorWidgetImpl';
12-
import { localize, localize2 } from 'vs/nls';
13-
import { Action2, MenuId } from 'vs/platform/actions/common/actions';
14-
import { ContextKeyExpr, ContextKeyValue } from 'vs/platform/contextkey/common/contextkey';
11+
import { localize2 } from 'vs/nls';
12+
import { Action2 } from 'vs/platform/actions/common/actions';
13+
import { ContextKeyValue } from 'vs/platform/contextkey/common/contextkey';
1514
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1615
import { IMultiDiffSourceResolver, IMultiDiffSourceResolverService, IResolvedMultiDiffSource, MultiDiffEditorItem } from 'vs/workbench/contrib/multiDiffEditor/browser/multiDiffSourceResolverService';
1716
import { ISCMRepository, ISCMResourceGroup, ISCMService } from 'vs/workbench/contrib/scm/common/scm';
@@ -112,35 +111,25 @@ export class ScmMultiDiffSourceResolverContribution extends Disposable {
112111
}
113112

114113
export class OpenScmGroupAction extends Action2 {
115-
public static async openMultiFileDiffEditor(group: ISCMResourceGroup, editorService: IEditorService, options?: IMultiDiffEditorOptions) {
116-
if (!group.provider.rootUri) {
114+
public static async openMultiFileDiffEditor(editorService: IEditorService, label: string, repositoryRootUri: URI | undefined, resourceGroupId: string, options?: IMultiDiffEditorOptions) {
115+
if (!repositoryRootUri) {
117116
return;
118117
}
119118

120-
const multiDiffSource = ScmMultiDiffSourceResolver.getMultiDiffSourceUri(group.provider.rootUri.toString(), group.id);
121-
const label = localize('scmDiffLabel', '{0}: {1}', group.provider.label, group.label);
119+
const multiDiffSource = ScmMultiDiffSourceResolver.getMultiDiffSourceUri(repositoryRootUri.toString(), resourceGroupId);
122120
return await editorService.openEditor({ label, multiDiffSource, options });
123121
}
124122

125123
constructor() {
126124
super({
127125
id: 'multiDiffEditor.openScmDiff',
128126
title: localize2('viewChanges', 'View Changes'),
129-
icon: Codicon.diffMultiple,
130-
menu: {
131-
when: ContextKeyExpr.and(
132-
ContextKeyExpr.has('config.multiDiffEditor.experimental.enabled'),
133-
ContextKeyExpr.has('multiDiffEditorEnableViewChanges'),
134-
),
135-
id: MenuId.SCMResourceGroupContext,
136-
group: 'inline',
137-
},
138-
f1: false,
127+
f1: false
139128
});
140129
}
141130

142-
async run(accessor: ServicesAccessor, group: ISCMResourceGroup): Promise<void> {
131+
async run(accessor: ServicesAccessor, title: string, repositoryRootUri: URI, resourceGroupId: string): Promise<void> {
143132
const editorService = accessor.get(IEditorService);
144-
await OpenScmGroupAction.openMultiFileDiffEditor(group, editorService);
133+
await OpenScmGroupAction.openMultiFileDiffEditor(editorService, title, repositoryRootUri, resourceGroupId);
145134
}
146135
}

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3093,7 +3093,9 @@ export class SCMViewPane extends ViewPane {
30933093
} else if (isSCMResource(e.element)) {
30943094
if (e.element.command?.id === API_OPEN_EDITOR_COMMAND_ID || e.element.command?.id === API_OPEN_DIFF_EDITOR_COMMAND_ID) {
30953095
if (isPointerEvent(e.browserEvent) && e.browserEvent.button === 1) {
3096-
await OpenScmGroupAction.openMultiFileDiffEditor(e.element.resourceGroup, this.editorService, {
3096+
const resourceGroup = e.element.resourceGroup;
3097+
const title = `${resourceGroup.provider.label}: ${resourceGroup.label}`;
3098+
await OpenScmGroupAction.openMultiFileDiffEditor(this.editorService, title, resourceGroup.provider.rootUri, resourceGroup.id, {
30973099
...e.editorOptions,
30983100
viewState: {
30993101
revealData: {

0 commit comments

Comments
 (0)