Skip to content

Commit 6082175

Browse files
authored
T289742: Extend zodbsync with an additional command zodbsync ff (#148)
1 parent 2e33cad commit 6082175

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
3+
from ..subcommand import SubCommand
4+
5+
6+
class FF(SubCommand):
7+
'''
8+
Perform a fast-forward merge to the target commit and apply changed paths
9+
'''
10+
@staticmethod
11+
def add_args(parser):
12+
parser.add_argument(
13+
'--skip-errors', action='store_true', default=False,
14+
help='Skip failed objects and continue',
15+
)
16+
parser.add_argument(
17+
'--dry-run', action='store_true', default=False,
18+
help='Only check for conflicts and roll back at the end.',
19+
)
20+
parser.add_argument(
21+
'commit', type=str,
22+
help='''Target commit'''
23+
)
24+
25+
@SubCommand.gitexec
26+
def run(self):
27+
target = self.args.commit
28+
self.logger.info('Attempting fast-forward merge to %s.' % target)
29+
self.gitcmd_run('merge', '--ff-only', target)

perfact/zodbsync/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
from .commands.freeze import Freeze
2929
from .commands.layer_init import LayerInit
3030
from .commands.layer_update import LayerUpdate
31+
from .commands.fastforward import FF
3132

3233

3334
class Runner(object):
3435
"""
3536
Parses arguments to select the correct SubCommand subclass.
3637
"""
3738
commands = [Record, Playback, Watch, Pick, Upload, WithLock, Reset, Exec,
38-
Reformat, Checkout, Freeze, LayerInit, LayerUpdate]
39+
Reformat, Checkout, Freeze, LayerInit, LayerUpdate, FF]
3940

4041
def __init__(self):
4142
"""

perfact/zodbsync/tests/test_sync.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,29 @@ def test_watch_dump_setup(self):
715715
tofind.remove(obj['path'])
716716
assert tofind == []
717717

718+
def test_ff(self):
719+
"""
720+
Change the title on a second branch,
721+
perform a fast-forward merge to it,
722+
and verify that the change is correctly applied.
723+
"""
724+
self.gitrun('checkout', '-b', 'second')
725+
path = self.repo.path + '/__root__/index_html/__meta__'
726+
with open(path) as f:
727+
lines = f.readlines()
728+
lines = [
729+
line if "('title', " not in line
730+
else " ('title', 'test-ff'),\n"
731+
for line in lines
732+
]
733+
with open(path, 'w') as f:
734+
f.writelines(lines)
735+
self.gitrun('commit', '-a', '-m', 'Change title via ff')
736+
737+
self.gitrun('checkout', 'autotest')
738+
self.run('ff', 'second')
739+
assert self.app.index_html.title == 'test-ff'
740+
718741
def test_reset(self):
719742
"""
720743
Change the title of index_html in a second branch, reset to it and

0 commit comments

Comments
 (0)