Skip to content

Commit 9bf7683

Browse files
authored
fix: Able to revert folders with children (#577)
1 parent 538262f commit 9bf7683

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

src/commands/revert.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SourceControlResourceState, window } from "vscode";
2+
import { SvnDepth } from "../common/types";
23
import { Command } from "./command";
34

45
export class Revert extends Command {
@@ -24,6 +25,16 @@ export class Revert extends Command {
2425
return;
2526
}
2627

28+
const picks: any[] = [];
29+
30+
for (const depth in SvnDepth) {
31+
if (SvnDepth.hasOwnProperty(depth)) {
32+
picks.push({ label: depth, description: SvnDepth[depth] });
33+
}
34+
}
35+
36+
const placeHolder = "Select revert depth";
37+
const pick = await window.showQuickPick(picks, { placeHolder });
2738
const uris = selection.map(resource => resource.resourceUri);
2839

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

3647
try {
37-
await repository.revert(paths);
48+
await repository.revert(paths, pick.label);
3849
} catch (error) {
3950
console.log(error);
4051
window.showErrorMessage("Unable to revert");

src/commands/revertAll.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SourceControlResourceGroup, window } from "vscode";
2+
import { SvnDepth } from "../common/types";
23
import { Command } from "./command";
34

45
export class RevertAll extends Command {
@@ -24,6 +25,16 @@ export class RevertAll extends Command {
2425
return;
2526
}
2627

28+
const picks: any[] = [];
29+
30+
for (const depth in SvnDepth) {
31+
if (SvnDepth.hasOwnProperty(depth)) {
32+
picks.push({ label: depth, description: SvnDepth[depth] });
33+
}
34+
}
35+
36+
const placeHolder = "Select revert depth";
37+
const pick = await window.showQuickPick(picks, { placeHolder });
2738
const uris = resourceStates.map(resource => resource.resourceUri);
2839

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

3647
try {
37-
await repository.revert(paths);
48+
await repository.revert(paths, pick.label);
3849
} catch (error) {
3950
console.log(error);
4051
window.showErrorMessage("Unable to revert");

src/common/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,10 @@ export interface ISvnLogEntry {
281281
msg: string;
282282
paths: ISvnLogEntryPath[];
283283
}
284+
285+
export enum SvnDepth {
286+
empty = "only the target itself",
287+
files = "the target and any immediate file children thereof",
288+
immediates = "the target and any immediate children thereof",
289+
infinity = "the target and all of its descendants—full recursion"
290+
}

src/repository.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
Operation,
2424
RepositoryState,
2525
Status,
26+
SvnDepth,
2627
SvnUriAction
2728
} from "./common/types";
2829
import { debounce, globalSequentialize, memoize, throttle } from "./decorators";
@@ -817,8 +818,8 @@ export class Repository implements IRemoteRepository {
817818
);
818819
}
819820

820-
public async revert(files: string[]) {
821-
return this.run(Operation.Revert, () => this.repository.revert(files));
821+
public async revert(files: string[], depth: SvnDepth) {
822+
return this.run(Operation.Revert, () => this.repository.revert(files, depth));
822823
}
823824

824825
public async info(path: string) {

src/svnRepository.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
IFileStatus,
99
ISvnInfo,
1010
ISvnLogEntry,
11-
Status
11+
Status,
12+
SvnDepth
1213
} from "./common/types";
1314
import { sequentialize } from "./decorators";
1415
import { exists, writeFile } from "./fs";
@@ -405,9 +406,9 @@ export class Repository {
405406
return true;
406407
}
407408

408-
public async revert(files: string[]) {
409+
public async revert(files: string[], depth: SvnDepth) {
409410
files = files.map(file => this.removeAbsolutePath(file));
410-
const result = await this.exec(["revert", ...files]);
411+
const result = await this.exec(["revert", "--depth", depth, ...files]);
411412
return result.stdout;
412413
}
413414

0 commit comments

Comments
 (0)