Skip to content

Commit

Permalink
notify on svn version mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanpas committed Jan 4, 2020
1 parent cfb4851 commit 4bfa04b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/commands/removeUnversioned.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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;
}
}
}
}
20 changes: 20 additions & 0 deletions src/svn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion src/svnRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/test/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ export function activeExtension() {
}

if (!extension.isActive) {
extension.activate().then(
() => resolve(),
() => reject()
);
extension.activate().then(() => resolve(), () => reject());
} else {
resolve();
}
Expand Down

0 comments on commit 4bfa04b

Please sign in to comment.