Add Git: Delete action to run git rm command on the current document (#285411)

This commit is contained in:
Dmitriy Vasyura
2026-01-16 21:36:23 +01:00
committed by GitHub
parent 5896bece5f
commit 0e28a4b760
3 changed files with 53 additions and 0 deletions

View File

@@ -321,6 +321,13 @@
"icon": "$(discard)",
"enablement": "!operationInProgress"
},
{
"command": "git.delete",
"title": "%command.delete%",
"category": "Git",
"icon": "$(trash)",
"enablement": "!operationInProgress"
},
{
"command": "git.commit",
"title": "%command.commit%",
@@ -1297,6 +1304,10 @@
"command": "git.rename",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && resourceScheme == file && scmActiveResourceRepository"
},
{
"command": "git.delete",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0 && resourceScheme == file"
},
{
"command": "git.commit",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
@@ -3303,6 +3314,11 @@
"description": "%config.confirmSync%",
"default": true
},
"git.confirmCommittedDelete": {
"type": "boolean",
"description": "%config.confirmCommittedDelete%",
"default": true
},
"git.countBadge": {
"type": "string",
"enum": [

View File

@@ -36,6 +36,7 @@
"command.unstageChange": "Unstage Change",
"command.unstageSelectedRanges": "Unstage Selected Ranges",
"command.rename": "Rename",
"command.delete": "Delete",
"command.clean": "Discard Changes",
"command.cleanAll": "Discard All Changes",
"command.cleanAllTracked": "Discard All Tracked Changes",
@@ -167,6 +168,7 @@
"config.autofetch": "When set to true, commits will automatically be fetched from the default remote of the current Git repository. Setting to `all` will fetch from all remotes.",
"config.autofetchPeriod": "Duration in seconds between each automatic git fetch, when `#git.autofetch#` is enabled.",
"config.confirmSync": "Confirm before synchronizing Git repositories.",
"config.confirmCommittedDelete": "Confirm before deleting committed files with Git.",
"config.countBadge": "Controls the Git count badge.",
"config.countBadge.all": "Count all changes.",
"config.countBadge.tracked": "Count only tracked changes.",

View File

@@ -1405,6 +1405,41 @@ export class CommandCenter {
await commands.executeCommand('vscode.open', Uri.file(path.join(repository.root, to)), { viewColumn: ViewColumn.Active });
}
@command('git.delete')
async delete(uri: Uri | undefined): Promise<void> {
const activeDocument = window.activeTextEditor?.document;
uri = uri ?? activeDocument?.uri;
if (!uri) {
return;
}
const repository = this.model.getRepository(uri);
if (!repository) {
return;
}
const allChangedResources = [
...repository.workingTreeGroup.resourceStates,
...repository.indexGroup.resourceStates,
...repository.mergeGroup.resourceStates,
...repository.untrackedGroup.resourceStates
];
// Check if file has uncommitted changes
const uriString = uri.toString();
if (allChangedResources.some(o => pathEquals(o.resourceUri.toString(), uriString))) {
window.showInformationMessage(l10n.t('Git: Delete can only be performed on committed files without uncommitted changes.'));
return;
}
await repository.rm([uri]);
// Close the active editor if it's not dirty
if (activeDocument && !activeDocument.isDirty && pathEquals(activeDocument.uri.toString(), uriString)) {
await commands.executeCommand('workbench.action.closeActiveEditor');
}
}
@command('git.stage')
async stage(...resourceStates: SourceControlResourceState[]): Promise<void> {
this.logger.debug(`[CommandCenter][stage] git.stage ${resourceStates.length} `);