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

@@ -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} `);