func GitRevision(dir string) (rev string, err error) { revisionResult, _, err := run.RunAndReturn("git", "--git-dir", filepath.Join(dir, ".git"), "--work-tree", dir, "rev-parse", "HEAD") if err != nil { return } rev = strings.TrimSpace(revisionResult) return }
func GitBranch(dir string) (branch string, err error) { branchResult, _, err := run.RunAndReturn("git", "--git-dir", filepath.Join(dir, ".git"), "--work-tree", dir, "rev-parse", "--abbrev-ref", "HEAD") if err != nil { return } branch = strings.TrimSpace(branchResult) return }
func GitCommitted(dir string) (result bool, err error) { _, _, err = run.RunAndReturn("git", "diff-index", "--quiet", "HEAD", "--") if err != nil { if _, ok := err.(*exec.ExitError); ok { err = nil } return } result = true return }