Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add commit subcommand #133

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions perfact/zodbsync/commands/commit.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion perfact/zodbsync/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
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):
"""
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):
"""
Expand Down
24 changes: 24 additions & 0 deletions perfact/zodbsync/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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') == ''
Loading