Mercurial > python-hglib
changeset 29:c072f525ea3e
client: add copy command
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Sun, 14 Aug 2011 00:48:40 +0300 |
parents | 221eeb3693f4 |
children | b7042bb3dbfd |
files | hglib/client.py tests/test-copy.py |
diffstat | 2 files changed, 42 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hglib/client.py Sun Aug 14 00:48:19 2011 +0300 +++ b/hglib/client.py Sun Aug 14 00:48:40 2011 +0300 @@ -301,6 +301,27 @@ return self._encoding + def copy(self, source, dest, after=False, force=False, dryrun=False, + include=None, exclude=None): + if not isinstance(source, list): + source = [source] + + source.append(dest) + args = cmdbuilder('copy', *source, A=after, f=force, n=dryrun, + I=include, X=exclude) + + # we could use Python 3 nonlocal here... + warnings = [False] + + def eh(ret, out, err): + if ret == 1: + warnings[0] = True + else: + raise error.CommandError(args, ret, out, err) + + self.rawcommand(args, eh=eh) + return not warnings[0] + def import_(self, patches, strip=None, force=False, nocommit=False, bypass=False, exact=False, importbranch=False, message=None, date=None, user=None, similarity=None):
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-copy.py Sun Aug 14 00:48:40 2011 +0300 @@ -0,0 +1,21 @@ +import common +import hglib + +class test_copy(common.basetest): + def test_basic(self): + self.append('a', 'a') + self.client.commit('first', addremove=True) + + self.assertTrue(self.client.copy('a', 'b')) + self.assertEquals(self.client.status()['A'], ['b']) + self.append('c', 'a') + self.assertTrue(self.client.copy('a', 'c', after=True)) + self.assertEquals(self.client.status()['A'], ['b', 'c']) + + # hg returns 0 even if there were warnings + #def test_warnings(self): + # self.append('a', 'a') + # self.client.commit('first', addremove=True) + + # self.assertTrue(self.client.copy('a', 'b')) + # self.assertFalse(self.client.copy('a', 'b'))