aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gbp/git.py15
-rw-r--r--tests/test_GitRepository.py23
2 files changed, 34 insertions, 4 deletions
diff --git a/gbp/git.py b/gbp/git.py
index 01cb060d..74ce7117 100644
--- a/gbp/git.py
+++ b/gbp/git.py
@@ -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 3f195455..404eb3a3 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)
"""