mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
git.stageAllUntracked, git.cleanAllUntracked
This commit is contained in:
parent
88c03a7a8d
commit
003177ea90
|
@ -109,6 +109,15 @@
|
|||
"dark": "resources/icons/dark/stage.svg"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "git.stageAllUntracked",
|
||||
"title": "%command.stageAllUntracked%",
|
||||
"category": "Git",
|
||||
"icon": {
|
||||
"light": "resources/icons/light/stage.svg",
|
||||
"dark": "resources/icons/dark/stage.svg"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "git.stageSelectedRanges",
|
||||
"title": "%command.stageSelectedRanges%",
|
||||
|
@ -178,6 +187,15 @@
|
|||
"dark": "resources/icons/dark/clean.svg"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "git.cleanAllUntracked",
|
||||
"title": "%command.cleanAllUntracked%",
|
||||
"category": "Git",
|
||||
"icon": {
|
||||
"light": "resources/icons/light/clean.svg",
|
||||
"dark": "resources/icons/dark/clean.svg"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "git.commit",
|
||||
"title": "%command.commit%",
|
||||
|
@ -450,6 +468,10 @@
|
|||
"command": "git.stageAll",
|
||||
"when": "config.git.enabled && gitOpenRepositoryCount != 0"
|
||||
},
|
||||
{
|
||||
"command": "git.stageAllUntracked",
|
||||
"when": "config.git.enabled && gitOpenRepositoryCount != 0"
|
||||
},
|
||||
{
|
||||
"command": "git.stageSelectedRanges",
|
||||
"when": "config.git.enabled && gitOpenRepositoryCount != 0"
|
||||
|
@ -880,6 +902,26 @@
|
|||
"command": "git.stageAll",
|
||||
"when": "scmProvider == git && scmResourceGroup == workingTree",
|
||||
"group": "inline"
|
||||
},
|
||||
{
|
||||
"command": "git.cleanAllUntracked",
|
||||
"when": "scmProvider == git && scmResourceGroup == untracked",
|
||||
"group": "1_modification"
|
||||
},
|
||||
{
|
||||
"command": "git.stageAllUntracked",
|
||||
"when": "scmProvider == git && scmResourceGroup == untracked",
|
||||
"group": "1_modification"
|
||||
},
|
||||
{
|
||||
"command": "git.cleanAllUntracked",
|
||||
"when": "scmProvider == git && scmResourceGroup == untracked",
|
||||
"group": "inline"
|
||||
},
|
||||
{
|
||||
"command": "git.stageAllUntracked",
|
||||
"when": "scmProvider == git && scmResourceGroup == untracked",
|
||||
"group": "inline"
|
||||
}
|
||||
],
|
||||
"scm/resourceFolder/context": [
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"command.openHEADFile": "Open File (HEAD)",
|
||||
"command.stage": "Stage Changes",
|
||||
"command.stageAll": "Stage All Changes",
|
||||
"command.stageAllUntracked": "Stage All Untracked Changes",
|
||||
"command.stageSelectedRanges": "Stage Selected Ranges",
|
||||
"command.revertSelectedRanges": "Revert Selected Ranges",
|
||||
"command.stageChange": "Stage Change",
|
||||
|
@ -20,6 +21,7 @@
|
|||
"command.unstageSelectedRanges": "Unstage Selected Ranges",
|
||||
"command.clean": "Discard Changes",
|
||||
"command.cleanAll": "Discard All Changes",
|
||||
"command.cleanAllUntracked": "Discard All Untracked Changes",
|
||||
"command.commit": "Commit",
|
||||
"command.commitStaged": "Commit Staged",
|
||||
"command.commitEmpty": "Commit Empty",
|
||||
|
|
|
@ -914,45 +914,9 @@ export class CommandCenter {
|
|||
}
|
||||
}
|
||||
|
||||
const handleUntracked = workspace.getConfiguration('git', Uri.file(repository.root)).get<'withchanges' | 'separate' | 'hide'>('handleUntracked');
|
||||
let includeUntracked = false;
|
||||
switch (handleUntracked) {
|
||||
case 'withchanges':
|
||||
includeUntracked = true;
|
||||
break;
|
||||
case 'separate':
|
||||
if (repository.untrackedGroup.resourceStates.length > 0) {
|
||||
const message = localize(
|
||||
'also add untracked files',
|
||||
'Would you like to also add and stage untracked files?'
|
||||
);
|
||||
|
||||
const yes = localize('yes', "Yes");
|
||||
const no = localize('no', 'No');
|
||||
const pick = await window.showInformationMessage(
|
||||
message,
|
||||
{ modal: true },
|
||||
yes,
|
||||
no
|
||||
);
|
||||
|
||||
if (pick === yes) {
|
||||
includeUntracked = true;
|
||||
} else if (pick === no) {
|
||||
includeUntracked = false;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Doesn't matter
|
||||
includeUntracked = false;
|
||||
}
|
||||
break;
|
||||
case 'hide':
|
||||
includeUntracked = false;
|
||||
break;
|
||||
}
|
||||
await repository.add([], includeUntracked ? undefined : { update: true });
|
||||
const config = workspace.getConfiguration('git', Uri.file(repository.root));
|
||||
const handleUntracked = config.get<'withchanges' | 'separate' | 'hide'>('handleUntracked');
|
||||
await repository.add([], handleUntracked === 'withchanges' ? undefined : { update: true });
|
||||
}
|
||||
|
||||
private async _stageDeletionConflict(repository: Repository, uri: Uri): Promise<void> {
|
||||
|
@ -990,6 +954,15 @@ export class CommandCenter {
|
|||
}
|
||||
}
|
||||
|
||||
@command('git.stageAllUntracked', { repository: true })
|
||||
async stageAllUntracked(repository: Repository): Promise<void> {
|
||||
const resources = [...repository.workingTreeGroup.resourceStates, ...repository.untrackedGroup.resourceStates]
|
||||
.filter(r => r.type === Status.UNTRACKED || r.type === Status.IGNORED);
|
||||
const uris = resources.map(r => r.resourceUri);
|
||||
|
||||
await repository.add(uris);
|
||||
}
|
||||
|
||||
@command('git.stageChange')
|
||||
async stageChange(uri: Uri, changes: LineChange[], index: number): Promise<void> {
|
||||
const textEditor = window.visibleTextEditors.filter(e => e.document.uri.toString() === uri.toString())[0];
|
||||
|
@ -1247,27 +1220,12 @@ export class CommandCenter {
|
|||
}
|
||||
|
||||
await repository.clean(resources.map(r => r.resourceUri));
|
||||
return;
|
||||
|
||||
} else if (resources.length === 1) {
|
||||
const message = localize('confirm delete', "Are you sure you want to DELETE {0}?\nThis is IRREVERSIBLE!\nThis file will be FOREVER LOST.", path.basename(resources[0].resourceUri.fsPath));
|
||||
const yes = localize('delete file', "Delete file");
|
||||
const pick = await window.showWarningMessage(message, { modal: true }, yes);
|
||||
await this._cleanUntrackedChange(repository, resources[0]);
|
||||
|
||||
if (pick !== yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
await repository.clean(resources.map(r => r.resourceUri));
|
||||
} else if (trackedResources.length === 0) {
|
||||
const message = localize('confirm delete multiple', "Are you sure you want to DELETE {0} files?", resources.length);
|
||||
const yes = localize('delete files', "Delete Files");
|
||||
const pick = await window.showWarningMessage(message, { modal: true }, yes);
|
||||
|
||||
if (pick !== yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
await repository.clean(resources.map(r => r.resourceUri));
|
||||
await this._cleanUntrackedChanges(repository, resources);
|
||||
|
||||
} else { // resources.length > 1 && untrackedResources.length > 0 && trackedResources.length > 0
|
||||
const untrackedMessage = untrackedResources.length === 1
|
||||
|
@ -1293,6 +1251,46 @@ export class CommandCenter {
|
|||
}
|
||||
}
|
||||
|
||||
@command('git.cleanAllUntracked', { repository: true })
|
||||
async cleanAllUntracked(repository: Repository): Promise<void> {
|
||||
const resources = [...repository.workingTreeGroup.resourceStates, ...repository.untrackedGroup.resourceStates]
|
||||
.filter(r => r.type === Status.UNTRACKED || r.type === Status.IGNORED);
|
||||
|
||||
if (resources.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (resources.length === 1) {
|
||||
await this._cleanUntrackedChange(repository, resources[0]);
|
||||
} else {
|
||||
await this._cleanUntrackedChanges(repository, resources);
|
||||
}
|
||||
}
|
||||
|
||||
private async _cleanUntrackedChange(repository: Repository, resource: Resource): Promise<void> {
|
||||
const message = localize('confirm delete', "Are you sure you want to DELETE {0}?\nThis is IRREVERSIBLE!\nThis file will be FOREVER LOST.", path.basename(resource.resourceUri.fsPath));
|
||||
const yes = localize('delete file', "Delete file");
|
||||
const pick = await window.showWarningMessage(message, { modal: true }, yes);
|
||||
|
||||
if (pick !== yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
await repository.clean([resource.resourceUri]);
|
||||
}
|
||||
|
||||
private async _cleanUntrackedChanges(repository: Repository, resources: Resource[]): Promise<void> {
|
||||
const message = localize('confirm delete multiple', "Are you sure you want to DELETE {0} files?", resources.length);
|
||||
const yes = localize('delete files', "Delete Files");
|
||||
const pick = await window.showWarningMessage(message, { modal: true }, yes);
|
||||
|
||||
if (pick !== yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
await repository.clean(resources.map(r => r.resourceUri));
|
||||
}
|
||||
|
||||
private async smartCommit(
|
||||
repository: Repository,
|
||||
getCommitMessage: () => Promise<string | undefined>,
|
||||
|
|
|
@ -969,6 +969,7 @@ export class Repository implements Disposable {
|
|||
const toClean: string[] = [];
|
||||
const toCheckout: string[] = [];
|
||||
const submodulesToUpdate: string[] = [];
|
||||
const resourceStates = [...this.workingTreeGroup.resourceStates, ...this.untrackedGroup.resourceStates];
|
||||
|
||||
resources.forEach(r => {
|
||||
const fsPath = r.fsPath;
|
||||
|
@ -981,7 +982,7 @@ export class Repository implements Disposable {
|
|||
}
|
||||
|
||||
const raw = r.toString();
|
||||
const scmResource = find(this.workingTreeGroup.resourceStates, sr => sr.resourceUri.toString() === raw);
|
||||
const scmResource = find(resourceStates, sr => sr.resourceUri.toString() === raw);
|
||||
|
||||
if (!scmResource) {
|
||||
return;
|
||||
|
@ -1526,7 +1527,11 @@ export class Repository implements Disposable {
|
|||
case 'separate': return untracked.push(new Resource(ResourceGroupType.Untracked, uri, Status.UNTRACKED, useIcons));
|
||||
default: return undefined;
|
||||
}
|
||||
case '!!': return workingTree.push(new Resource(ResourceGroupType.WorkingTree, uri, Status.IGNORED, useIcons));
|
||||
case '!!': switch (handleUntracked) {
|
||||
case 'withchanges': return workingTree.push(new Resource(ResourceGroupType.WorkingTree, uri, Status.IGNORED, useIcons));
|
||||
case 'separate': return untracked.push(new Resource(ResourceGroupType.Untracked, uri, Status.IGNORED, useIcons));
|
||||
default: return undefined;
|
||||
}
|
||||
case 'DD': return merge.push(new Resource(ResourceGroupType.Merge, uri, Status.BOTH_DELETED, useIcons));
|
||||
case 'AU': return merge.push(new Resource(ResourceGroupType.Merge, uri, Status.ADDED_BY_US, useIcons));
|
||||
case 'UD': return merge.push(new Resource(ResourceGroupType.Merge, uri, Status.DELETED_BY_THEM, useIcons));
|
||||
|
|
Loading…
Reference in a new issue