Commit 533cb7d0 authored by Georges Racinet's avatar Georges Racinet 🎸

testhelpers: new commit_remove() helper method

This is the equivalent to `hg rm` for a single file.
parent 9935ee545308
......@@ -266,6 +266,23 @@ class LocalRepoWrapper(object):
return self.commit((path, ), message=message, add_remove=True,
def commit_remove(self, rpath, parent=None, message=None,
"""Make a commit removing the given file.
:param add_remove: ignored
:param commit_opts: see :meth:`commit` except ``add_removed`` which
is ignored.
commit_opts.pop('add_remove', None)
if message is None:
message = b"removing %s" % as_bytes(rpath)
os.unlink(os.path.join(self.repo.root, as_bytes(rpath)))
return self.commit((rpath, ), message=message, add_remove=True,
def update_bin(self, bin_node, **opts):
"""Update to a revision specified by its node in binary form.
......@@ -237,6 +237,24 @@ def test_phase(tmpdir):
assert ctx.phase() == phases.draft
@parametrize('msg_kind', ('no-message', 'explicit-message'))
def test_remove_file(tmpdir, msg_kind):
wrapper = LocalRepoWrapper.init(tmpdir)
wrapper.write_commit('foo', content='bar')
assert tmpdir.join('foo').read() == 'bar'
if msg_kind == 'no-message':
passed_msg, expected_msg = (None, b'removing foo')
passed_msg, expected_msg = ('explicit', b'explicit')
ctx = wrapper.commit_remove('foo', message=passed_msg)
assert ctx.description() == expected_msg
# also proves the file actually was in parent revision
assert ctx.filesremoved() == [b'foo']
assert not tmpdir.join('foo').exists()
def test_prune_update_hidden(tmpdir):
wrapper = LocalRepoWrapper.init(tmpdir,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment