1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

35 lines
877 B
Go
Raw Normal View History

2017-08-19 12:47:04 -03:00
// Package git provides an integration with the git command
package git
import (
"errors"
"os/exec"
"strings"
"github.com/apex/log"
2017-08-19 12:47:04 -03:00
)
// IsRepo returns true if current folder is a git repository
func IsRepo() bool {
out, err := Run("rev-parse", "--is-inside-work-tree")
return err == nil && strings.TrimSpace(out) == "true"
}
2017-08-19 12:47:04 -03:00
// Run runs a git command and returns its output or errors
func Run(args ...string) (output string, err error) {
/* #nosec */
2017-08-19 12:47:04 -03:00
var cmd = exec.Command("git", args...)
log.WithField("args", args).Debug("running git")
2017-08-19 12:47:04 -03:00
bts, err := cmd.CombinedOutput()
if err != nil {
return "", errors.New(string(bts))
}
log.WithField("output", string(bts)).Debug("result")
2017-08-19 12:47:04 -03:00
return string(bts), err
}
// Clean the output
func Clean(output string, err error) (string, error) {
return strings.Replace(strings.Split(output, "\n")[0], "'", "", -1), err
}