diff options
author | Rob Taylor <rob.taylor@codethink.co.uk> | 2012-01-19 10:28:21 +0000 |
---|---|---|
committer | Rob Taylor <rob.taylor@codethink.co.uk> | 2012-01-19 10:28:21 +0000 |
commit | e946a1e66d1a236a475f9c83351305a0082e0c25 (patch) | |
tree | d12d26f8ba462571cd212319f825fe9cc9a31394 /morphlib/git.py | |
parent | eb36c1b9da1e629836264c1ff4fa6f4fb78d3c74 (diff) | |
download | morph-e946a1e66d1a236a475f9c83351305a0082e0c25.tar.gz |
Complete SourceManager tests
Diffstat (limited to 'morphlib/git.py')
-rw-r--r-- | morphlib/git.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/morphlib/git.py b/morphlib/git.py index 655d4716..e8c9eb70 100644 --- a/morphlib/git.py +++ b/morphlib/git.py @@ -18,6 +18,7 @@ import logging import urlparse import binascii import morphlib +import os class NoMorphs(Exception): @@ -44,14 +45,15 @@ class InvalidTreeish(Exception): class Treeish: - def __init__(self, repo, ref): + def __init__(self, repo, ref, msg=logging.debug): self.repo = repo + self.msg = msg self.sha1 = None self.ref = None self._resolve_ref(ref) def _resolve_ref(self, ref): - ex = morphlib.execute.Execute(self.repo, msg=logging.debug) + ex = morphlib.execute.Execute(self.repo, self.msg) try: refs = ex.runv(['git', 'show-ref', ref]).split() binascii.unhexlify(refs[0]) #Valid hex? @@ -64,10 +66,10 @@ class Treeish: try: if len(ref)==40: binascii.unhexlify(ref) - ex = morphlib.execute.Execute(self.repo, msg=logging.debug) + ex = morphlib.execute.Execute(self.repo, self.msg) try: refs = ex.runv(['git', 'rev-list', '--no-walk', ref]) - self.sha1=REF + self.sha1=ref except morphlib.execute.CommandFailure: raise InvalidTreeish(self.repo,ref) @@ -94,3 +96,14 @@ def clone(location, repo): ex = morphlib.execute.Execute('.', msg=logging.debug) return ex.runv(['git', 'clone', repo, location]) +def init(location): + '''initialise git repo at location''' + os.mkdir(location) + ex = morphlib.execute.Execute(location, msg=logging.debug) + return ex.runv(['git', 'init']) + +def add_remote(gitdir, name, url): + '''add remote with name 'name' for url at gitdir''' + ex = morphlib.execute.Execute(gitdir, msg=logging.debug) + return ex.runv(['git', 'remote', 'add', '-f', name, url]) + |