diff --git a/perfact/zodbsync/commands/commit.py b/perfact/zodbsync/commands/commit.py new file mode 100644 index 0000000..75cb7a7 --- /dev/null +++ b/perfact/zodbsync/commands/commit.py @@ -0,0 +1,23 @@ +#!/usr/bin/python3 + +from ..subcommand import SubCommand + + +class Commit(SubCommand): + """ + Commit changes to given files, possibly prepending a commit that helps in a + layer setup. + """ + + @staticmethod + def add_args(parser): + parser.add_argument( + '-m', type=str, help="Commit message" + ) + parser.add_argument( + 'path', type=str, nargs='+', + help="Paths in which changes are to be commited" + ) + + def run(self): + pass diff --git a/perfact/zodbsync/main.py b/perfact/zodbsync/main.py index 344a676..d7c5214 100644 --- a/perfact/zodbsync/main.py +++ b/perfact/zodbsync/main.py @@ -29,6 +29,7 @@ from .commands.layer_hash import LayerHash from .commands.layer_init import LayerInit from .commands.layer_update import LayerUpdate +from .commands.commit import Commit class Runner(object): @@ -36,7 +37,8 @@ class Runner(object): Parses arguments to select the correct SubCommand subclass. """ commands = [Record, Playback, Watch, Pick, Upload, WithLock, Reset, Exec, - Reformat, Checkout, Freeze, LayerHash, LayerInit, LayerUpdate] + Reformat, Checkout, Freeze, LayerHash, LayerInit, LayerUpdate, + Commit] def __init__(self): """ diff --git a/perfact/zodbsync/tests/test_sync.py b/perfact/zodbsync/tests/test_sync.py index dfdd044..4984183 100644 --- a/perfact/zodbsync/tests/test_sync.py +++ b/perfact/zodbsync/tests/test_sync.py @@ -2186,3 +2186,27 @@ def test_layer_frozen(self): with open(source_fmt.format(self.repo.path)) as f: # ... content is in custom layer! assert f.read() == 'text_content' + + def test_layer_commit(self): + """ + Commit a change to a file that belongs to a lower layer. This creates + two commits, one where the old state is added to the custom layer and + one where the actual change is recorded. + """ + with self.runner.sync.tm: + self.app.manage_addProduct['OFSP'].manage_addFile(id='blob') + with self.addlayer() as layer: + self.run('record', '/blob') + shutil.move( + '{}/__root__/blob'.format(self.repo.path), + '{}/__root__/blob'.format(layer), + ) + with self.runner.sync.tm: + self.app.blob.manage_edit( + filedata='text_content', + content_type='text/plain', + title='BLOB' + ) + self.run('record', '/') + self.run('commit', '-m', 'change content', '__root__/blob') + assert self.gitoutput('status', '--porcelain') == ''