diff --git a/perfact/zodbsync/commands/fastforward.py b/perfact/zodbsync/commands/fastforward.py new file mode 100644 index 0000000..1e7bf5d --- /dev/null +++ b/perfact/zodbsync/commands/fastforward.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +from ..subcommand import SubCommand + + +class FF(SubCommand): + ''' + Perform a fast-forward merge to the target commit and apply changed paths + ''' + @staticmethod + def add_args(parser): + parser.add_argument( + '--skip-errors', action='store_true', default=False, + help='Skip failed objects and continue', + ) + parser.add_argument( + '--dry-run', action='store_true', default=False, + help='Only check for conflicts and roll back at the end.', + ) + parser.add_argument( + 'commit', type=str, + help='''Target commit''' + ) + + @SubCommand.gitexec + def run(self): + target = self.args.commit + self.logger.info('Attempting fast-forward merge to %s.' % target) + self.gitcmd_run('merge', '--ff-only', target) diff --git a/perfact/zodbsync/main.py b/perfact/zodbsync/main.py index 1ca4a6f..845ccc2 100644 --- a/perfact/zodbsync/main.py +++ b/perfact/zodbsync/main.py @@ -28,6 +28,7 @@ from .commands.freeze import Freeze from .commands.layer_init import LayerInit from .commands.layer_update import LayerUpdate +from .commands.fastforward import FF class Runner(object): @@ -35,7 +36,7 @@ class Runner(object): Parses arguments to select the correct SubCommand subclass. """ commands = [Record, Playback, Watch, Pick, Upload, WithLock, Reset, Exec, - Reformat, Checkout, Freeze, LayerInit, LayerUpdate] + Reformat, Checkout, Freeze, LayerInit, LayerUpdate, FF] def __init__(self): """ diff --git a/perfact/zodbsync/tests/test_sync.py b/perfact/zodbsync/tests/test_sync.py index 7386356..5449907 100644 --- a/perfact/zodbsync/tests/test_sync.py +++ b/perfact/zodbsync/tests/test_sync.py @@ -715,6 +715,29 @@ def test_watch_dump_setup(self): tofind.remove(obj['path']) assert tofind == [] + def test_ff(self): + """ + Change the title on a second branch, + perform a fast-forward merge to it, + and verify that the change is correctly applied. + """ + self.gitrun('checkout', '-b', 'second') + path = self.repo.path + '/__root__/index_html/__meta__' + with open(path) as f: + lines = f.readlines() + lines = [ + line if "('title', " not in line + else " ('title', 'test-ff'),\n" + for line in lines + ] + with open(path, 'w') as f: + f.writelines(lines) + self.gitrun('commit', '-a', '-m', 'Change title via ff') + + self.gitrun('checkout', 'autotest') + self.run('ff', 'second') + assert self.app.index_html.title == 'test-ff' + def test_reset(self): """ Change the title of index_html in a second branch, reset to it and