diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 77101cf8347..a04aba93531 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -388,8 +388,15 @@ export class Git { } async clone(url: string, parentPath: string, cancellationToken?: CancellationToken): Promise { - const folderName = decodeURI(url).replace(/^.*\//, '').replace(/\.git$/, '') || 'repository'; - const folderPath = path.join(parentPath, folderName); + let baseFolderName = decodeURI(url).replace(/^.*\//, '').replace(/\.git$/, '') || 'repository'; + let folderName = baseFolderName; + let folderPath = path.join(parentPath, folderName); + let count = 1; + + while (count < 20 && await new Promise(c => fs.exists(folderPath, c))) { + folderName = `${baseFolderName}-${count++}`; + folderPath = path.join(parentPath, folderName); + } await mkdirp(parentPath);