mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Don't fetch default branch if ref is specified
Currently, we always fetch the default branch with an initial git clone and then fetch the ref after if it's specified. This changes it to only make one fetch instead of two if a ref is specified.
This commit is contained in:
@@ -29,31 +29,46 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
|
|||||||
|
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
gitProgram,
|
gitProgram,
|
||||||
"clone",
|
"init",
|
||||||
"--depth=1",
|
|
||||||
repoSpec.CloneSpec(),
|
|
||||||
repoSpec.Dir.String())
|
repoSpec.Dir.String())
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error cloning git repo: %s", out)
|
log.Printf("Error initializing git repo: %s", out)
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
err,
|
err,
|
||||||
"trouble cloning git repo %v in %s",
|
"trouble initializing git repo in %s",
|
||||||
repoSpec.CloneSpec(), repoSpec.Dir.String())
|
repoSpec.Dir.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd = exec.Command(
|
||||||
|
gitProgram,
|
||||||
|
"remote",
|
||||||
|
"add",
|
||||||
|
"origin",
|
||||||
|
repoSpec.CloneSpec())
|
||||||
|
cmd.Dir = repoSpec.Dir.String()
|
||||||
|
out, err = cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error adding remote: %s", out)
|
||||||
|
return errors.Wrapf(err, "trouble adding remote %s", repoSpec.CloneSpec())
|
||||||
|
}
|
||||||
|
|
||||||
|
ref := "HEAD"
|
||||||
if repoSpec.Ref != "" {
|
if repoSpec.Ref != "" {
|
||||||
|
ref = repoSpec.Ref
|
||||||
|
}
|
||||||
|
|
||||||
cmd = exec.Command(
|
cmd = exec.Command(
|
||||||
gitProgram,
|
gitProgram,
|
||||||
"fetch",
|
"fetch",
|
||||||
"--depth=1",
|
"--depth=1",
|
||||||
"origin",
|
"origin",
|
||||||
repoSpec.Ref)
|
ref)
|
||||||
cmd.Dir = repoSpec.Dir.String()
|
cmd.Dir = repoSpec.Dir.String()
|
||||||
out, err = cmd.CombinedOutput()
|
out, err = cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching ref: %s", out)
|
log.Printf("Error fetching ref: %s", out)
|
||||||
return errors.Wrapf(err, "trouble fetching %s", repoSpec.Ref)
|
return errors.Wrapf(err, "trouble fetching %s", ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = exec.Command(
|
cmd = exec.Command(
|
||||||
@@ -64,8 +79,7 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
|
|||||||
out, err = cmd.CombinedOutput()
|
out, err = cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error checking out ref: %s", out)
|
log.Printf("Error checking out ref: %s", out)
|
||||||
return errors.Wrapf(err, "trouble checking out %s", repoSpec.Ref)
|
return errors.Wrapf(err, "trouble checking out %s", ref)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = exec.Command(
|
cmd = exec.Command(
|
||||||
|
|||||||
Reference in New Issue
Block a user