Merge pull request #3306 from thatsmydoing/single-fetch

Don't fetch default branch if ref is specified
This commit is contained in:
Jeff Regan
2020-12-07 13:10:26 -08:00
committed by GitHub

View File

@@ -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(