Mercurial > python-hglib
changeset 20:6a9d16ddae31
client: add update command
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Thu, 11 Aug 2011 15:42:59 +0300 |
parents | 19d2c55c3928 |
children | ffef7df076e8 |
files | hglib/client.py tests/test-update.py |
diffstat | 2 files changed, 94 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hglib/client.py Thu Aug 11 15:42:58 2011 +0300 +++ b/hglib/client.py Thu Aug 11 15:42:59 2011 +0300 @@ -341,3 +341,29 @@ return self._parserevs(out)[0] + def update(self, rev=None, clean=False, check=False, date=None): + """ + Update the repository's working directory to changeset specified by rev. + If rev isn't specified, update to the tip of the current named branch. + + Return the number of files (updated, merged, removed, unresolved) + """ + if clean and check: + raise ValueError('clean and check cannot both be True') + + args = cmdbuilder('update', r=rev, C=clean, c=check, d=date) + + def eh(ret, out, err): + if ret == 1: + return out + + raise error.CommandError(args, ret, out, err) + + + out = self.rawcommand(args, eh=eh) + + # filter out 'merging ...' lines + out = util.skiplines(out, 'merging ') + + counters = out.rstrip().split(', ') + return tuple(int(s.split(' ', 1)[0]) for s in counters)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-update.py Thu Aug 11 15:42:59 2011 +0300 @@ -0,0 +1,68 @@ +import common +from hglib import error + +class test_update(common.basetest): + def setUp(self): + common.basetest.setUp(self) + self.append('a', 'a') + self.rev0, self.node0 = self.client.commit('first', addremove=True) + self.append('a', 'a') + self.rev1, self.node1 = self.client.commit('second') + + def test_basic(self): + u, m, r, ur = self.client.update(self.rev0) + self.assertEquals(u, 1) + self.assertEquals(m, 0) + self.assertEquals(r, 0) + self.assertEquals(ur, 0) + + def test_unresolved(self): + self.client.update(self.rev0) + self.append('a', 'b') + u, m, r, ur = self.client.update() + self.assertEquals(u, 0) + self.assertEquals(m, 0) + self.assertEquals(r, 0) + self.assertEquals(ur, 1) + self.assertEquals(self.client.status()['M'][0], 'a') + + def test_merge(self): + self.append('a', '\n\n\n\nb') + rev2, node2 = self.client.commit('third') + self.append('a', 'b') + self.client.commit('fourth') + self.client.update(rev2) + old = open('a').read() + open('a', 'w').write('a' + old) + u, m, r, ur = self.client.update() + self.assertEquals(u, 0) + self.assertEquals(m, 1) + self.assertEquals(r, 0) + self.assertEquals(ur, 0) + self.assertEquals(self.client.status()['M'][0], 'a') + + def test_tip(self): + self.client.update(self.rev0) + u, m, r, ur = self.client.update() + self.assertEquals(u, 1) + self.assertEquals(self.client.parents()[0].node, self.node1) + + self.client.update(self.rev0) + self.append('a', 'b') + rev2, node2 = self.client.commit('new head') + self.client.update(self.rev0) + + self.client.update() + self.assertEquals(self.client.parents()[0].node, node2) + + def test_check_clean(self): + self.assertRaises(ValueError, self.client.update, clean=True, check=True) + + def test_clean(self): + old = open('a').read() + self.append('a', 'b') + self.assertRaises(error.CommandError, self.client.update, check=True) + + u, m, r, ur = self.client.update(clean=True) + self.assertEquals(u, 1) + self.assertEquals(old, open('a').read())