Exemple #1
0
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
}
Exemple #2
0
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
}
Exemple #3
0
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
}