Skip to content

Commit 5656ea4

Browse files
committed
added ability to revert
1 parent 210e295 commit 5656ea4

File tree

4 files changed

+82
-22
lines changed

4 files changed

+82
-22
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# **v1.1.0**
2+
3+
## What's New
4+
5+
* Added file revert command
6+
17
# **v1.0.3**
28

39
## Changes

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svn-scm",
33
"displayName": "SVN",
44
"description": "Integrated Subversion source control",
5-
"version": "1.0.3",
5+
"version": "1.1.0",
66
"publisher": "johnstoncode",
77
"engines": {
88
"vscode": "^1.17.0"
@@ -71,6 +71,11 @@
7171
"command": "svn.switchBranch",
7272
"title": "Switch Branch",
7373
"category": "SVN"
74+
},
75+
{
76+
"command": "svn.revert",
77+
"title": "Revert Selected",
78+
"category": "SVN"
7479
}
7580
],
7681
"menus": {
@@ -102,6 +107,11 @@
102107
"command": "svn.openDiffHead",
103108
"when": "scmProvider == svn && scmResourceGroup == changes",
104109
"group": "1_modification"
110+
},
111+
{
112+
"command": "svn.revert",
113+
"when": "scmProvider == svn && scmResourceGroup == changes",
114+
"group": "1_modification"
105115
}
106116
],
107117
"editor/title": []

src/commands.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CreateBranchItem implements QuickPickItem {
3737
class SwitchBranchItem implements QuickPickItem {
3838
protected tree: string = "";
3939
protected name: string = "";
40-
40+
4141
constructor(protected ref: string) {
4242
let parts = ref.split("/");
4343
if (parts[1]) {
@@ -106,6 +106,11 @@ export class SvnCommands {
106106
commandId: "svn.branch",
107107
method: this.branch,
108108
options: { repository: true }
109+
},
110+
{
111+
commandId: "svn.revert",
112+
method: this.revert,
113+
options: { repository: true }
109114
}
110115
];
111116

@@ -313,4 +318,18 @@ export class SvnCommands {
313318
);
314319
await repository.branch(name);
315320
}
321+
322+
async revert(repository: Repository, ...args: any[][]) {
323+
try {
324+
const paths = args[0].map(state => {
325+
return state.resourceUri.fsPath;
326+
});
327+
328+
await repository.repository.revert(paths);
329+
repository.update();
330+
} catch (error) {
331+
console.error(error);
332+
window.showErrorMessage("Unable to revert");
333+
}
334+
}
316335
}

src/svn.ts

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ export class Svn {
123123
switchBranch(root: string, path: string) {
124124
return this.exec(root, ["switch", path]);
125125
}
126+
127+
revert(files: any[]) {
128+
let args = ["revert"];
129+
130+
for (let file of files) {
131+
args.push(file);
132+
}
133+
134+
return this.exec("", args);
135+
}
126136
}
127137

128138
export class Repository {
@@ -188,13 +198,15 @@ export class Repository {
188198

189199
async getRepoUrl() {
190200
const info = await this.svn.info(this.root);
191-
201+
192202
if (info.exitCode !== 0) {
193203
throw new Error(info.stderr);
194204
}
195205

196206
let repoUrl = info.stdout.match(/<root>(.*?)<\/root>/)[1];
197-
const match = info.stdout.match(/<url>(.*?)\/(trunk|branches|tags).*?<\/url>/);
207+
const match = info.stdout.match(
208+
/<url>(.*?)\/(trunk|branches|tags).*?<\/url>/
209+
);
198210

199211
if (match[1]) {
200212
repoUrl = match[1];
@@ -208,7 +220,12 @@ export class Repository {
208220

209221
const branches = [];
210222

211-
let trunkExists = await this.svn.exec("", ["ls", repoUrl + "/trunk", "--depth", "empty"]);
223+
let trunkExists = await this.svn.exec("", [
224+
"ls",
225+
repoUrl + "/trunk",
226+
"--depth",
227+
"empty"
228+
]);
212229

213230
if (trunkExists.exitCode === 0) {
214231
branches.push("trunk");
@@ -219,23 +236,21 @@ export class Repository {
219236
for (let index in trees) {
220237
const tree = trees[index];
221238
const branchUrl = repoUrl + "/" + tree;
222-
223-
const result = await this.svn.list(branchUrl);
224-
225-
if (result.exitCode !== 0) {
226-
continue;
227-
}
228-
229-
const list = result.stdout
230-
.trim()
231-
.replace(/\/|\\/g, "")
232-
.split(/[\r\n]+/)
233-
.map((i: string) => tree + "/" + i);
234-
235-
branches.push(...list);
236-
237-
}
238239

240+
const result = await this.svn.list(branchUrl);
241+
242+
if (result.exitCode !== 0) {
243+
continue;
244+
}
245+
246+
const list = result.stdout
247+
.trim()
248+
.replace(/\/|\\/g, "")
249+
.split(/[\r\n]+/)
250+
.map((i: string) => tree + "/" + i);
251+
252+
branches.push(...list);
253+
}
239254

240255
return branches;
241256
}
@@ -262,7 +277,7 @@ export class Repository {
262277

263278
async switchBranch(ref: string) {
264279
const repoUrl = await this.getRepoUrl();
265-
280+
266281
var branchUrl = repoUrl + "/" + ref;
267282

268283
const switchBranch = await this.svn.switchBranch(this.root, branchUrl);
@@ -273,4 +288,14 @@ export class Repository {
273288

274289
return true;
275290
}
291+
292+
async revert(files: any[]) {
293+
const result = await this.svn.revert(files);
294+
295+
if (result.exitCode !== 0) {
296+
throw new Error(result.stderr);
297+
}
298+
299+
return result.stdout;
300+
}
276301
}

0 commit comments

Comments
 (0)