Skip to content

Commit

Permalink
feat(scm): allow to set local replia folder name
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhyc committed Jan 15, 2025
1 parent 7191c3d commit 47624e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/scm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export abstract class BaseSCM {
*
* @returns A promise that resolves to the validated URI
*/
public static async validateBaseUri(uri: string): Promise<vscode.Uri> {
public static async validateBaseUri(uri: string, projectName?: string): Promise<vscode.Uri> {
return Promise.resolve( vscode.Uri.parse(uri) );
}

Expand Down
18 changes: 14 additions & 4 deletions src/scm/localReplicaSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,24 @@ export class LocalReplicaSCMProvider extends BaseSCM {
public readonly baseUri: vscode.Uri,
) {
super(vfs, baseUri);
if ( !baseUri.path.endsWith(`/${vfs.projectName}`) ) {
this.baseUri = vscode.Uri.joinPath(baseUri, vfs.projectName);
}
}

public static async validateBaseUri(uri: string): Promise<vscode.Uri> {
public static async validateBaseUri(uri: string, projectName?: string): Promise<vscode.Uri> {
try {
let baseUri = vscode.Uri.file(uri);
// check if the path exists
try {
const stat = await vscode.workspace.fs.stat(baseUri);
if (stat.type!==vscode.FileType.Directory) {
throw new Error('Not a folder');
}
// check if the project name is included in the path
if (projectName!==undefined && !baseUri.path.endsWith(`/${projectName}`)) {
baseUri = vscode.Uri.joinPath(baseUri, projectName);
}
} catch {
// keep the baseUri as is
}
// try to create the folder with `mkdirp` semantics
await vscode.workspace.fs.createDirectory(baseUri);
await vscode.workspace.fs.stat(baseUri);
Expand Down
4 changes: 2 additions & 2 deletions src/scm/scmCollectionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ export class SCMCollectionProvider extends vscode.Disposable {
}
});
})
.then((uri) => scmProto.validateBaseUri(uri as string || ''))
.then((uri) => scmProto.validateBaseUri(uri as string || '', this.vfs.projectName))
.then(async (baseUri) => {
if (baseUri) {
const scm = await this.createSCM(scmProto, baseUri, true);
if (scm) {
vscode.window.showInformationMessage( vscode.l10n.t('"{scm}" created: {uri}.', {scm:scmProto.label, uri:scm.baseUri.toString()}) );
vscode.window.showInformationMessage( vscode.l10n.t('"{scm}" created: {uri}.', {scm:scmProto.label, uri: decodeURI(scm.baseUri.toString()) }) );
} else {
vscode.window.showErrorMessage( vscode.l10n.t('"{scm}" creation failed.', {scm:scmProto.label}) );
}
Expand Down

0 comments on commit 47624e4

Please sign in to comment.