Skip to content

Commit

Permalink
Log output from git on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
richardmarshall committed Aug 15, 2019
1 parent 44b62a8 commit 54f1952
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/git/cloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package git

import (
"bytes"
"log"
"os/exec"

"github.com/pkg/errors"
Expand Down Expand Up @@ -45,8 +46,10 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
repoSpec.Dir.String())
var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out
err = cmd.Run()
if err != nil {
log.Printf("Error initializing empty git repo: %s", out.String())
return errors.Wrapf(
err,
"trouble initializing empty git repo in %s",
Expand All @@ -60,9 +63,11 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
"origin",
repoSpec.CloneSpec())
cmd.Stdout = &out
cmd.Stderr = &out
cmd.Dir = repoSpec.Dir.String()
err = cmd.Run()
if err != nil {
log.Printf("Error setting git remote: %s", out.String())
return errors.Wrapf(
err,
"trouble adding remote %s",
Expand All @@ -78,9 +83,11 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
"origin",
repoSpec.Ref)
cmd.Stdout = &out
cmd.Stderr = &out
cmd.Dir = repoSpec.Dir.String()
err = cmd.Run()
if err != nil {
log.Printf("Error performing git fetch: %s", out.String())
return errors.Wrapf(err, "trouble fetching %s", repoSpec.Ref)
}

Expand All @@ -90,9 +97,11 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
"--hard",
"FETCH_HEAD")
cmd.Stdout = &out
cmd.Stderr = &out
cmd.Dir = repoSpec.Dir.String()
err = cmd.Run()
if err != nil {
log.Printf("Error performing git reset: %s", out.String())
return errors.Wrapf(
err, "trouble hard resetting empty repository to %s", repoSpec.Ref)
}
Expand Down

0 comments on commit 54f1952

Please sign in to comment.