2017-08-19 12:47:04 -03:00
|
|
|
// Package git provides an integration with the git command
|
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os/exec"
|
2017-10-16 15:43:26 -02:00
|
|
|
"strings"
|
2017-08-19 12:47:04 -03:00
|
|
|
)
|
|
|
|
|
2017-10-16 15:43:26 -02: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) {
|
|
|
|
var cmd = exec.Command("git", args...)
|
|
|
|
bts, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.New(string(bts))
|
|
|
|
}
|
|
|
|
return string(bts), err
|
|
|
|
}
|