@@ -25,10 +25,9 @@ import (
2525 "path/filepath"
2626 "strings"
2727
28+ "github.com/reddec/layout/internal/gitclient"
2829 "github.com/reddec/layout/internal/ui"
2930 "github.com/reddec/layout/internal/ui/simple"
30-
31- "github.com/go-git/go-git/v5"
3231)
3332
3433const (
@@ -45,21 +44,25 @@ type Config struct {
4544 Debug bool // enable debug messages and tracing
4645 Version string // current version, used to filter manifests by constraints
4746 AskOnce bool // do not try to ask for user input after wrong value and interrupt deployment
47+ Git gitclient.Client // Git client, default is gitclient.Auto
4848}
4949
50- func (cfg Config ) withDefaults () Config {
50+ func (cfg Config ) withDefaults (ctx context. Context ) Config {
5151 if cfg .Default == "" {
5252 cfg .Default = defaultRepoTemplate
5353 }
5454 if cfg .Display == nil {
5555 cfg .Display = simple .Default ()
5656 }
57+ if cfg .Git == nil {
58+ cfg .Git = gitclient .Auto (ctx )
59+ }
5760 return cfg
5861}
5962
6063// Deploy layout, which means clone repo, ask for question, and template content.
6164func Deploy (ctx context.Context , config Config ) error {
62- config = config .withDefaults ()
65+ config = config .withDefaults (ctx )
6366
6467 var projectDir string
6568
@@ -85,7 +88,7 @@ func Deploy(ctx context.Context, config Config) error {
8588 url = strings .ReplaceAll (repoTemplate , "{0}" , repo )
8689 fallthrough
8790 default : // finally all we need is to pull remote repository by URL
88- tmpDir , err := cloneFromGit (ctx , url )
91+ tmpDir , err := cloneFromGit (ctx , config . Git , url )
8992 if err != nil {
9093 return fmt .Errorf ("copy project from git %s: %w" , url , err )
9194 }
@@ -112,20 +115,14 @@ func Deploy(ctx context.Context, config Config) error {
112115 return nil
113116}
114117
115- // clones from git repository from default branch with minimal depth (1).
116- // Reports progress to STDERR. Supports submodules.
118+ // clones from git repository into temporary directory.
117119// Returned directory should be removed by caller.
118- func cloneFromGit (ctx context.Context , url string ) (projectDir string , err error ) {
120+ func cloneFromGit (ctx context.Context , client gitclient. Client , url string ) (projectDir string , err error ) {
119121 tmpDir , err := os .MkdirTemp ("" , "layout-*" )
120122 if err != nil {
121123 return "" , fmt .Errorf ("create temp dir: %w" , err )
122124 }
123- _ , err = git .PlainCloneContext (ctx , tmpDir , false , & git.CloneOptions {
124- URL : url ,
125- Depth : 1 ,
126- RecurseSubmodules : git .DefaultSubmoduleRecursionDepth ,
127- Progress : os .Stderr ,
128- })
125+ err = client (ctx , url , tmpDir )
129126 if err != nil {
130127 _ = os .RemoveAll (tmpDir )
131128 return "" , fmt .Errorf ("clone repo: %w" , err )
0 commit comments