summaryrefslogtreecommitdiff
path: root/gbp
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-10-22 16:55:47 +0200
committerGuido Günther <agx@sigxcpu.org>2011-10-23 16:20:33 +0200
commite9e382ef3b26143787aa6d9d0b7a6d5df64c3057 (patch)
tree48a1980f974434bde8513a86012a3af54b0010fa /gbp
parent642db87a79ef5e9b5b8f4b20d63bf5e7141d48b2 (diff)
Replace GitClone by GitRepository.clone()
Diffstat (limited to 'gbp')
-rw-r--r--gbp/command_wrappers.py8
-rw-r--r--gbp/git.py24
2 files changed, 24 insertions, 8 deletions
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py
index 4c1de10..b768239 100644
--- a/gbp/command_wrappers.py
+++ b/gbp/command_wrappers.py
@@ -230,14 +230,6 @@ class GitCommand(Command):
self.run_error = "Couldn't run git %s" % cmd
-# FIXME: move to gbp.git.__init__
-class GitClone(GitCommand):
- """Wrap git clone"""
- def __init__(self):
- GitCommand.__init__(self, 'clone')
- self.run_error = "Couldn't clone git repository"
-
-
# FIXME: move to gbp.git.fetch
class GitFetch(GitCommand):
"""Wrap git fetch"""
diff --git a/gbp/git.py b/gbp/git.py
index 6a3ff6f..cfd01bc 100644
--- a/gbp/git.py
+++ b/gbp/git.py
@@ -869,6 +869,30 @@ class GitRepository(object):
raise GitRepositoryError, "Cannot create Git repository at %s: %s " % (abspath, err[1])
return None
+ @classmethod
+ def clone(klass, path, remote):
+ """
+ Clone a git repository at I{path}
+
+ @param path: where to clone the repository to
+ @type path: string
+ @param remote: URL to clone
+ @type remote: string
+ @return: git repository object
+ @rtype:GitRepository
+ """
+ abspath = os.path.abspath(path)
+ try:
+ if not os.path.exists(abspath):
+ os.makedirs(abspath)
+
+ GitCommand("clone", [remote], cwd=abspath)()
+ (clone, dummy) = os.path.splitext(remote.rstrip('/').rsplit('/',1)[1])
+ return klass(os.path.join(abspath, clone))
+ except OSError, err:
+ raise GitRepositoryError, "Cannot clone Git repository %s to %s: %s " % (remote, abspath, err[1])
+ return None
+
class FastImport(object):
"""Invoke git-fast-import"""