gitee.com/mirrors_opencollective/goreleaser@v0.45.0/internal/git/git.go (about) 1 // Package git provides an integration with the git command 2 package git 3 4 import ( 5 "errors" 6 "os/exec" 7 "strings" 8 ) 9 10 // IsRepo returns true if current folder is a git repository 11 func IsRepo() bool { 12 out, err := Run("rev-parse", "--is-inside-work-tree") 13 return err == nil && strings.TrimSpace(out) == "true" 14 } 15 16 // Run runs a git command and returns its output or errors 17 func Run(args ...string) (output string, err error) { 18 /* #nosec */ 19 var cmd = exec.Command("git", args...) 20 bts, err := cmd.CombinedOutput() 21 if err != nil { 22 return "", errors.New(string(bts)) 23 } 24 return string(bts), err 25 } 26 27 // Clean the output 28 func Clean(output string, err error) (string, error) { 29 return strings.Replace(strings.Split(output, "\n")[0], "'", "", -1), err 30 }