]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
git: Implement ParseRef to change a ref into a changeset
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 17 May 2017 16:39:55 +0000 (17:39 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Wed, 17 May 2017 16:52:00 +0000 (17:52 +0100)
Signed-off-by: George Dunlap <george.dunlap@citrix.com>
git.go

diff --git a/git.go b/git.go
index b015c75dd85f4a26010b4265ea711daf13d6f740..e7b5bc7c0de5d2a49b55298ee4619add7db94831 100644 (file)
--- 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)