forked from JohnstonCode/svn-scm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevert.ts
64 lines (54 loc) · 1.29 KB
/
revert.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Uri, window } from "vscode";
import { SvnDepth } from "../common/types";
import { lstat } from "../fs";
export async function confirmRevert() {
const yes = "Yes I'm sure";
const answer = await window.showWarningMessage(
"Are you sure? This will wipe all local changes.",
{ modal: true },
yes
);
if (answer !== yes) {
return false;
}
return true;
}
export async function promptDepth() {
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 });
if (!pick) {
return undefined;
}
return pick.label;
}
export async function checkAndPromptDepth(
uris: Uri[],
defaultDepth: keyof typeof SvnDepth = "empty"
) {
// Without uris, force prompt
let hasDirectory = uris.length === 0;
for (const uri of uris) {
if (uri.scheme !== "file") {
continue;
}
try {
const stat = await lstat(uri.fsPath);
if (stat.isDirectory()) {
hasDirectory = true;
break;
}
} catch (error) {
// ignore
}
}
if (hasDirectory) {
return await promptDepth();
}
return defaultDepth;
}