-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3b7e74b
commit 02c983b
Showing
8 changed files
with
154 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Uri, window } from "vscode"; | ||
import { checkAndPromptDepth, confirmRevert } from "../input/revert"; | ||
import { Command } from "./command"; | ||
|
||
export class RevertExplorer extends Command { | ||
constructor() { | ||
super("svn.revertExplorer"); | ||
} | ||
|
||
public async execute(_mainUri?: Uri, allUris?: Uri[]) { | ||
if (!allUris) { | ||
return; | ||
} | ||
|
||
const uris = allUris; | ||
if (uris.length === 0 || !(await confirmRevert())) { | ||
return; | ||
} | ||
|
||
const depth = await checkAndPromptDepth(uris); | ||
|
||
if (!depth) { | ||
return; | ||
} | ||
|
||
await this.runByRepository(uris, async (repository, resources) => { | ||
if (!repository) { | ||
return; | ||
} | ||
|
||
const paths = resources.map(resource => resource.fsPath); | ||
|
||
try { | ||
await repository.revert(paths, depth); | ||
} catch (error) { | ||
console.log(error); | ||
window.showErrorMessage("Unable to revert"); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters