diff options
-rw-r--r-- | gbp/command_wrappers.py | 8 | ||||
-rw-r--r-- | gbp/git.py | 35 | ||||
-rwxr-xr-x | git-import-dsc | 4 | ||||
-rw-r--r-- | tests/03_test_gbp_branch.py | 2 | ||||
-rw-r--r-- | tests/04_test_gbp_submodules.py | 4 |
5 files changed, 23 insertions, 30 deletions
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py index dd7bc4cf..34885750 100644 --- a/gbp/command_wrappers.py +++ b/gbp/command_wrappers.py @@ -231,14 +231,6 @@ class GitCommand(Command): # FIXME: move to gbp.git.__init__ -class GitInit(GitCommand): - """Wrap git init""" - def __init__(self): - GitCommand.__init__(self, 'init') - self.run_error = "Couldn't init git repository" - - -# FIXME: move to gbp.git.__init__ class GitClone(GitCommand): """Wrap git clone""" def __init__(self): @@ -19,7 +19,7 @@ import re import subprocess import os.path -from command_wrappers import (GitCommand, GitInit, GitAdd, GitBranch, copy_from) +from command_wrappers import (GitCommand, GitAdd, GitBranch, copy_from) from errors import GbpError import log import dateutil.parser @@ -583,6 +583,23 @@ class GitRepository(object): recursive=recursive) return submodules + @classmethod + def create(klass, path, description=None): + """create a repository at path""" + abspath = os.path.abspath(path) + try: + if not os.path.exists(abspath): + os.makedirs(abspath) + GitCommand("init", cwd=abspath)() + if description: + with file(os.path.join(abspath, ".git", "description"), 'w') as f: + description += '\n' if description[-1] != '\n' else '' + f.write(description) + return klass(abspath) + except OSError, err: + raise GitRepositoryError, "Cannot create Git repository at %s: %s " % (abspath, err[1]) + return None + class FastImport(object): """Invoke git-fast-import""" @@ -649,22 +666,6 @@ from refs/heads/%(branch)s^0 self.close() -def create_repo(path): - """create a repository at path""" - abspath = os.path.abspath(path) - pwd = os.path.abspath(os.curdir) - try: - os.makedirs(abspath) - os.chdir(abspath) - GitInit()() - return GitRepository(abspath) - except OSError, err: - raise GitRepositoryError, "Cannot create Git repository at %s: %s " % (path, err[1]) - finally: - os.chdir(pwd) - return None - - def build_tag(format, version): """Generate a tag from a given format and a version diff --git a/git-import-dsc b/git-import-dsc index 16a9771f..0332e424 100755 --- a/git-import-dsc +++ b/git-import-dsc @@ -29,7 +29,7 @@ from email.Utils import parseaddr import gbp.command_wrappers as gbpc from gbp.deb import (debian_version_chars, parse_changelog, parse_dsc, DscFile, UpstreamSource) -from gbp.git import (build_tag, create_repo, GitRepository, +from gbp.git import (build_tag, GitRepository, GitRepositoryError, rfc822_date_to_git) from gbp.config import GbpOptionParser, GbpOptionGroup, no_upstream_branch_msg from gbp.errors import GbpError @@ -246,7 +246,7 @@ def main(argv): if needs_repo: gbp.log.info("No git repository found, creating one.") - repo = create_repo(src.pkg) + repo = GitRepository.create(src.pkg) os.chdir(repo.path) dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..')) diff --git a/tests/03_test_gbp_branch.py b/tests/03_test_gbp_branch.py index 9c3d9369..a3056975 100644 --- a/tests/03_test_gbp_branch.py +++ b/tests/03_test_gbp_branch.py @@ -16,7 +16,7 @@ def setup(): top = os.path.abspath(os.curdir) repo_dir = os.path.join(top, 'gbp_%s_test_repo' % __name__) - repo = gbp.git.create_repo(repo_dir) + repo = gbp.git.GitRepository.create(repo_dir) os.chdir(repo_dir) diff --git a/tests/04_test_gbp_submodules.py b/tests/04_test_gbp_submodules.py index 7a4dfa94..af44c07a 100644 --- a/tests/04_test_gbp_submodules.py +++ b/tests/04_test_gbp_submodules.py @@ -23,7 +23,7 @@ class Submodule(object): def __init__(self, name, tmpdir): self.name = name self.dir = os.path.join(tmpdir, name) - self.repo = gbp.git.create_repo(self.dir) + self.repo = gbp.git.GitRepository.create(self.dir) def setup(): @@ -34,7 +34,7 @@ def setup(): os.mkdir(tmpdir) repodir = os.path.join(tmpdir, 'test_repo') - repo = gbp.git.create_repo(repodir) + repo = gbp.git.GitRepository.create(repodir) for name in submodule_names: submodules.append(Submodule(name, tmpdir)) |