diff --git a/src/commands/removeUnversioned.ts b/src/commands/removeUnversioned.ts index 7995d1d2..0c8f55a5 100644 --- a/src/commands/removeUnversioned.ts +++ b/src/commands/removeUnversioned.ts @@ -1,6 +1,7 @@ import { Repository } from "../repository"; import { Command } from "./command"; import { window } from "vscode"; +import { VersionError } from "../svn"; export class RemoveUnversioned extends Command { constructor() { @@ -14,8 +15,19 @@ export class RemoveUnversioned extends Command { "Yes", "No" ); - if (answer === "Yes") { + if (answer !== "Yes") { + return; + } + try { await repository.removeUnversioned(); + } catch (e) { + if (e instanceof VersionError) { + window.showErrorMessage( + "Your svn is too old and does not support this feature" + ); + } else { + throw e; + } } } } diff --git a/src/svn.ts b/src/svn.ts index cbaf2bab..25357238 100644 --- a/src/svn.ts +++ b/src/svn.ts @@ -58,9 +58,22 @@ export function cpErrorHandler( }; } +export interface SvnVersion { + major: number; + minor: number; +} + +export class VersionError extends Error { + // Ok to extend Error since we use ES6 +} + export class Svn { private svnPath: string; private lastCwd: string = ""; + private _version?: SvnVersion; + get version(): SvnVersion | undefined { + return this._version; + } private _onOutput = new EventEmitter(); get onOutput(): EventEmitter { @@ -69,6 +82,13 @@ export class Svn { constructor(options: ISvnOptions) { this.svnPath = options.svnPath; + const verMatch = /.*?(\d+)\.(\d+).*/.exec(options.version); + if (verMatch) { + this._version = { + major: parseInt(verMatch[0], 10), + minor: parseInt(verMatch[1], 10), + }; + } } public logOutput(output: string): void { diff --git a/src/svnRepository.ts b/src/svnRepository.ts index e0a038c4..e0069d59 100644 --- a/src/svnRepository.ts +++ b/src/svnRepository.ts @@ -22,7 +22,7 @@ import { parseInfoXml } from "./infoParser"; import { parseSvnList } from "./listParser"; import { parseSvnLog } from "./logParser"; import { parseStatusXml } from "./statusParser"; -import { Svn } from "./svn"; +import { Svn, VersionError } from "./svn"; import { fixPathSeparator, fixPegRevision, @@ -701,6 +701,10 @@ export class Repository { } public async removeUnversioned() { + const svnVersion = this.svn.version; + if (svnVersion && svnVersion.major == 1 && svnVersion.minor < 9 ) { + throw new VersionError(); + } const result = await this.exec(["cleanup", "--remove-unversioned"]); this.svn.logOutput(result.stdout); diff --git a/src/test/testUtil.ts b/src/test/testUtil.ts index 867317cf..c6ee1277 100644 --- a/src/test/testUtil.ts +++ b/src/test/testUtil.ts @@ -185,10 +185,7 @@ export function activeExtension() { } if (!extension.isActive) { - extension.activate().then( - () => resolve(), - () => reject() - ); + extension.activate().then(() => resolve(), () => reject()); } else { resolve(); }