mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-09-15 12:18:57 +00:00
unify git cloner behaviour
This commit is contained in:
@@ -15,41 +15,6 @@ import (
|
|||||||
// Cloner is a function that can clone a git repo.
|
// Cloner is a function that can clone a git repo.
|
||||||
type Cloner func(repoSpec *RepoSpec) error
|
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
|
// ClonerUsingGitExec uses a local git install, as opposed
|
||||||
// to say, some remote API, to obtain a local clone of
|
// to say, some remote API, to obtain a local clone of
|
||||||
// a remote repo.
|
// a remote repo.
|
||||||
@@ -109,8 +74,28 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
|
|||||||
cmd.Dir = repoSpec.Dir.String()
|
cmd.Dir = repoSpec.Dir.String()
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error performing git fetch: %s", out.String())
|
cmd = exec.Command(
|
||||||
return errors.Wrapf(err, "trouble fetching %s", repoSpec.Ref)
|
gitProgram,
|
||||||
|
"pull",
|
||||||
|
"origin",
|
||||||
|
"master")
|
||||||
|
var out bytes.Buffer
|
||||||
|
cmd.Stdout = &out
|
||||||
|
cmd.Dir = repoSpec.Dir.String()
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "trouble pulling %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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = exec.Command(
|
cmd = exec.Command(
|
||||||
|
|||||||
Reference in New Issue
Block a user