aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-01-20 17:12:03 +0100
committerGuido Günther <agx@sigxcpu.org>2017-01-20 17:17:54 +0100
commit5c23d417c47b2a1a38f3d62335dd88e7b9617754 (patch)
treef7e142fafe85b3a58cf52b8d4e0cb2123b7c97f7
parentba4f5264ce4dd95025272d43df1a34dd3110087a (diff)
GitRepository: properly determine git-dir
instead of assuming '.git' Heavily based on a patch by Markus Lehtonnen Closes: #674015
-rw-r--r--gbp/git/repository.py14
-rw-r--r--tests/component/deb/test_import_orig.py16
-rw-r--r--tests/doctests/test_GitRepository.py16
3 files changed, 44 insertions, 2 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index cc916a6..78b15d3 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -85,7 +85,18 @@ class GitRepository(object):
raise GitRepositoryError(
"Failed to get repository state at '%s'" % self.path)
self._bare = False if out.strip() != 'true' else True
- self._git_dir = '' if self._bare else '.git'
+
+ def _get_git_dir(self):
+ out, dummy, ret = self._git_inout('rev-parse', ['--git-dir'],
+ capture_stderr=True)
+ if ret:
+ raise GitRepositoryError(
+ "Failed to determine repos git-dir at '%s'" % self.path)
+ git_dir = out.strip()
+ if os.path.isabs(git_dir):
+ self._git_dir = git_dir
+ else:
+ self._git_dir = os.path.abspath(os.path.join(self.path, git_dir))
def __init__(self, path):
self._path = os.path.abspath(path)
@@ -100,6 +111,7 @@ class GitRepository(object):
except:
raise GitRepositoryError("No Git repository at '%s'" % self.path)
self._check_bare()
+ self._get_git_dir()
@staticmethod
def __build_env(extra_env):
diff --git a/tests/component/deb/test_import_orig.py b/tests/component/deb/test_import_orig.py
index 5b9ec9b..7665c65 100644
--- a/tests/component/deb/test_import_orig.py
+++ b/tests/component/deb/test_import_orig.py
@@ -299,3 +299,19 @@ class TestImportOrig(ComponentTestBase):
with assert_raises(KeyError):
t.getmember(f)
t.close()
+
+ @RepoFixtures.quilt30(DEFAULT_DSC, opts=['--pristine-tar'])
+ def test_import_in_submodule(self, repo):
+ """
+ Test that importing works if repo is a git submodule (#674015)
+ """
+ parent_repo = GitRepository.create('../parent')
+ parent_repo.add_submodule(repo.path)
+ parent_repo.update_submodules(init=True, recursive=True)
+ submodule = GitRepository(os.path.join(parent_repo.path,
+ 'hello-debhelper'))
+ ok_(submodule.path.endswith, 'parent/hello-debhelper')
+ os.chdir(submodule.path)
+ orig = self._orig('2.8')
+ submodule.create_branch('upstream', 'origin/upstream')
+ ok_(import_orig(['arg0', '--no-interactive', orig]) == 0)
diff --git a/tests/doctests/test_GitRepository.py b/tests/doctests/test_GitRepository.py
index cc3933a..30a846e 100644
--- a/tests/doctests/test_GitRepository.py
+++ b/tests/doctests/test_GitRepository.py
@@ -739,7 +739,7 @@ def test_create_bare():
>>> bare = gbp.git.GitRepository.create(dirs['bare'], bare=True, description="msg")
>>> bare.path == dirs['bare']
True
- >>> bare.git_dir[:-1] == dirs['bare']
+ >>> bare.git_dir == dirs['bare']
True
>>> type(bare) == gbp.git.GitRepository
True
@@ -1021,4 +1021,18 @@ def test_set_user_name_and_email():
>>> repo.set_user_email("stapelberg@test.invalid")
"""
+
+def test_git_dir():
+ """
+ Properties tested:
+ - L{gbp.git.GitRepository.git_dir}
+ >>> import os, gbp.git
+ >>> git_dir = os.path.join(dirs['repo'], '.git')
+ >>> os.environ['GIT_DIR'] = git_dir
+ >>> somewhere = gbp.git.GitRepository(os.path.join(dirs['repo'], '..'))
+ >>> somewhere.git_dir == git_dir
+ True
+ >>> del os.environ['GIT_DIR']
+ """
+
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: