Skip to content

Commit

Permalink
refactor: stage all but merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Fong Kye committed May 24, 2020
1 parent d2b5d32 commit 65fa899
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions extensions/git/src/commands.ts
Expand Up @@ -1000,37 +1000,14 @@ export class CommandCenter {

@command('git.stageAll', { repository: true })
async stageAll(repository: Repository): Promise<void> {
const resources = repository.mergeGroup.resourceStates.filter(s => s instanceof Resource) as Resource[];
const { merge, unresolved, deletionConflicts } = await categorizeResourceByResolution(resources);

try {
for (const deletionConflict of deletionConflicts) {
await this._stageDeletionConflict(repository, deletionConflict.resourceUri);
}
} catch (err) {
if (/Cancelled/.test(err.message)) {
return;
}

throw err;
}

if (unresolved.length > 0) {
const message = unresolved.length > 1
? localize('confirm stage files with merge conflicts', "Are you sure you want to stage {0} files with merge conflicts?", merge.length)
: localize('confirm stage file with merge conflicts', "Are you sure you want to stage {0} with merge conflicts?", path.basename(merge[0].resourceUri.fsPath));

const yes = localize('yes', "Yes");
const pick = await window.showWarningMessage(message, { modal: true }, yes);
const resources = [...repository.workingTreeGroup.resourceStates, ...repository.untrackedGroup.resourceStates];
const uris = resources.map(r => r.resourceUri);

if (pick !== yes) {
return;
}
if (uris.length > 0) {
const config = workspace.getConfiguration('git', Uri.file(repository.root));
const untrackedChanges = config.get<'mixed' | 'separate' | 'hidden'>('untrackedChanges');
await repository.add(uris, untrackedChanges === 'mixed' ? undefined : { update: true });
}

const config = workspace.getConfiguration('git', Uri.file(repository.root));
const untrackedChanges = config.get<'mixed' | 'separate' | 'hidden'>('untrackedChanges');
await repository.add([], untrackedChanges === 'mixed' ? undefined : { update: true });
}

private async _stageDeletionConflict(repository: Repository, uri: Uri): Promise<void> {
Expand Down

0 comments on commit 65fa899

Please sign in to comment.