Skip to content

Commit 637159a

Browse files
bysiberzzzeek
authored andcommitted
Add --splice support to merge command
Added ``--splice`` support to the :func:`.merge` command. Previously, the merge command would suggest using ``--splice`` when attempting to merge non-head revisions, but the flag was not actually accepted by the command. The ``splice`` parameter is now available in both the command-line interface and the :func:`.command.merge` function, matching the existing support in :func:`.command.revision`. Pull request courtesy Kadir Can Ozden. Fixes: #1712 Closes: #1794 Pull-request: #1794 Pull-request-sha: a0f9b6d Change-Id: I12125061777b829b98663adab1701154c6f7c3ac
1 parent 2854248 commit 637159a

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

alembic/command.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ def merge(
385385
message: Optional[str] = None,
386386
branch_label: Optional[_RevIdType] = None,
387387
rev_id: Optional[str] = None,
388+
splice: bool = False,
388389
) -> Optional[Script]:
389390
"""Merge two revisions together. Creates a new migration file.
390391
@@ -399,6 +400,11 @@ def merge(
399400
:param rev_id: hardcoded revision identifier instead of generating a new
400401
one.
401402
403+
:param splice: if True, allow the merge to create a new branch point
404+
even if the given revisions are not heads.
405+
406+
.. versionadded:: 1.18.5
407+
402408
.. seealso::
403409
404410
:ref:`branches`
@@ -435,6 +441,7 @@ def nothing(rev, context):
435441
refresh=True,
436442
head=revisions,
437443
branch_labels=branch_label,
444+
splice=splice,
438445
**template_args, # type:ignore[arg-type]
439446
)
440447

docs/build/unreleased/1712.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. change::
2+
:tags: usecase, commands
3+
:tickets: 1712
4+
5+
Added ``--splice`` support to the :func:`.merge` command. Previously, the
6+
merge command would suggest using ``--splice`` when attempting to merge
7+
non-head revisions, but the flag was not actually accepted by the command.
8+
The ``splice`` parameter is now available in both the command-line
9+
interface and the :func:`.command.merge` function, matching the existing
10+
support in :func:`.command.revision`. Pull request courtesy Kadir Can
11+
Ozden.

tests/test_command.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,38 @@ def test_merge_cmd_revision_environment(self, rev_env):
276276

277277
assert os.path.exists(rev.path)
278278

279+
def test_merge_cmd_splice(self):
280+
"""merge with --splice allows non-head revisions to be merged."""
281+
cfg = self.cfg
282+
self.a, self.b, self.c = three_rev_fixture(cfg)
283+
self.d, self.e, self.f = multi_heads_fixture(
284+
cfg, self.a, self.b, self.c
285+
)
286+
# e and f are heads, but b is not a head.
287+
# merging b and c (at least one is not a head) should fail
288+
# without splice.
289+
with expect_raises_message(
290+
util.CommandError,
291+
"please specify --splice",
292+
):
293+
command.merge(
294+
self.cfg,
295+
[self.b, self.d],
296+
rev_id="should_fail",
297+
)
298+
# with splice=True, it should succeed
299+
command.merge(
300+
self.cfg,
301+
[self.b, self.d],
302+
rev_id="splice_merge",
303+
splice=True,
304+
)
305+
rev = ScriptDirectory.from_config(self.cfg).get_revision(
306+
"splice_merge"
307+
)
308+
assert os.path.exists(rev.path)
309+
eq_(rev.module.down_revision, (self.b, self.d))
310+
279311

280312
class CurrentTest(_BufMixin, TestBase):
281313
@classmethod

0 commit comments

Comments
 (0)