summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-10-20 11:29:14 +0200
committerGuido Günther <agx@sigxcpu.org>2017-10-20 11:29:14 +0200
commit15510515a5fa98d212082057effb6b002310125e (patch)
tree3d7c867fedcdccff8ea01fdfe3edbf468bc5f9a2
parent17dbb90b105a098febd2a70dff07cf3e85ffa5cc (diff)
pq: import pq branch on switch
Closes: #761166
-rw-r--r--gbp/scripts/common/pq.py12
-rwxr-xr-xgbp/scripts/pq.py34
-rwxr-xr-xgbp/scripts/pq_rpm.py12
-rw-r--r--tests/13_test_gbp_pq.py14
-rw-r--r--tests/component/deb/test_pq.py9
5 files changed, 54 insertions, 27 deletions
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py
index b44588b6..be663a3e 100644
--- a/gbp/scripts/common/pq.py
+++ b/gbp/scripts/common/pq.py
@@ -290,7 +290,7 @@ def get_maintainer_from_control(repo):
def switch_to_pq_branch(repo, branch):
"""
- Switch to patch-queue branch if not already there, create it if it
+ Switch to patch-queue branch if not already on it.
doesn't exist yet
"""
if is_pq_branch(branch):
@@ -354,13 +354,3 @@ def drop_pq(repo, branch):
gbp.log.info("Dropped branch '%s'." % pq_branch)
else:
gbp.log.info("No patch queue branch found - doing nothing.")
-
-
-def switch_pq(repo, current):
- """Switch to patch-queue branch if on base branch and vice versa"""
- if is_pq_branch(current):
- base = pq_branch_base(current)
- gbp.log.info("Switching to %s" % base)
- repo.checkout(base)
- else:
- switch_to_pq_branch(repo, current)
diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py
index 2ac68ae2..7bf7736f 100755
--- a/gbp/scripts/pq.py
+++ b/gbp/scripts/pq.py
@@ -34,7 +34,7 @@ from gbp.patch_series import (PatchSeries, Patch)
from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base,
parse_gbp_commands, format_patch,
apply_single_patch,
- apply_and_commit_patch, switch_pq,
+ apply_and_commit_patch,
drop_pq, get_maintainer_from_control,
switch_to_pq_branch)
from gbp.scripts.common import ExitCodes
@@ -292,8 +292,7 @@ def import_quilt_patches(repo, branch, series, tries, force, pq_from,
pq_branch = pq_branch_name(branch)
repo.checkout(branch)
else:
- gbp.log.err("Already on a patch-queue branch '%s' - doing nothing." % branch)
- raise GbpError
+ raise GbpError("Already on a patch-queue branch '%s' - doing nothing." % branch)
else:
pq_branch = pq_branch_name(branch)
@@ -355,11 +354,7 @@ def import_quilt_patches(repo, branch, series, tries, force, pq_from,
def rebase_pq(repo, branch, options):
- # Import patches if not yet done
- if not repo.has_branch(pq_branch_name(branch)):
- gbp.log.info("No pq branch found, importing patches")
- import_pq(repo, branch, options)
-
+ maybe_import_pq(repo, branch, options)
# Make sure we're on the pq branch
switch_to_pq_branch(repo, branch)
if pq_on_upstream_tag(options.pq_from):
@@ -371,6 +366,7 @@ def rebase_pq(repo, branch, options):
def import_pq(repo, branch, options):
+ """Import quilt patches onto pq branch"""
series = SERIES_FILE
tries = options.time_machine if (options.time_machine > 0) else 1
num = import_quilt_patches(repo, branch, series, tries,
@@ -380,6 +376,26 @@ def import_pq(repo, branch, options):
(num, series, repo.get_branch()))
+def maybe_import_pq(repo, branch, options):
+ """Import quilt patches onto pq branch if pq branch does not exist yet"""
+ if not repo.has_branch(pq_branch_name(branch)):
+ gbp.log.info("No pq branch found, importing patches")
+ import_pq(repo, branch, options)
+ return True
+ return False
+
+
+def switch_pq(repo, branch, options):
+ """Switch to patch-queue branch if on base branch and vice versa"""
+ if is_pq_branch(branch):
+ base = pq_branch_base(branch)
+ gbp.log.info("Switching to %s" % base)
+ repo.checkout(base)
+ else:
+ maybe_import_pq(repo, branch, options)
+ switch_to_pq_branch(repo, branch)
+
+
def usage_msg():
return """%prog [options] action - maintain patches on a patch queue branch
Actions:
@@ -479,7 +495,7 @@ def main(argv):
maintainer = get_maintainer_from_control(repo)
apply_single_patch(repo, current, patch, maintainer, options.topic)
elif action == "switch":
- switch_pq(repo, current)
+ switch_pq(repo, current, options)
except KeyboardInterrupt:
retval = 1
gbp.log.err("Interrupted. Aborting.")
diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py
index 92a58792..7808e24b 100755
--- a/gbp/scripts/pq_rpm.py
+++ b/gbp/scripts/pq_rpm.py
@@ -41,7 +41,7 @@ from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base,
parse_gbp_commands, format_patch, format_diff,
switch_to_pq_branch, apply_single_patch,
apply_and_commit_patch,
- drop_pq, switch_pq)
+ drop_pq)
from gbp.scripts.common.buildpackage import dump_tree
@@ -348,6 +348,16 @@ def rebase_pq(repo, options):
GitCommand("rebase")([upstream_commit])
+def switch_pq(repo, current):
+ """Switch to patch-queue branch if on base branch and vice versa"""
+ if is_pq_branch(current):
+ base = pq_branch_base(current)
+ gbp.log.info("Switching to %s" % base)
+ repo.checkout(base)
+ else:
+ switch_to_pq_branch(repo, current)
+
+
def usage_msg():
return """%prog [options] action - maintain patches on a patch queue branch
Ations:
diff --git a/tests/13_test_gbp_pq.py b/tests/13_test_gbp_pq.py
index 6136454c..2e9f8a60 100644
--- a/tests/13_test_gbp_pq.py
+++ b/tests/13_test_gbp_pq.py
@@ -23,7 +23,9 @@ import unittest
from gbp.command_wrappers import GitCommand
from gbp.scripts.pq import (generate_patches, export_patches,
- import_quilt_patches, rebase_pq, SERIES_FILE)
+ import_quilt_patches, rebase_pq,
+ switch_pq,
+ SERIES_FILE)
import gbp.scripts.common.pq as pq
import gbp.patch_series
@@ -239,7 +241,7 @@ class TestExport(testutils.DebianGitTestRepo):
opts.drop = True
repo.create_branch(pq.pq_branch_name('master'))
- pq.switch_pq(repo, start)
+ switch_pq(repo, start, opts)
self.assertEqual(repo.get_branch(), pq_branch)
export_patches(repo, pq_branch, opts)
self.assertEqual(repo.get_branch(), start)
@@ -253,7 +255,7 @@ class TestExport(testutils.DebianGitTestRepo):
opts = TestExport.Options()
opts.commit = True
repo.create_branch(pq.pq_branch_name('master'))
- pq.switch_pq(repo, start)
+ switch_pq(repo, start, opts)
self.assertEqual(len(repo.get_commits()), 1)
self.assertEqual(repo.get_branch(), pq_branch)
self.add_file('foo', 'foo')
@@ -282,7 +284,7 @@ class TestExport(testutils.DebianGitTestRepo):
repo.add_files('debian/patches')
repo.commit_all('Add series file')
repo.create_branch(pq.pq_branch_name('master'))
- pq.switch_pq(repo, start)
+ switch_pq(repo, start, opts)
self.assertEqual(len(repo.get_commits()), 2)
self.assertEqual(repo.get_branch(), pq_branch)
export_patches(repo, pq_branch, opts)
@@ -394,7 +396,7 @@ class TestFromTAG(testutils.DebianGitTestRepo):
self.assertTrue(os.path.exists(os.path.join(self.repo.path,
os.path.dirname(SERIES_FILE),
'added-bar.patch')))
- pq.switch_pq(self.repo, 'master')
+ switch_pq(self.repo, 'master', TestFromTAG.Options)
rebase_pq(self.repo,
branch=self.repo.get_branch(),
options=TestFromTAG.Options())
@@ -418,7 +420,7 @@ class TestFromTAG(testutils.DebianGitTestRepo):
' -- Mr. T. S. <t@example.com> '
'Thu, 01 Jan 1970 00:00:00 +0000\n'
)
- pq.switch_pq(self.repo, 'master')
+ switch_pq(self.repo, 'master', TestFromTAG.Options())
rebase_pq(self.repo,
branch=self.repo.get_branch(),
options=TestFromTAG.Options())
diff --git a/tests/component/deb/test_pq.py b/tests/component/deb/test_pq.py
index 2f0f247e..5a2395b4 100644
--- a/tests/component/deb/test_pq.py
+++ b/tests/component/deb/test_pq.py
@@ -38,11 +38,20 @@ class TestPq(ComponentTestBase):
@RepoFixtures.quilt30()
def test_rebase_import(self, repo):
"""Test if rebase imports patches first"""
+ eq_(repo.branch, 'master')
eq_(repo.has_branch('patch-queue/master'), False)
self._test_pq(repo, 'rebase')
eq_(repo.has_branch('patch-queue/master'), True)
@RepoFixtures.quilt30()
+ def test_switch_import(self, repo):
+ """Test if switch imports patches first"""
+ eq_(repo.branch, 'master')
+ eq_(repo.has_branch('patch-queue/master'), False)
+ self._test_pq(repo, 'switch')
+ eq_(repo.has_branch('patch-queue/master'), True)
+
+ @RepoFixtures.quilt30()
def test_empty_cycle(self, repo):
eq_(repo.has_branch('patch-queue/master'), False)
eq_(repo.branch, 'master')