diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-10-22 16:55:47 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-10-23 16:20:33 +0200 |
commit | e9e382ef3b26143787aa6d9d0b7a6d5df64c3057 (patch) | |
tree | 48a1980f974434bde8513a86012a3af54b0010fa | |
parent | 642db87a79ef5e9b5b8f4b20d63bf5e7141d48b2 (diff) |
Replace GitClone by GitRepository.clone()
-rwxr-xr-x | gbp-clone | 10 | ||||
-rw-r--r-- | gbp/command_wrappers.py | 8 | ||||
-rw-r--r-- | gbp/git.py | 24 |
3 files changed, 27 insertions, 15 deletions
@@ -24,7 +24,7 @@ import sys import os, os.path from gbp.config import (GbpOptionParser, GbpOptionGroup) from gbp.git import (GitRepositoryError, GitRepository) -from gbp.command_wrappers import (GitClone, Command, CommandExecFailed, +from gbp.command_wrappers import (Command, CommandExecFailed, PristineTar) from gbp.errors import GbpError import gbp.log @@ -71,17 +71,13 @@ def main(argv): pass try: - GitClone()([source]) - - (clone, dummy) = os.path.splitext(source.rstrip('/').rsplit('/',1)[1]) - os.chdir(clone) + repo = GitRepository.clone(os.path.curdir, source) + os.chdir(repo.path) # Reparse the config files of the cloned repository so we pick up the # branch information from there: (options, args) = parse_args(argv) - repo = GitRepository(os.path.curdir) - # Track all branches: if options.all: remotes = repo.get_remote_branches() 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""" @@ -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""" |