add --deep_git_clone flag

This commit is contained in:
john
2019-11-28 11:54:03 +00:00
parent fc92f4acd0
commit 6485a7cf3e
9 changed files with 87 additions and 6 deletions

View File

@@ -15,6 +15,41 @@ import (
// Cloner is a function that can clone a git repo.
type Cloner func(repoSpec *RepoSpec) error
// DeepClonerUsingGitExec uses a local git install
// to obtain a full-depth clone of a remote repo
func DeepClonerUsingGitExec(repoSpec *RepoSpec) error {
gitProgram, err := exec.LookPath("git")
if err != nil {
return errors.Wrap(err, "no 'git' program on path")
}
repoSpec.Dir, err = filesys.NewTmpConfirmedDir()
if err != nil {
return err
}
cmd := exec.Command(
gitProgram,
"clone",
repoSpec.CloneSpec(),
repoSpec.Dir.String())
var out bytes.Buffer
cmd.Stdout = &out
err = cmd.Run()
if err != nil {
return errors.Wrapf(err, "trouble cloning %s", repoSpec.OrgRepo)
}
if repoSpec.Ref == "" {
repoSpec.Ref = "master"
}
cmd = exec.Command(gitProgram, "checkout", repoSpec.Ref)
cmd.Dir = repoSpec.Dir.String()
err = cmd.Run()
if err != nil {
return errors.Wrapf(
err, "trouble checking out href %s", repoSpec.Ref)
}
return nil
}
// ClonerUsingGitExec uses a local git install, as opposed
// to say, some remote API, to obtain a local clone of
// a remote repo.

View File

@@ -34,7 +34,8 @@ func NewFakeLoaderWithRestrictor(
// Create fake filesystem and inject it into initial Loader.
fSys := filesys.MakeFsInMemory()
fSys.Mkdir(initialDir)
ldr, err := loader.NewLoader(lr, initialDir, fSys)
dc := false
ldr, err := loader.NewLoader(lr, initialDir, fSys, dc)
if err != nil {
log.Fatalf("Unable to make loader: %v", err)
}

View File

@@ -57,8 +57,9 @@ metadata:
t.Fatalf("err %v", err)
}
dc := false
ldr, err := fLdr.NewLoader(
fLdr.RestrictionRootOnly, dir, fSys)
fLdr.RestrictionRootOnly, dir, fSys, dc)
if err != nil {
t.Fatalf("Err: %v", err)
}