# HG changeset patch # User Idan Kamara # Date 1313074449 -10800 # Node ID ca0d7e212cf832a9669c291fafce1c3b75ce0b92 # Parent 223e463c25e05f5e191163ca444ed3c4bdc82834 client: add bookmarks command diff -r 223e463c25e0 -r ca0d7e212cf8 hglib/client.py --- a/hglib/client.py Thu Aug 11 17:53:56 2011 +0300 +++ b/hglib/client.py Thu Aug 11 17:54:09 2011 +0300 @@ -157,6 +157,27 @@ self.rawcommand(args) + def bookmarks(self): + """ + Return the bookmarks as a list of (name, rev, node) and the + index of the current one. + + If there isn't a current one, -1 is returned as the index + """ + out = self.rawcommand(['bookmarks']) + + bms = [] + current = -1 + if out.rstrip() != 'no bookmarks set': + for line in out.splitlines(): + iscurrent, line = line[0:3], line[3:] + if '*' in iscurrent: + current = len(bms) + name, line = line.split(' ', 1) + rev, node = line.split(':') + bms.append((name, int(rev), node)) + return bms, current + def branch(self, name=None, clean=False, force=False): if name and clean: raise ValueError('cannot use both name and clean') diff -r 223e463c25e0 -r ca0d7e212cf8 tests/test-bookmarks.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-bookmarks.py Thu Aug 11 17:54:09 2011 +0300 @@ -0,0 +1,25 @@ +import common + +class test_bookmarks(common.basetest): + def test_empty(self): + self.assertEquals(self.client.bookmarks(), ([], -1)) + + def test_basic(self): + self.append('a', 'a') + rev0, node0 = self.client.commit('first', addremove=True) + self.append('a', 'a') + rev1, node1 = self.client.commit('second') + + self.client.bookmark('0', rev0) + self.assertEquals(self.client.bookmarks(), + ([('0', rev0, node0[:12])], -1)) + + self.client.bookmark('1', rev1) + self.assertEquals(self.client.bookmarks(), + ([('0', rev0, node0[:12]), + ('1', rev1, node1[:12])], 1)) + + #def test_spaces(self): + # self.client.bookmark('s pace', self.rev0) + # self.assertEquals(self.client.bookmarks(), + # ([('s pace', 0, self.rev0.node[:12])], -1))