Example #1
0
func (g *Git) runOutputWithOpts(opts runutil.Opts, args ...string) ([]string, error) {
	var stdout, stderr bytes.Buffer
	opts.Stdout = &stdout
	opts.Stderr = &stderr
	if err := g.commandWithOpts(opts, args...); err != nil {
		return nil, err
	}
	output := strings.TrimSpace(stdout.String())
	if output == "" {
		return nil, nil
	} else {
		return strings.Split(output, "\n"), nil
	}
}
Example #2
0
func (g *Git) commandWithOpts(opts runutil.Opts, args ...string) error {
	if g.rootDir != "" {
		opts.Dir = g.rootDir
	}
	if err := g.r.CommandWithOpts(opts, "git", args...); err != nil {
		stdout, stderr := "", ""
		buf, ok := opts.Stdout.(*bytes.Buffer)
		if ok {
			stdout = buf.String()
		}
		buf, ok = opts.Stderr.(*bytes.Buffer)
		if ok {
			stderr = buf.String()
		}
		return Error(stdout, stderr, args...)
	}
	return nil
}