Skip to content
Snippets Groups Projects
Commit d8b7d77b61d7 authored by Georges Racinet's avatar Georges Racinet
Browse files

testhelpers: write_commit branch kwarg

parent 3b02a4edcda8
No related branches found
No related tags found
No related merge requests found
......@@ -56,7 +56,9 @@
ui = make_ui(base_ui, config=config)
return cls(hg.repository(ui, path))
def write_commit(self, rpath, content=None, message=None, parent=None):
def write_commit(self, rpath,
content=None, message=None,
parent=None, branch=None):
"""Write content at rpath and commit in one call.
This is meant to allow fast and efficient preparation of
......@@ -88,6 +90,9 @@
if parent is not None:
self.update_bin(parent)
if branch is not None:
self.repo.dirstate.setbranch(branch)
flags = 'wb' if isinstance(content, bytes) else 'w'
with open(path, flags) as fobj:
fobj.write(content)
......
......@@ -98,8 +98,8 @@
assert foo.read() == 'Foo 1'
def test_write_commit_branching(tmpdir):
def test_write_commit_named_branch(tmpdir):
"""Demonstrate the use of write_commit with parent."""
wrapper = LocalRepoWrapper.init(tmpdir)
node0 = wrapper.write_commit('foo', content='Foo 0')
wrapper.write_commit('foo', content='Foo 1')
......@@ -102,7 +102,8 @@
"""Demonstrate the use of write_commit with parent."""
wrapper = LocalRepoWrapper.init(tmpdir)
node0 = wrapper.write_commit('foo', content='Foo 0')
wrapper.write_commit('foo', content='Foo 1')
nodebr = wrapper.write_commit('foo', content='Foo branch', parent=node0)
nodebr = wrapper.write_commit('foo', content='Foo branch',
parent=node0, branch='other')
ctxbr = wrapper.repo[nodebr]
......@@ -107,3 +108,4 @@
ctxbr = wrapper.repo[nodebr]
assert ctxbr.branch() == 'other'
assert [c.node() for c in ctxbr.parents()] == [node0]
......@@ -109,1 +111,14 @@
assert [c.node() for c in ctxbr.parents()] == [node0]
def test_write_commit_wild_branch(tmpdir):
"""Demonstrate the use of write_commit with parent."""
wrapper = LocalRepoWrapper.init(tmpdir)
node0 = wrapper.write_commit('foo', content='Foo 0')
wrapper.write_commit('foo', content='Foo 1')
nodebr = wrapper.write_commit('foo', content='Foo branch',
parent=node0)
ctxbr = wrapper.repo[nodebr]
assert ctxbr.branch() == 'default'
assert [c.node() for c in ctxbr.parents()] == [node0]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment