summaryrefslogtreecommitdiff
path: root/morphlib/git.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/git.py')
-rw-r--r--morphlib/git.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/morphlib/git.py b/morphlib/git.py
index 47eb7ffe..f3403e2b 100644
--- a/morphlib/git.py
+++ b/morphlib/git.py
@@ -16,6 +16,7 @@
import gzip
import logging
+import urlparse
import morphlib
@@ -28,3 +29,14 @@ def export_sources(repo, ref, tar_filename):
f.write(tar)
f.close()
+
+def get_commit_id(repo, ref):
+ '''Return the full SHA-1 commit id for a repo+ref.'''
+ # FIXME: This assume repo is a file:/// URL.
+
+ scheme, netlock, path, params, query, frag = urlparse.urlparse(repo)
+ assert scheme == 'file'
+ ex = morphlib.execute.Execute(path, msg=logging.debug)
+ out = ex.runv(['git', 'rev-list', '-n1', ref])
+ return out.strip()
+