Example #1
0
File: git.go Project: tbruyelle/git
// Checkout executes the git checkout command.
// If remote is specified, first delete the local branch if any
// and recreate according to that remote.
func Checkout(ref, remote string) (err error) {
	if remote == "" {
		_, err = qexec.Run("git", "checkout", ref)
		return
	}
	qexec.Run("git", "branch", "-D", ref)
	_, err = qexec.Run("git", "checkout", "-b", ref, remote)
	return
}
Example #2
0
File: git.go Project: tbruyelle/git
// Remote returns the requested remote url
func Remote(name string) (string, error) {
	remote, err := qexec.Run("git", "config", "--get", fmt.Sprintf("remote.%s.url", name))
	if err != nil {
		return "", err
	}
	return strings.TrimSpace(remote), err
}
Example #3
0
File: git.go Project: tbruyelle/git
// RevParse executes the git rev-parse command.
func RevParse(arg string) (string, error) {
	ref, err := qexec.Run("git", "rev-parse", "-q", arg)
	if err != nil {
		return "", nil
	}
	return strings.TrimSpace(ref), nil
}
Example #4
0
File: git.go Project: tbruyelle/git
// Branch returns the current branch.
func Branch() (string, error) {
	branch, err := qexec.Run("git", "rev-parse", "--abbrev-ref", "HEAD")
	if err != nil {
		return "", err
	}
	return strings.TrimSpace(branch), nil
}
Example #5
0
File: git.go Project: tbruyelle/git
// HasLocalDiff returns true if repo has local modifications.
func HasLocalDiff() (bool, error) {
	_, err := qexec.Run("git", "diff", "--quiet", "HEAD")
	status, err := qexec.ExitStatus(err)
	if err != nil {
		return false, err
	}
	return status != 0, nil
}
Example #6
0
File: git.go Project: tbruyelle/git
// RefExists checks if the ref exists in the repository.
func RefExists(ref string) (bool, error) {
	_, err := qexec.Run("git", "rev-parse", "--quiet", "--verify", ref)
	if err != nil {
		status, err := qexec.ExitStatus(err)
		if err != nil || status != 1 {
			return false, err
		}
		return false, nil
	}
	return true, nil
}
Example #7
0
File: git.go Project: tbruyelle/git
// Log returns the list of commits from the requested range.
func Log(start, end string) ([]Commit, error) {
	output, err := qexec.Run("git", "log", start+".."+end, "--oneline")
	if err != nil {
		return nil, err
	}
	lines := strings.Split(strings.TrimSpace(output), "\n")
	commits := make([]Commit, 0)
	for _, line := range lines {
		tokens := strings.SplitN(line, " ", 2)
		if len(tokens) != 2 {
			continue
		}
		commits = append(commits, Commit{tokens[0], tokens[1]})
	}
	return commits, nil
}
Example #8
0
File: git.go Project: tbruyelle/git
// Pull executes the git pull command
func Pull(remote string) error {
	_, err := qexec.Run("git", "pull", remote)
	return err
}
Example #9
0
File: git.go Project: tbruyelle/git
// AddRemote add a new remote to the repository.
func AddRemote(name, url string) error {
	_, err := qexec.Run("git", "remote", "add", name, url)
	return err
}
Example #10
0
File: git.go Project: tbruyelle/git
// ResetHard executes the git reset --hard command.
func ResetHard(ref string) error {
	_, err := qexec.Run("git", "reset", "--hard", ref)
	return err
}
Example #11
0
File: git.go Project: tbruyelle/git
// Fetch executes the git fetch command.
func Fetch(remote string) error {
	_, err := qexec.Run("git", "fetch", remote)
	return err
}
Example #12
0
File: git.go Project: tbruyelle/git
// Merge executes the git merge command.
func Merge(ref string) error {
	_, err := qexec.Run("git", "merge", ref)
	return err
}