aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-08-05 18:46:08 -0300
committerGuido Günther <agx@sigxcpu.org>2017-08-05 19:44:22 -0300
commit2320e1969145546688a6cd06d82fbeed78897046 (patch)
tree464afc9456ceb57c1d18505f992a55f88095f442
parente75a221260684d9a2d277c7ea2eb7e629caee331 (diff)
pq: don't create empty pq branch on rebase and switch
We always want to start from an imported series. Thanks: Chris Lamb for the reproducer
-rw-r--r--docs/chapters/patches.sgml85
-rw-r--r--gbp/scripts/common/pq.py7
-rwxr-xr-xgbp/scripts/pq.py13
-rw-r--r--tests/13_test_gbp_pq.py6
-rw-r--r--tests/component/rpm/test_pq_rpm.py8
5 files changed, 67 insertions, 52 deletions
diff --git a/docs/chapters/patches.sgml b/docs/chapters/patches.sgml
index b6084e55..ab3b0d33 100644
--- a/docs/chapters/patches.sgml
+++ b/docs/chapters/patches.sgml
@@ -137,54 +137,71 @@
<sect1 id="gbp.patches.newupstream">
<title>Importing a new upstream version</title>
- <para>After importing a new upstream version you can use the following commands
- to refresh <filename>debian/patches/</filename>:
+ <para>
+ Ideally one would import the current set of patches to the
+ patch-queue branch
+ (&gbp <option>pq</option> <option>import</option>) before
+ importing the new upstream version, then rebase these
+ (&gbp <option>pq</option> <option>rebase</option>) and finally
+ export (&gbp <option>pq</option> <option>export</option>) but
+ don't worry if you forgot to do so before importing the new version
+ (or if another team member imported the version already).
+ </para>
+
+ <para>
+ In this case you can make &gbp-pq; figure out where to apply the
+ patches by using the <option>--time-machine=</option> option. The
+ following command
</para>
+
<programlisting>
- &gbp-pq; rebase
- &gbp-pq; export --commit
+ &gbp-pq; import --force --time-machine=10
</programlisting>
-<para>
- Should the rebase fail (e.g. because the upstream source changed at
- the same place your patches modify the code) you can resolve this by
- using the options of &gitcmd; <option>rebase</option>. If you simply
- want to abort use
- &gitcmd; <option>rebase</option> <option>--abort</option>.
-</para>
-
-<para>
- If you forgot to create a patch-queue branch before importing the
- new upstream version or if you're not sure if it's up to date you can
- make &gbp-pq; figure out where to apply the patches by using
- the <option>--time-machine=</option>. E.g:
-</para>
+ <para>
+ would drop your current patch-queue branch (if existent) and
+ create a new one by going back in your commit history as far as 10
+ commits to find a place where your patches still
+ apply <footnote><para>This is not necessarily your debian branch
+ HEAD since the new upstream version might have changed so that the
+ patches no longer apply cleanly there.</para></footnote>. If it
+ finds such a commit on your debian branch it will create the
+ patch-queue branch from there and switch you to that branch. You
+ can now rework your patches to apply to the new upstream version
+ by using &gbp-pq <option>rebase</option>:
+ </para>
<programlisting>
- &gbp-pq; import --force --time-machine=10
+ &gbp-pq; rebase
</programlisting>
<para>
- would drop your current patch-queue branch and create a new one by
- going back in your commit history as far as 10 commits to find a place
- where your patches still apply. If it finds such a place it will
- create the patch-queue branch there and switch you to that branch.
- You can now rework your patches to apply to the new upstream version
- either by using &gbp-pq <option>rebase</option> or by using
- &gitcmd; <option>rebase</option> directly. Let's do the later:
-<para>
+ or you can invoke &gitcmd <option>rebase</option> directly:
+</para>
<programlisting>
- &gitcmd; rebase -i debian/sid
+ &gitcmd; rebase -i debian/sid
</programlisting>
-<para>
- Once done you can export your commits to patches again as describe
- above. See this in action in a
- <ulink url="https://honk.sigxcpu.org/piki/projects/git-buildpackage/videos/gbp-pq-new-upstream-version.ogv">short
- video</ulink>.
-</para>
+ <para>
+ Should the rebase fail (e.g. because the upstream source changed
+ at the same place your patches modify the code) you can resolve
+ this by using the options of &gitcmd; <option>rebase</option>. If
+ you simply want to abort use
+ &gitcmd; <option>rebase</option> <option>--abort</option>.
+ </para>
+ <para>
+ Once done you can export your commits to patch files again:
+ </para>
+<programlisting>
+ &gbp-pq; export --commit
+</programlisting>
+ <para>
+ See this in action in a
+ <ulink url="https://honk.sigxcpu.org/piki/projects/git-buildpackage/videos/gbp-pq-new-upstream-version.ogv">short
+ video</ulink>.
+ </para>
</sect1>
<sect1 id="gbp.patches.firstpatch">
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py
index 37eba6d0..ce05a99c 100644
--- a/gbp/scripts/common/pq.py
+++ b/gbp/scripts/common/pq.py
@@ -284,11 +284,8 @@ def switch_to_pq_branch(repo, branch):
pq_branch = pq_branch_name(branch)
if not repo.has_branch(pq_branch):
- try:
- repo.create_branch(pq_branch)
- except GitRepositoryError:
- raise GbpError("Cannot create patch-queue branch '%s'. "
- "Try 'rebase' instead." % pq_branch)
+ raise GbpError("Branch '%s' does not exist, try "
+ "'import' instead" % pq_branch)
gbp.log.info("Switching to '%s'" % pq_branch)
repo.set_branch(pq_branch)
diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py
index 1a0dcfa8..66a8d0dc 100755
--- a/gbp/scripts/pq.py
+++ b/gbp/scripts/pq.py
@@ -33,7 +33,7 @@ import gbp.log
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,
- switch_to_pq_branch, apply_single_patch,
+ apply_single_patch,
apply_and_commit_patch, switch_pq,
drop_pq, get_maintainer_from_control)
from gbp.scripts.common import ExitCodes
@@ -353,19 +353,16 @@ def import_quilt_patches(repo, branch, series, tries, force, pq_from,
def rebase_pq(repo, branch, pq_from, upstream_tag):
-
if is_pq_branch(branch):
base = pq_branch_base(branch)
else:
- switch_to_pq_branch(repo, branch)
- base = branch
+ raise GbpError("Rebase must be run from the patch-queue branch. "
+ "Try 'import' instead.")
if pq_on_upstream_tag(pq_from):
- _from = find_upstream_commit(repo, base, upstream_tag)
- else:
- _from = base
+ base = find_upstream_commit(repo, base, upstream_tag)
- GitCommand("rebase", cwd=repo.path)([_from])
+ GitCommand("rebase", cwd=repo.path)([base])
def usage_msg():
diff --git a/tests/13_test_gbp_pq.py b/tests/13_test_gbp_pq.py
index 1a7160dc..8a3a5cab 100644
--- a/tests/13_test_gbp_pq.py
+++ b/tests/13_test_gbp_pq.py
@@ -100,6 +100,7 @@ class TestApplySinglePatch(testutils.DebianGitTestRepo):
patch = gbp.patch_series.Patch(_patch_path('foo.patch'))
+ self.repo.create_branch(pq.pq_branch_name('master'))
pq.apply_single_patch(self.repo, 'master', patch, None)
self.assertIn(b'foo', self.repo.list_files())
@@ -230,6 +231,7 @@ class TestExport(testutils.DebianGitTestRepo):
opts = TestExport.Options()
opts.drop = True
+ repo.create_branch(pq.pq_branch_name('master'))
pq.switch_pq(repo, start)
self.assertEqual(repo.get_branch(), pq_branch)
export_patches(repo, pq_branch, opts)
@@ -243,6 +245,7 @@ class TestExport(testutils.DebianGitTestRepo):
pq_branch = os.path.join('patch-queue', start)
opts = TestExport.Options()
opts.commit = True
+ repo.create_branch(pq.pq_branch_name('master'))
pq.switch_pq(repo, start)
self.assertEqual(len(repo.get_commits()), 1)
self.assertEqual(repo.get_branch(), pq_branch)
@@ -271,6 +274,7 @@ class TestExport(testutils.DebianGitTestRepo):
f.write("patch2.diff\n")
repo.add_files('debian/patches')
repo.commit_all('Add series file')
+ repo.create_branch(pq.pq_branch_name('master'))
pq.switch_pq(repo, start)
self.assertEqual(len(repo.get_commits()), 2)
self.assertEqual(repo.get_branch(), pq_branch)
@@ -388,6 +392,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')
rebase_pq(self.repo,
branch=self.repo.get_branch(),
pq_from=TestFromTAG.Options.pq_from,
@@ -412,6 +417,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')
rebase_pq(self.repo,
branch=self.repo.get_branch(),
pq_from=TestFromTAG.Options.pq_from,
diff --git a/tests/component/rpm/test_pq_rpm.py b/tests/component/rpm/test_pq_rpm.py
index d7fdf9cb..114e6507 100644
--- a/tests/component/rpm/test_pq_rpm.py
+++ b/tests/component/rpm/test_pq_rpm.py
@@ -150,15 +150,13 @@ class TestPqRpm(RpmRepoTestBase):
"""Basic test for switch action"""
repo = self.init_test_repo('gbp-test')
branches = repo.get_local_branches() + ['patch-queue/master']
- # Switch to non-existent pq-branch should create one
- eq_(mock_pq(['switch']), 0)
- self._check_repo_state(repo, 'patch-queue/master', branches)
+ repo.create_branch('patch-queue/master')
# Switch to base branch and back to pq
eq_(mock_pq(['switch']), 0)
- self._check_repo_state(repo, 'master', branches)
- eq_(mock_pq(['switch']), 0)
self._check_repo_state(repo, 'patch-queue/master', branches)
+ eq_(mock_pq(['switch']), 0)
+ self._check_repo_state(repo, 'master', branches)
def test_switch_drop(self):
"""Basic test for drop action"""