diff --git a/gbp/deb/git.py b/gbp/deb/git.py index 23d3ee7e..f4c7eaf4 100644 --- a/gbp/deb/git.py +++ b/gbp/deb/git.py @@ -32,8 +32,8 @@ class DebianGitRepository(GitRepository): '%(?P([^%]|\\%))+' '\)s') - def __init__(self, path): - super(DebianGitRepository, self).__init__(path) + def __init__(self, *args, **kwargs): + super(DebianGitRepository, self).__init__(*args, **kwargs) self.pristine_tar = DebianPristineTar(self) def tree_drop_dirs(self, tree, dirs): diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index 59e920b1..18e86de7 100644 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -423,8 +423,10 @@ def main(argv): return ExitCodes.parse_error try: + old_cwd = os.path.abspath(os.path.curdir) try: - repo = DebianGitRepository('.') + repo = DebianGitRepository('.', toplevel=False) + os.chdir(repo.path) except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) @@ -566,6 +568,8 @@ def main(argv): if str(err): gbp.log.err(err) ret = 1 + finally: + os.chdir(old_cwd) return ret diff --git a/tests/11_test_dch_main.py b/tests/11_test_dch_main.py index a9b2146a..58571687 100644 --- a/tests/11_test_dch_main.py +++ b/tests/11_test_dch_main.py @@ -81,7 +81,8 @@ def run_dch(self, dch_options=None): options.extend(dch_options) ret = dch.main(options) self.assertEqual(ret, 0) - return open("debian/changelog").readlines() + cl = os.path.join(self.repo.path, 'debian/changelog') + return open(cl).readlines() def test_dch_main_new_upstream_version(self): """Test dch.py like gbp dch script does: new upstream version""" @@ -399,3 +400,7 @@ def test_dch_main_no_git_author(self): options = ["--no-git-author", '-S', '-a'] lines = self.run_dch(options) self.assertNotIn("-- gbp test user", "\n".join(lines)) + + def test_dch_subdir(self): + os.chdir('debian/') + self.run_dch()