github.com/pluralsh/plural-cli@v0.9.5/pkg/utils/git/cmd.go (about)

     1  package git
     2  
     3  import (
     4  	"fmt"
     5  	"os/exec"
     6  	"strings"
     7  )
     8  
     9  func GitRaw(args ...string) (string, error) {
    10  	cmd := exec.Command("git", args...)
    11  	res, err := execute(cmd)
    12  
    13  	_ = fmt.Sprintf("cmds %s    res:\n %s \n", cmd.String(), res)
    14  
    15  	return strings.TrimSpace(string(res)), err
    16  }
    17  
    18  func git(root string, args ...string) (string, error) {
    19  	cmd := exec.Command("git", args...)
    20  	cmd.Dir = root
    21  	res, err := execute(cmd)
    22  	return strings.TrimSpace(string(res)), err
    23  }
    24  
    25  func execute(cmd *exec.Cmd) (string, error) {
    26  	res, err := cmd.CombinedOutput()
    27  	if err != nil {
    28  		return string(res), fmt.Errorf("Command %s failed with output:\n\n%s", cmd.String(), res)
    29  	}
    30  
    31  	return string(res), nil
    32  }