mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
🐛 any resource can come in via command arguments
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { Uri, commands, scm, Disposable, window, workspace, QuickPickItem, OutputChannel, Range, WorkspaceEdit, Position, LineChange } from 'vscode';
|
||||
import { Uri, commands, scm, Disposable, window, workspace, QuickPickItem, OutputChannel, Range, WorkspaceEdit, Position, LineChange, SourceControlResourceState } from 'vscode';
|
||||
import { Ref, RefType, Git } from './git';
|
||||
import { Model, Resource, Status, CommitOptions } from './model';
|
||||
import { Model, Resource, Status, CommitOptions, WorkingTreeGroup, IndexGroup, MergeGroup } from './model';
|
||||
import * as staging from './staging';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
@@ -270,7 +270,10 @@ export class CommandCenter {
|
||||
}
|
||||
|
||||
@command('git.stage')
|
||||
async stage(...resources: Resource[]): Promise<void> {
|
||||
async stage(...resourceStates: SourceControlResourceState[]): Promise<void> {
|
||||
const resources = resourceStates
|
||||
.filter(s => s instanceof Resource && (s.resourceGroup instanceof WorkingTreeGroup || s.resourceGroup instanceof MergeGroup)) as Resource[];
|
||||
|
||||
if (!resources.length) {
|
||||
return;
|
||||
}
|
||||
@@ -363,7 +366,10 @@ export class CommandCenter {
|
||||
}
|
||||
|
||||
@command('git.unstage')
|
||||
async unstage(...resources: Resource[]): Promise<void> {
|
||||
async unstage(...resourceStates: SourceControlResourceState[]): Promise<void> {
|
||||
const resources = resourceStates
|
||||
.filter(s => s instanceof Resource && s.resourceGroup instanceof IndexGroup) as Resource[];
|
||||
|
||||
if (!resources.length) {
|
||||
return;
|
||||
}
|
||||
@@ -418,7 +424,10 @@ export class CommandCenter {
|
||||
}
|
||||
|
||||
@command('git.clean')
|
||||
async clean(...resources: Resource[]): Promise<void> {
|
||||
async clean(...resourceStates: SourceControlResourceState[]): Promise<void> {
|
||||
const resources = resourceStates
|
||||
.filter(s => s instanceof Resource && s.resourceGroup instanceof WorkingTreeGroup) as Resource[];
|
||||
|
||||
if (!resources.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
+24
-18
@@ -71,6 +71,7 @@ export class Resource implements SourceControlResourceState {
|
||||
};
|
||||
}
|
||||
|
||||
get resourceGroup(): ResourceGroup { return this._resourceGroup; }
|
||||
get type(): Status { return this._type; }
|
||||
get original(): Uri { return this._resourceUri; }
|
||||
get renameResourceUri(): Uri | undefined { return this._renameResourceUri; }
|
||||
@@ -139,10 +140,15 @@ export class Resource implements SourceControlResourceState {
|
||||
return { strikeThrough: this.strikeThrough, light, dark };
|
||||
}
|
||||
|
||||
constructor(private resourceGroupId: string, private _resourceUri: Uri, private _type: Status, private _renameResourceUri?: Uri) { }
|
||||
constructor(
|
||||
private _resourceGroup: ResourceGroup,
|
||||
private _resourceUri: Uri,
|
||||
private _type: Status,
|
||||
private _renameResourceUri?: Uri
|
||||
) { }
|
||||
}
|
||||
|
||||
export class ResourceGroup {
|
||||
export abstract class ResourceGroup {
|
||||
|
||||
get id(): string { return this._id; }
|
||||
get contextKey(): string { return this._id; }
|
||||
@@ -619,30 +625,30 @@ export class Model implements Disposable {
|
||||
const renameUri = raw.rename ? Uri.file(path.join(this.repository.root, raw.rename)) : undefined;
|
||||
|
||||
switch (raw.x + raw.y) {
|
||||
case '??': return workingTree.push(new Resource(WorkingTreeGroup.ID, uri, Status.UNTRACKED));
|
||||
case '!!': return workingTree.push(new Resource(WorkingTreeGroup.ID, uri, Status.IGNORED));
|
||||
case 'DD': return merge.push(new Resource(MergeGroup.ID, uri, Status.BOTH_DELETED));
|
||||
case 'AU': return merge.push(new Resource(MergeGroup.ID, uri, Status.ADDED_BY_US));
|
||||
case 'UD': return merge.push(new Resource(MergeGroup.ID, uri, Status.DELETED_BY_THEM));
|
||||
case 'UA': return merge.push(new Resource(MergeGroup.ID, uri, Status.ADDED_BY_THEM));
|
||||
case 'DU': return merge.push(new Resource(MergeGroup.ID, uri, Status.DELETED_BY_US));
|
||||
case 'AA': return merge.push(new Resource(MergeGroup.ID, uri, Status.BOTH_ADDED));
|
||||
case 'UU': return merge.push(new Resource(MergeGroup.ID, uri, Status.BOTH_MODIFIED));
|
||||
case '??': return workingTree.push(new Resource(this.workingTreeGroup, uri, Status.UNTRACKED));
|
||||
case '!!': return workingTree.push(new Resource(this.workingTreeGroup, uri, Status.IGNORED));
|
||||
case 'DD': return merge.push(new Resource(this.mergeGroup, uri, Status.BOTH_DELETED));
|
||||
case 'AU': return merge.push(new Resource(this.mergeGroup, uri, Status.ADDED_BY_US));
|
||||
case 'UD': return merge.push(new Resource(this.mergeGroup, uri, Status.DELETED_BY_THEM));
|
||||
case 'UA': return merge.push(new Resource(this.mergeGroup, uri, Status.ADDED_BY_THEM));
|
||||
case 'DU': return merge.push(new Resource(this.mergeGroup, uri, Status.DELETED_BY_US));
|
||||
case 'AA': return merge.push(new Resource(this.mergeGroup, uri, Status.BOTH_ADDED));
|
||||
case 'UU': return merge.push(new Resource(this.mergeGroup, uri, Status.BOTH_MODIFIED));
|
||||
}
|
||||
|
||||
let isModifiedInIndex = false;
|
||||
|
||||
switch (raw.x) {
|
||||
case 'M': index.push(new Resource(IndexGroup.ID, uri, Status.INDEX_MODIFIED)); isModifiedInIndex = true; break;
|
||||
case 'A': index.push(new Resource(IndexGroup.ID, uri, Status.INDEX_ADDED)); break;
|
||||
case 'D': index.push(new Resource(IndexGroup.ID, uri, Status.INDEX_DELETED)); break;
|
||||
case 'R': index.push(new Resource(IndexGroup.ID, uri, Status.INDEX_RENAMED, renameUri)); break;
|
||||
case 'C': index.push(new Resource(IndexGroup.ID, uri, Status.INDEX_COPIED)); break;
|
||||
case 'M': index.push(new Resource(this.indexGroup, uri, Status.INDEX_MODIFIED)); isModifiedInIndex = true; break;
|
||||
case 'A': index.push(new Resource(this.indexGroup, uri, Status.INDEX_ADDED)); break;
|
||||
case 'D': index.push(new Resource(this.indexGroup, uri, Status.INDEX_DELETED)); break;
|
||||
case 'R': index.push(new Resource(this.indexGroup, uri, Status.INDEX_RENAMED, renameUri)); break;
|
||||
case 'C': index.push(new Resource(this.indexGroup, uri, Status.INDEX_COPIED)); break;
|
||||
}
|
||||
|
||||
switch (raw.y) {
|
||||
case 'M': workingTree.push(new Resource(WorkingTreeGroup.ID, uri, Status.MODIFIED, renameUri)); break;
|
||||
case 'D': workingTree.push(new Resource(WorkingTreeGroup.ID, uri, Status.DELETED, renameUri)); break;
|
||||
case 'M': workingTree.push(new Resource(this.workingTreeGroup, uri, Status.MODIFIED, renameUri)); break;
|
||||
case 'D': workingTree.push(new Resource(this.workingTreeGroup, uri, Status.DELETED, renameUri)); break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user