@@ -363,32 +363,46 @@ const initSite = async () => {
363
363
const repo = `https://github.com/${templateDetails.providerOwner}/${templateDetails.providerRepositoryId}`;
364
364
let selected = { template: templateDetails.frameworks[0].providerRootDirectory };
365
365
366
- let gitInitCommands = '';
367
- let gitPullCommands = '';
366
+ let gitCloneCommands = '';
368
367
369
368
const sparse = selected.template.startsWith('./') ? selected.template.substring(2) : selected.template;
370
369
371
370
log('Fetching site code ...');
372
371
373
372
if(selected.template === './') {
374
- gitInitCommands = `git clone --single-branch --depth 1 ${repo} .`;
373
+ gitCloneCommands = `
374
+ mkdir -p .
375
+ cd .
376
+ git init
377
+ git remote add origin ${repo}
378
+ git config --global init.defaultBranch main
379
+ git fetch --depth=1 origin refs/tags/$(git ls-remote --tags origin "${templateDetails.providerVersion}" | tail -n 1 | awk -F '/' '{print $3}')
380
+ git checkout FETCH_HEAD
381
+ `.trim();
375
382
} else {
376
- gitInitCommands = `git clone --single-branch --depth 1 --sparse ${repo} .`; // depth prevents fetching older commits reducing the amount fetched
377
- gitPullCommands = `git sparse-checkout add ${sparse}`;
383
+ gitCloneCommands = `
384
+ mkdir -p .
385
+ cd .
386
+ git init
387
+ git remote add origin ${repo}
388
+ git config --global init.defaultBranch main
389
+ git config core.sparseCheckout true
390
+ echo "${sparse}" >> .git/info/sparse-checkout
391
+ git config --add remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
392
+ git config remote.origin.tagopt --no-tags
393
+ git fetch --depth=1 origin refs/tags/$(git ls-remote --tags origin "${templateDetails.providerVersion}" | tail -n 1 | awk -F '/' '{print $3}')
394
+ git checkout FETCH_HEAD
395
+ `.trim();
378
396
}
379
397
380
398
/* Force use CMD as powershell does not support && */
381
399
if (process.platform === 'win32') {
382
- gitInitCommands = 'cmd /c "' + gitInitCommands + '"';
383
- if(gitPullCommands)
384
- gitPullCommands = 'cmd /c "' + gitPullCommands + '"';
400
+ gitCloneCommands = 'cmd /c "' + gitCloneCommands + '"';
385
401
}
386
402
387
403
/* Execute the child process but do not print any std output */
388
404
try {
389
- childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: templatesDir });
390
- if(gitPullCommands)
391
- childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: templatesDir });
405
+ childProcess.execSync(gitCloneCommands, { stdio: 'pipe', cwd: templatesDir });
392
406
} catch (error) {
393
407
/* Specialised errors with recommended actions to take */
394
408
if (error.message.includes('error: unknown option')) {
0 commit comments