Skip to content

Commit

Permalink
fix: Able to revert folders with children (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnstonCode committed May 24, 2019
1 parent 538262f commit 9bf7683
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/commands/revert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SourceControlResourceState, window } from "vscode";
import { SvnDepth } from "../common/types";
import { Command } from "./command";

export class Revert extends Command {
Expand All @@ -24,6 +25,16 @@ export class Revert extends Command {
return;
}

const picks: any[] = [];

for (const depth in SvnDepth) {
if (SvnDepth.hasOwnProperty(depth)) {
picks.push({ label: depth, description: SvnDepth[depth] });
}
}

const placeHolder = "Select revert depth";
const pick = await window.showQuickPick(picks, { placeHolder });
const uris = selection.map(resource => resource.resourceUri);

await this.runByRepository(uris, async (repository, resources) => {
Expand All @@ -34,7 +45,7 @@ export class Revert extends Command {
const paths = resources.map(resource => resource.fsPath);

try {
await repository.revert(paths);
await repository.revert(paths, pick.label);
} catch (error) {
console.log(error);
window.showErrorMessage("Unable to revert");
Expand Down
13 changes: 12 additions & 1 deletion src/commands/revertAll.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SourceControlResourceGroup, window } from "vscode";
import { SvnDepth } from "../common/types";
import { Command } from "./command";

export class RevertAll extends Command {
Expand All @@ -24,6 +25,16 @@ export class RevertAll extends Command {
return;
}

const picks: any[] = [];

for (const depth in SvnDepth) {
if (SvnDepth.hasOwnProperty(depth)) {
picks.push({ label: depth, description: SvnDepth[depth] });
}
}

const placeHolder = "Select revert depth";
const pick = await window.showQuickPick(picks, { placeHolder });
const uris = resourceStates.map(resource => resource.resourceUri);

await this.runByRepository(uris, async (repository, resources) => {
Expand All @@ -34,7 +45,7 @@ export class RevertAll extends Command {
const paths = resources.map(resource => resource.fsPath);

try {
await repository.revert(paths);
await repository.revert(paths, pick.label);
} catch (error) {
console.log(error);
window.showErrorMessage("Unable to revert");
Expand Down
7 changes: 7 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,10 @@ export interface ISvnLogEntry {
msg: string;
paths: ISvnLogEntryPath[];
}

export enum SvnDepth {
empty = "only the target itself",
files = "the target and any immediate file children thereof",
immediates = "the target and any immediate children thereof",
infinity = "the target and all of its descendants—full recursion"
}
5 changes: 3 additions & 2 deletions src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Operation,
RepositoryState,
Status,
SvnDepth,
SvnUriAction
} from "./common/types";
import { debounce, globalSequentialize, memoize, throttle } from "./decorators";
Expand Down Expand Up @@ -817,8 +818,8 @@ export class Repository implements IRemoteRepository {
);
}

public async revert(files: string[]) {
return this.run(Operation.Revert, () => this.repository.revert(files));
public async revert(files: string[], depth: SvnDepth) {
return this.run(Operation.Revert, () => this.repository.revert(files, depth));
}

public async info(path: string) {
Expand Down
7 changes: 4 additions & 3 deletions src/svnRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
IFileStatus,
ISvnInfo,
ISvnLogEntry,
Status
Status,
SvnDepth
} from "./common/types";
import { sequentialize } from "./decorators";
import { exists, writeFile } from "./fs";
Expand Down Expand Up @@ -405,9 +406,9 @@ export class Repository {
return true;
}

public async revert(files: string[]) {
public async revert(files: string[], depth: SvnDepth) {
files = files.map(file => this.removeAbsolutePath(file));
const result = await this.exec(["revert", ...files]);
const result = await this.exec(["revert", "--depth", depth, ...files]);
return result.stdout;
}

Expand Down

0 comments on commit 9bf7683

Please sign in to comment.