summaryrefslogtreecommitdiff
path: root/morphlib/git.py
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-10-03 14:49:46 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-10-03 14:49:46 +0100
commita4a66fce7c6086f25b4071d5c33f07d5badf8181 (patch)
treececfdd96a67fe39ad0ad36e9a1bafb3b429250b4 /morphlib/git.py
parent3b592b24c6e1afd6fc1fdadea76093b5e1f6231c (diff)
parent47ccbd4d3d7a2bbfa3c840f442f00528c88f5a45 (diff)
downloadmorph-a4a66fce7c6086f25b4071d5c33f07d5badf8181.tar.gz
Merge remote-tracking branch 'origin/samthursfield/ref-access-fixes'
Diffstat (limited to 'morphlib/git.py')
-rw-r--r--morphlib/git.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/morphlib/git.py b/morphlib/git.py
index 5862ef9b..b3dd2c45 100644
--- a/morphlib/git.py
+++ b/morphlib/git.py
@@ -221,7 +221,12 @@ def clone_into(runcmd, srcpath, targetpath, ref=None):
else:
runcmd(['git', 'clone', '-b', ref, srcpath, targetpath])
-def find_first_ref(runcmd, gitdir, ref):
- '''Find the *first* ref match and returns its sha1.'''
- return runcmd(['git', 'show-ref', ref],
- cwd=gitdir).split("\n")[0].split(" ")[0]
+def is_valid_sha1(ref):
+ '''Checks whether a string is a valid SHA1.'''
+
+ valid_chars = 'abcdefABCDEF0123456789'
+ return len(ref) == 40 and all([x in valid_chars for x in ref])
+
+def rev_parse(runcmd, gitdir, ref):
+ '''Find the sha1 for the given ref'''
+ return runcmd(['git', 'rev-parse', ref], cwd=gitdir)[0:40]