Skip to content

Commit d2ecf30

Browse files
Copilotalexr00
andcommitted
Improve directory creation to handle nested paths robustly
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent de49d0d commit d2ecf30

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/github/createPRViewProvider.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,19 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
917917
`;
918918

919919
try {
920-
// Create parent directories if they don't exist
921-
const parentDir = vscode.Uri.joinPath(templatePath, '..');
922-
await vscode.workspace.fs.createDirectory(parentDir);
920+
// Ensure all parent directories exist by creating them step by step
921+
const pathParts = selected.label.split('/');
922+
let currentPath = workspaceFolder;
923+
924+
// Create each directory in the path (excluding the file name)
925+
for (let i = 0; i < pathParts.length - 1; i++) {
926+
currentPath = vscode.Uri.joinPath(currentPath, pathParts[i]);
927+
try {
928+
await vscode.workspace.fs.createDirectory(currentPath);
929+
} catch (e) {
930+
// Directory might already exist, which is fine
931+
}
932+
}
923933

924934
// Create the template file
925935
const encoder = new TextEncoder();

0 commit comments

Comments
 (0)