]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
git: Add function to get a hash of the tree at a particular reference
authorGeorge Dunlap <george.dunlap@citrix.com>
Mon, 20 Nov 2017 10:58:53 +0000 (10:58 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Mon, 20 Nov 2017 10:58:53 +0000 (10:58 +0000)
Signed-off-by: George Dunlap <george.dunlap@citrix.com>
git.go

diff --git a/git.go b/git.go
index 1554bc60e2fc3930cff49861d160c24733d507b5..74377707e1d800dc520bd7ede86d6f981c880567 100644 (file)
--- a/git.go
+++ b/git.go
@@ -173,6 +173,20 @@ func (r Repo) ParseRef(ref string) (string, error) {
        return lines[0], nil
 }
 
+// Return the hash of the tree corresponding to the reference
+func (r Repo) TreeRef(ref string) (string, error) {
+       ref = ref + ":"
+       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
+}
+
 // This wants SetRefSafe, which uses the "compare exchange" provided by git
 func (r Repo) SetRef(ref string, value string) (out []byte, err error) {
        out, err = r.gitCmd("update-ref", ref, value)