Skip to content

Commit 97a8318

Browse files
committed
Added check for old working copy
1 parent 8f9408e commit 97a8318

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
@@ -1193,6 +1193,46 @@ export class SvnCommands implements IDisposable {
11931193
await repository.rename(oldFile, newName);
11941194
}
11951195

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