Stop users from adding project paths that won't work

This commit is contained in:
Ani Betts 2024-05-21 12:39:47 +02:00
parent 4e68e593e5
commit eece290edd
No known key found for this signature in database

View File

@ -107,6 +107,8 @@ export class ProjectService {
const path = await this.promptForDirectory();
if (!path) return;
if (!this.validateProjectPath(path)) return;
try {
const project = await this.add(path);
if (!project) return;
@ -118,6 +120,32 @@ export class ProjectService {
}
}
validateProjectPath(path: string, showErrors = true) {
if (/^\\\\wsl.localhost/i.test(path)) {
if (showErrors) {
showError(
'Use the Linux version of GitButler',
'For WSL2 projects, install the Linux version of GitButler inside of your WSL2 distro'
);
}
return false;
}
if (/^\\\\/i.test(path)) {
if (showErrors) {
showError(
'UNC Paths are not directly supported',
'Using git across a network is not recommended. Either clone the repo locally, or use the NET USE command to map a network drive'
);
}
return false;
}
return true;
}
getLastOpenedProject() {
return get(this.persistedId);
}