From: George Dunlap Date: Wed, 17 May 2017 16:39:55 +0000 (+0100) Subject: git: Implement ParseRef to change a ref into a changeset X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=a188e885c9bc5a766f5e054568856762b0aec403;p=people%2Fgdunlap%2Fxsatool git: Implement ParseRef to change a ref into a changeset Signed-off-by: George Dunlap --- diff --git a/git.go b/git.go index b015c75..e7b5bc7 100644 --- a/git.go +++ b/git.go @@ -110,6 +110,18 @@ func (r Repo) VerifyRef(ref string) (ok bool) { return err == nil } +func (r Repo) ParseRef(ref string) (string, error) { + out, err := r.gitCmd("rev-parse", "--verify", ref) + if err != nil { + return "", err + } + lines := strings.Split(string(out), "\n") + if len(lines) != 2 { + return "", fmt.Errorf("Multiple lines in output") + } + return lines[0], nil +} + func (r Repo) DeleteBranch(branch string) (out []byte, err error) { out, err = r.gitCmd("branch", "-D", branch)