mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
Add Git: Delete action to run git rm command on the current document (#285411)
This commit is contained in:
@@ -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} `);
|
||||
|
||||
Reference in New Issue
Block a user