mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-16 17:33:14 +00:00
Merge pull request #857 from pst/fastergitclone
Reduce time required for cloning remote bases
This commit is contained in:
@@ -41,24 +41,61 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
|
|||||||
}
|
}
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
gitProgram,
|
gitProgram,
|
||||||
"clone",
|
"init",
|
||||||
repoSpec.CloneSpec(),
|
|
||||||
repoSpec.cloneDir.String())
|
repoSpec.cloneDir.String())
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "trouble cloning %s", repoSpec.raw)
|
return errors.Wrapf(
|
||||||
|
err,
|
||||||
|
"trouble initializing empty git repo in %s",
|
||||||
|
repoSpec.cloneDir.String())
|
||||||
}
|
}
|
||||||
if repoSpec.ref == "" {
|
|
||||||
return nil
|
cmd = exec.Command(
|
||||||
}
|
gitProgram,
|
||||||
cmd = exec.Command(gitProgram, "checkout", repoSpec.ref)
|
"remote",
|
||||||
|
"add",
|
||||||
|
"origin",
|
||||||
|
repoSpec.CloneSpec())
|
||||||
|
cmd.Stdout = &out
|
||||||
cmd.Dir = repoSpec.cloneDir.String()
|
cmd.Dir = repoSpec.cloneDir.String()
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
err, "trouble checking out href %s", repoSpec.ref)
|
err,
|
||||||
|
"trouble adding remote %s",
|
||||||
|
repoSpec.CloneSpec())
|
||||||
|
}
|
||||||
|
|
||||||
|
if repoSpec.ref == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cmd = exec.Command(
|
||||||
|
gitProgram,
|
||||||
|
"fetch",
|
||||||
|
"--depth=1",
|
||||||
|
"origin",
|
||||||
|
repoSpec.ref)
|
||||||
|
cmd.Stdout = &out
|
||||||
|
cmd.Dir = repoSpec.cloneDir.String()
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "trouble fetching %s", repoSpec.ref)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = exec.Command(
|
||||||
|
gitProgram,
|
||||||
|
"reset",
|
||||||
|
"--hard",
|
||||||
|
"FETCH_HEAD")
|
||||||
|
cmd.Stdout = &out
|
||||||
|
cmd.Dir = repoSpec.cloneDir.String()
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(
|
||||||
|
err, "trouble hard resetting empty repository to %s", repoSpec.ref)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user