Skip to content
Permalink
Browse files

fix: show git error on debug (#710)

Right now, if git fails, it doesn't matter if debug is enabled, because it won't print both stdout and stderr.
  • Loading branch information...
caarlos0 committed Jul 4, 2018
2 parents 35da820 + b898635 commit 47b6bd5f502050dd1ebd94896d009e7aa87785b1
Showing with 7 additions and 9 deletions.
  1. +7 −9 internal/git/git.go
@@ -2,7 +2,6 @@
package git

import (
"bytes"
"errors"
"os/exec"
"strings"
@@ -18,18 +17,17 @@ func IsRepo() bool {

// Run runs a git command and returns its output or errors
func Run(args ...string) (string, error) {
// TODO: use exex.CommandContext here and refactor.
/* #nosec */
var cmd = exec.Command("git", args...)
log.WithField("args", args).Debug("running git")
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return "", errors.New(stderr.String())
bts, err := cmd.CombinedOutput()
log.WithField("output", string(bts)).
Debug("git result")
if err != nil {
return "", errors.New(string(bts))
}
log.WithField("output", stdout.String()).Debug("git result")
return stdout.String(), nil
return string(bts), nil
}

// Clean the output

0 comments on commit 47b6bd5

Please sign in to comment.
You can’t perform that action at this time.