@@ -313,10 +313,6 @@ func siteEntryRequiresBuildCommand(entry SiteEntry) bool {
313313}
314314
315315// downloadSiteTemplate fetches the framework's starter into the site directory.
316- //
317- // The clone is built by hand rather than with `git clone` because the template
318- // lives at a tag in a subdirectory of a shared repository: a sparse checkout of
319- // one directory at one tag is cheaper than cloning the whole thing.
320316func downloadSiteTemplate (
321317 out interface { Write ([]byte ) (int , error ) },
322318 template * siteTemplate ,
@@ -330,7 +326,7 @@ func downloadSiteTemplate(
330326 return fmt .Errorf ("No starter template found for framework %s" , framework )
331327 }
332328
333- root := template .Frameworks [0 ].ProviderRootDirectory
329+ root := strings . Trim ( strings . TrimPrefix ( template .Frameworks [0 ].ProviderRootDirectory , "./" ), "/" )
334330
335331 if err := os .MkdirAll (siteFolder , 0o777 ); err != nil {
336332 return err
@@ -340,48 +336,38 @@ func downloadSiteTemplate(
340336 }
341337 defer os .RemoveAll (templatesDir )
342338
343- repo := fmt .Sprintf ("https://github.com/%s/%s" ,
339+ repository := fmt .Sprintf ("https://github.com/%s/%s" ,
344340 template .ProviderOwner , template .ProviderRepositoryID )
345341
346- setup := []string {
347- "git init" ,
348- "git remote add origin " + repo ,
349- "git config --global init.defaultBranch main" ,
350- }
351-
352- if root != "./" {
353- sparse := strings .TrimPrefix (root , "./" )
354- setup = append (setup ,
355- "git config core.sparseCheckout true" ,
356- fmt .Sprintf ("echo %q >> .git/info/sparse-checkout" , sparse ),
357- "git config --add remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'" ,
358- "git config remote.origin.tagopt --no-tags" ,
359- )
360- }
361-
362342 output .Log (out , "Fetching site code ..." )
363343
364- // The tag is resolved remotely and the LAST match taken, which is how a
365- // version like "0.1.*" picks its newest release.
366- setup = append (setup ,
367- fmt .Sprintf ("git fetch --depth=1 origin refs/tags/$(git ls-remote --tags " +
368- "origin %q | tail -n 1 | awk -F '/' '{print $3}')" , template .ProviderVersion ),
369- "git checkout FETCH_HEAD" ,
370- )
344+ tag , err := resolveGitTag (templatesDir , repository , template .ProviderVersion )
345+ if err != nil {
346+ return err
347+ }
371348
372- if err := runGit (templatesDir , strings .Join (setup , "\n " )); err != nil {
349+ cloneArguments := []string {"clone" , "--single-branch" , "--depth" , "1" }
350+ if tag != "" {
351+ cloneArguments = append (cloneArguments , "--branch" , tag )
352+ }
353+ if root != "" {
354+ cloneArguments = append (cloneArguments , "--sparse" )
355+ }
356+ cloneArguments = append (cloneArguments , repository , "." )
357+ if err := runGitCommand (templatesDir , cloneArguments ... ); err != nil {
373358 return err
374359 }
360+ if root != "" {
361+ if err := runGitCommand (templatesDir , "sparse-checkout" , "add" , root ); err != nil {
362+ return err
363+ }
364+ }
375365
376366 if err := os .RemoveAll (filepath .Join (templatesDir , ".git" )); err != nil {
377367 return err
378368 }
379369
380- source := templatesDir
381- if root != "./" {
382- source = filepath .Join (templatesDir , root )
383- }
384- if err := copyTree (source , siteDir ); err != nil {
370+ if err := copyTree (filepath .Join (templatesDir , filepath .FromSlash (root )), siteDir ); err != nil {
385371 return err
386372 }
387373
0 commit comments