From 320db0d24a3884c704b7d0d7c1356b5d704dcfb6 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Mon, 1 Dec 2014 11:36:52 +0200 Subject: pq: allow running actions in repo subdir This should make the usage of gbp-pq more flexible and prevent mistakes caused by e.g. running gbp-pq import under some subdirectory. Signed-off-by: Markus Lehtonen --- gbp/scripts/pq.py | 4 ++++ gbp/scripts/pq_rpm.py | 4 ++++ tests/component/rpm/test_pq_rpm.py | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 1e1e96b..11af997 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -388,6 +388,10 @@ def main(argv): gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 + if os.path.abspath('.') != repo.path: + gbp.log.warn("Switching to topdir before running commands") + os.chdir(repo.path) + try: current = repo.get_branch() if action == "export": diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 764ccff..3c22ccb 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -429,6 +429,10 @@ def main(argv): gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 + if os.path.abspath('.') != repo.path: + gbp.log.warn("Switching to topdir before running commands") + os.chdir(repo.path) + try: # Create base temporary directory for this run options.tmp_dir = tempfile.mkdtemp(dir=options.tmp_dir, diff --git a/tests/component/rpm/test_pq_rpm.py b/tests/component/rpm/test_pq_rpm.py index f0dac8d..16252f0 100644 --- a/tests/component/rpm/test_pq_rpm.py +++ b/tests/component/rpm/test_pq_rpm.py @@ -118,6 +118,18 @@ class TestPqRpm(RpmRepoTestBase): self._check_repo_state(repo, 'master-orphan', branches) eq_(repo.status()[' M'], ['packaging/gbp-test2.spec']) + def test_import_in_subdir(self): + """Test running gbp-rpm-pq from a subdir in the git tree""" + repo = self.init_test_repo('gbp-test2') + repo.set_branch('master-orphan') + branches = repo.get_local_branches() + ['patch-queue/master-orphan'] + os.chdir('packaging') + + # Running from subdir should be ok + eq_(mock_pq(['import']), 0) + self._check_repo_state(repo, 'patch-queue/master-orphan', branches) + + def test_rebase(self): """Basic test for rebase action""" repo = self.init_test_repo('gbp-test') -- cgit v1.2.3