# 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):
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
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"""
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
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
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='..'))
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)
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():
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))