diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-10-27 20:57:16 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-10-27 22:08:00 +0200 |
commit | 1a590241a7b95f13784d735a2e6d34bde83ed31c (patch) | |
tree | 5d36f7d98d288182d8a4457a4bda9cee8e362f38 | |
parent | c4f9f23dace4b3ea87955f9ebe093f302b75f810 (diff) |
GitRepository: Don't try to access .git/ in bare repos
-rw-r--r-- | gbp/git.py | 15 | ||||
-rw-r--r-- | tests/test_GitRepository.py | 23 |
2 files changed, 34 insertions, 4 deletions
@@ -95,6 +95,7 @@ class GitRepository(object): raise GitRepositoryError( "Failed to get repository state at '%s'" % self.path) self._bare = False if out[0].strip() != 'true' else True + self._git_dir = '' if self._bare else '.git' def __init__(self, path): self._path = os.path.abspath(path) @@ -195,7 +196,7 @@ class GitRepository(object): @property def base_dir(self): """Get the base of the repository""" - return os.path.join(self.path, '.git') + return os.path.join(self.path, self._git_dir) @property def bare(self): @@ -851,7 +852,7 @@ class GitRepository(object): @type committer: C{dict} with keys I{name}, I{email}, I{date} """ - git_index_file = os.path.join(self.path, '.git', 'gbp_index') + git_index_file = os.path.join(self.path, self._git_dir, 'gbp_index') try: os.unlink(git_index_file) except OSError: @@ -1138,13 +1139,19 @@ class GitRepository(object): """ abspath = os.path.abspath(path) - args = [ '--bare' ] if bare else [] + if bare: + args = [ '--bare' ] + git_dir = '' + else: + args = [] + git_dir = '.git' + try: if not os.path.exists(abspath): os.makedirs(abspath) GitCommand("init", args, cwd=abspath)() if description: - with file(os.path.join(abspath, ".git", "description"), 'w') as f: + with file(os.path.join(abspath, git_dir, "description"), 'w') as f: description += '\n' if description[-1] != '\n' else '' f.write(description) return klass(abspath) diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py index 3f19545..404eb3a 100644 --- a/tests/test_GitRepository.py +++ b/tests/test_GitRepository.py @@ -7,6 +7,8 @@ Test L{gbp.git.GitRepository} import os repo_dir = os.path.abspath( os.path.join(os.path.curdir, 'gbp_%s_test_repo' % __name__)) +bare_dir = os.path.abspath( + os.path.join(os.path.curdir, 'gbp_%s_test_bare' % __name__)) clone_dir = os.path.abspath( os.path.join(os.path.curdir, 'gbp_%s_test_clone' % __name__)) mirror_clone_dir = os.path.abspath( @@ -317,12 +319,33 @@ def test_pull(): >>> clone.pull() """ +def test_create_bare(): + """ + Create a bare repository + + Methods tested: + - L{gbp.git.GitRepository.create} + - L{gbp.git.GitRepository.is_empty} + + >>> import gbp.git + >>> bare = gbp.git.GitRepository.create(bare_dir, bare=True, description="msg") + >>> bare.path == bare_dir + True + >>> bare.base_dir[:-1] == bare_dir + True + >>> type(bare) == gbp.git.GitRepository + True + >>> bare.is_empty() + True + """ + def test_teardown(): """ Perform the teardown >>> import shutil, os >>> os.getenv("GBP_TESTS_NOCLEAN") or shutil.rmtree(repo_dir) + >>> os.getenv("GBP_TESTS_NOCLEAN") or shutil.rmtree(bare_dir) >>> os.getenv("GBP_TESTS_NOCLEAN") or shutil.rmtree(mirror_clone_dir) >>> os.getenv("GBP_TESTS_NOCLEAN") or shutil.rmtree(clone_dir) """ |