From 53b5af5898a8be27ec5f03d88e3e6c76232f6292 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 23 Jan 2017 08:44:53 +0100 Subject: dch: Allow to run from subdirectory Resolves #1 --- gbp/deb/git.py | 4 ++-- gbp/scripts/dch.py | 6 +++++- tests/11_test_dch_main.py | 7 ++++++- 3 files changed, 13 insertions(+), 4 deletions(-) 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 @@ class TestScriptDch(DebianGitTestRepo): 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 @@ class TestScriptDch(DebianGitTestRepo): 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() -- cgit v1.2.3