# HG changeset patch # User Idan Kamara # Date 1313272120 -10800 # Node ID c072f525ea3ec9bbcc14cbbbd54759b24e0e21ba # Parent 221eeb3693f4910bf047b7cfc0d00bea854934a5 client: add copy command diff -r 221eeb3693f4 -r c072f525ea3e hglib/client.py --- 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): diff -r 221eeb3693f4 -r c072f525ea3e tests/test-copy.py --- /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'))