Skip to content

Commit f4ae030

Browse files
authored
Merge pull request #306 from edgardmessias/old_working_copy
Added check for old working copy
2 parents 0999ac3 + 97a8318 commit f4ae030

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@
546546
"description": "Ignores the warning when SVN is missing",
547547
"default": false
548548
},
549+
"svn.ignoreWorkingCopyIsTooOld": {
550+
"type": "boolean",
551+
"description": "Ignores the warning when working copy is too old",
552+
"default": false
553+
},
549554
"svn.diff.withHead": {
550555
"type": "boolean",
551556
"description":

src/commands.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,46 @@ export class SvnCommands implements IDisposable {
11981198
await repository.rename(oldFile, newName);
11991199
}
12001200

1201+
@command("svn.upgrade")
1202+
public async upgrade(folderPath: string): Promise<void> {
1203+
if (!folderPath) {
1204+
return;
1205+
}
1206+
1207+
if (configuration.get("ignoreWorkingCopyIsTooOld", false)) {
1208+
return;
1209+
}
1210+
1211+
folderPath = fixPathSeparator(folderPath);
1212+
1213+
const yes = "Yes";
1214+
const no = "No";
1215+
const neverShowAgain = "Don't Show Again";
1216+
const choice = await window.showWarningMessage(
1217+
"You want upgrade the working copy (svn upgrade)?",
1218+
yes,
1219+
no,
1220+
neverShowAgain
1221+
);
1222+
1223+
if (choice === yes) {
1224+
const upgraded = await this.model.upgradeWorkingCopy(folderPath);
1225+
1226+
if (upgraded) {
1227+
window.showInformationMessage(`Working copy "${folderPath}" upgraded`);
1228+
this.model.tryOpenRepository(folderPath);
1229+
} else {
1230+
window.showErrorMessage(
1231+
`Error on upgrading working copy "${folderPath}". See log for more detail`
1232+
);
1233+
}
1234+
} else if (choice === neverShowAgain) {
1235+
return configuration.update("ignoreWorkingCopyIsTooOld", true);
1236+
}
1237+
1238+
return;
1239+
}
1240+
12011241
private getSCMResource(uri?: Uri): Resource | undefined {
12021242
uri = uri
12031243
? uri

src/model.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
import { debounce, sequentialize } from "./decorators";
2121
import { configuration } from "./helpers/configuration";
2222
import { Repository } from "./repository";
23-
import { Svn } from "./svn";
23+
import { Svn, svnErrorCodes } from "./svn";
24+
import SvnError from "./svnError";
2425
import {
2526
anyEvent,
2627
dispose,
@@ -283,6 +284,12 @@ export class Model implements IDisposable {
283284

284285
this.open(repository);
285286
} catch (err) {
287+
if (err instanceof SvnError) {
288+
if (err.svnErrorCode === svnErrorCodes.WorkingCopyIsTooOld) {
289+
await commands.executeCommand("svn.upgrade", path);
290+
return;
291+
}
292+
}
286293
console.error(err);
287294
}
288295
return;
@@ -424,6 +431,16 @@ export class Model implements IDisposable {
424431
return pick && pick.repository;
425432
}
426433

434+
public async upgradeWorkingCopy(folderPath: string): Promise<boolean> {
435+
try {
436+
const result = await this.svn.exec(folderPath, ["upgrade"]);
437+
return result.exitCode === 0;
438+
} catch (e) {
439+
console.log(e);
440+
}
441+
return false;
442+
}
443+
427444
public dispose(): void {
428445
this.disable();
429446
this.configurationChangeDisposable.dispose();

src/svn.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const svnErrorCodes: { [key: string]: string } = {
1515
AuthorizationFailed: "E170001",
1616
RepositoryIsLocked: "E155004",
1717
NotASvnRepository: "E155007",
18-
NotShareCommonAncestry: "E195012"
18+
NotShareCommonAncestry: "E195012",
19+
WorkingCopyIsTooOld: "E155036"
1920
};
2021

2122
function getSvnErrorCode(stderr: string): string | undefined {
@@ -206,6 +207,9 @@ export class Svn {
206207
// SVN 1.6 not has "wcroot-abspath"
207208
return path;
208209
} catch (error) {
210+
if (error instanceof SvnError) {
211+
throw error;
212+
}
209213
console.error(error);
210214
throw new Error("Unable to find repository root path");
211215
}

0 commit comments

Comments
 (0)