@@ -301,7 +301,7 @@ export class ParserIncludes {
301301 if ( this . _cache . sha === undefined ) {
302302 if ( this . isLocal ) {
303303 this . _cache . sha = this . gitData . commit . SHA ;
304- } else if ( / ^ [ 0 - 9 a - f ] { 40 } $ / . test ( this . effectiveRef ) ) {
304+ } else if ( / ^ [ 0 - 9 a - f ] { 40 } $ / i . test ( this . effectiveRef ) ) {
305305 // effectiveRef may already be a sha, if so return it directly
306306 this . _cache . sha = this . effectiveRef ;
307307 } else {
@@ -377,13 +377,15 @@ export class ParserIncludes {
377377 await fs . mkdirp ( path . dirname ( `${ cwd } /${ target } /${ normalizedFile } ` ) ) ;
378378 tmpDir = `${ cwd } /${ target } .${ ext } ` ;
379379
380- const gitCloneBranch = ( ref === "HEAD" ) ? "" : `--branch ${ ref } ` ;
380+ const isCommitSha = / ^ [ 0 - 9 a - f ] { 40 } $ / i. test ( ref ) ;
381+ const gitCloneBranch = ( ref === "HEAD" || isCommitSha ) ? "" : `--branch ${ ref } ` ;
381382 await Utils . bashMulti ( [
382383 `cd ${ cwd } /${ stateDir } ` ,
383384 `git clone ${ gitCloneBranch } -n --depth=1 --filter=tree:0 ${ remote . schema } ://${ remote . host } :${ remote . port } /${ project } .git ${ tmpDir } ` ,
384385 `cd ${ tmpDir } ` ,
386+ ...isCommitSha ? [ `git fetch --depth=1 --filter=tree:0 origin ${ ref } ` ] : [ ] ,
385387 `git sparse-checkout set --no-cone ${ normalizedFile } ` ,
386- "git checkout" ,
388+ isCommitSha ? "git checkout FETCH_HEAD" : "git checkout" ,
387389 `cd ${ cwd } /${ stateDir } ` ,
388390 `cp ${ tmpDir } /${ normalizedFile } ${ cwd } /${ target } /${ normalizedFile } ` ,
389391 ] , cwd ) ;
@@ -418,13 +420,15 @@ export class ParserIncludes {
418420 await fs . mkdirp ( path . dirname ( `${ cwd } /${ target } /templates` ) ) ;
419421 tmpDir = `${ cwd } /${ target } .${ ext } ` ;
420422
421- const gitCloneBranch = ( ref === "HEAD" ) ? "" : `--branch ${ ref } ` ;
423+ const isCommitSha = / ^ [ 0 - 9 a - f ] { 40 } $ / i. test ( ref ) ;
424+ const gitCloneBranch = ( ref === "HEAD" || isCommitSha ) ? "" : `--branch ${ ref } ` ;
422425 await Utils . bashMulti ( [
423426 `cd ${ cwd } /${ stateDir } ` ,
424427 `git clone ${ gitCloneBranch } -n --depth=1 --filter=tree:0 ${ remote . schema } ://${ remote . host } :${ remote . port } /${ project } .git ${ tmpDir } ` ,
425428 `cd ${ tmpDir } ` ,
429+ ...isCommitSha ? [ `git fetch --depth=1 --filter=tree:0 origin ${ ref } ` ] : [ ] ,
426430 `git sparse-checkout set --no-cone ${ files [ 0 ] } ${ files [ 1 ] } ` ,
427- "git checkout" ,
431+ isCommitSha ? "git checkout FETCH_HEAD" : "git checkout" ,
428432 `cd ${ cwd } /${ stateDir } ` ,
429433 `mkdir -p ${ tmpDir } /templates` , // create templates subdir (if it doesn't exist), as the check out may not create it
430434 `cp -r ${ tmpDir } /templates ${ cwd } /${ target } ` ,
0 commit comments