Skip to content

Commit 496dae2

Browse files
authored
Merge pull request #360 from edgardmessias/find_svn
feat: Added option to search the executable of svn
2 parents c2af690 + 243bd9e commit 496dae2

File tree

3 files changed

+85
-34
lines changed

3 files changed

+85
-34
lines changed

src/extension.ts

Lines changed: 66 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from "path";
12
import {
23
commands,
34
Disposable,
@@ -83,41 +84,74 @@ async function _activate(context: ExtensionContext, disposables: Disposable[]) {
8384
outputChannel.show();
8485
}
8586

86-
try {
87-
await init(context, outputChannel, disposables);
88-
} catch (err) {
89-
if (!/Svn installation not found/.test(err.message || "")) {
90-
throw err;
91-
}
92-
93-
const shouldIgnore =
94-
configuration.get<boolean>("ignoreMissingSvnWarning") === true;
87+
const tryInit = async () => {
88+
try {
89+
await init(context, outputChannel, disposables);
90+
} catch (err) {
91+
if (!/Svn installation not found/.test(err.message || "")) {
92+
throw err;
93+
}
94+
95+
const shouldIgnore =
96+
configuration.get<boolean>("ignoreMissingSvnWarning") === true;
97+
98+
if (shouldIgnore) {
99+
return;
100+
}
101+
102+
console.warn(err.message);
103+
outputChannel.appendLine(err.message);
104+
outputChannel.show();
105+
106+
const findSvnExecutable = "Find SVN executable";
107+
const download = "Download SVN";
108+
const neverShowAgain = "Don't Show Again";
109+
const choice = await window.showWarningMessage(
110+
"SVN not found. Install it or configure it using the 'svn.path' setting.",
111+
findSvnExecutable,
112+
download,
113+
neverShowAgain
114+
);
95115

96-
if (shouldIgnore) {
97-
return;
116+
if (choice === findSvnExecutable) {
117+
let filters: { [name: string]: string[] } | undefined;
118+
119+
// For windows, limit to executable files
120+
if (path.sep === "\\") {
121+
filters = {
122+
svn: ["exe", "bat"]
123+
};
124+
}
125+
126+
const executable = await window.showOpenDialog({
127+
canSelectFiles: true,
128+
canSelectFolders: false,
129+
canSelectMany: false,
130+
filters
131+
});
132+
133+
if (executable && executable[0]) {
134+
const file = executable[0].fsPath;
135+
136+
outputChannel.appendLine(`Updated "svn.path" with "${file}"`);
137+
138+
await configuration.update("path", file);
139+
140+
// Try Re-init after select the executable
141+
await tryInit();
142+
}
143+
} else if (choice === download) {
144+
commands.executeCommand(
145+
"vscode.open",
146+
Uri.parse("https://subversion.apache.org/packages.html")
147+
);
148+
} else if (choice === neverShowAgain) {
149+
await configuration.update("ignoreMissingSvnWarning", true);
150+
}
98151
}
152+
};
99153

100-
console.warn(err.message);
101-
outputChannel.appendLine(err.message);
102-
outputChannel.show();
103-
104-
const download = "Download SVN";
105-
const neverShowAgain = "Don't Show Again";
106-
const choice = await window.showWarningMessage(
107-
"SVN not found. Install it or configure it using the 'svn.path' setting.",
108-
download,
109-
neverShowAgain
110-
);
111-
112-
if (choice === download) {
113-
commands.executeCommand(
114-
"vscode.open",
115-
Uri.parse("https://subversion.apache.org/packages.html")
116-
);
117-
} else if (choice === neverShowAgain) {
118-
await configuration.update("ignoreMissingSvnWarning", true);
119-
}
120-
}
154+
await tryInit();
121155
}
122156

123157
export async function activate(context: ExtensionContext) {

src/helpers/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Configuration {
3838
return this.configuration.get<T>(section, defaultValue!);
3939
}
4040

41-
public update(section: string, value: any): void {
42-
this.configuration.update(section, value);
41+
public update(section: string, value: any): Thenable<void> {
42+
return this.configuration.update(section, value);
4343
}
4444

4545
public inspect(section: string) {

src/svnFinder.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class SvnFinder {
3333
return this.findSpecificSvn("svn");
3434
}
3535
})
36+
.then(svn => this.checkSvnCommand(svn))
3637
.then(null, () =>
3738
Promise.reject(new Error("Svn installation not found."))
3839
);
@@ -118,4 +119,20 @@ export class SvnFinder {
118119
);
119120
});
120121
}
122+
123+
public checkSvnCommand(svn: ISvn): Promise<ISvn> {
124+
return new Promise<ISvn>((c, e) => {
125+
const buffers: Buffer[] = [];
126+
const child = cp.spawn(svn.path, ["help", "checkout"]);
127+
child.stdout.on("data", (b: Buffer) => buffers.push(b));
128+
child.on("error", cpErrorHandler(e));
129+
child.on(
130+
"exit",
131+
code =>
132+
code || Buffer.concat(buffers).toString("utf8").length < 100
133+
? e(new Error("Not found"))
134+
: c(svn)
135+
);
136+
});
137+
}
121138
}

0 commit comments

Comments
 (0)