# HG changeset patch # User Idan Kamara # Date 1312924865 -10800 # Node ID 0549d00a617db65ce0e28c1657c0514c8ae6826e # Parent fce3102c19e5a20ba42a609d51b26d5bbe9b9808 client: add missing options to branch() and add some more tests diff -r fce3102c19e5 -r 0549d00a617d hglib/client.py --- a/hglib/client.py Tue Aug 09 23:24:40 2011 +0300 +++ b/hglib/client.py Wed Aug 10 00:21:05 2011 +0300 @@ -141,9 +141,20 @@ self.server = None return ret - def branch(self, name=None): - if not name: - return self.rawcommand(['branch']).rstrip() + def branch(self, name=None, clean=False, force=False): + if name and clean: + raise ValueError('cannot use both name and clean') + + args = cmdbuilder('branch', name, f=force, C=clean) + out = self.rawcommand(args).rstrip() + + if name: + return name + elif not clean: + return out + else: + # len('reset working directory to branch ') == 34 + return out[34:] def branches(self): out = self.rawcommand(['branches']) diff -r fce3102c19e5 -r 0549d00a617d tests/test-branch.py --- a/tests/test-branch.py Tue Aug 09 23:24:40 2011 +0300 +++ b/tests/test-branch.py Wed Aug 10 00:21:05 2011 +0300 @@ -2,10 +2,38 @@ import hglib class test_branch(common.basetest): + def test_empty(self): + self.assertEquals(self.client.branch(), 'default') + def test_basic(self): - self.assertEquals(self.client.branch(), 'default') + self.assertEquals(self.client.branch('foo'), 'foo') self.append('a', 'a') rev = self.client.commit('first', addremove=True) - branches = self.client.branches() + + self.assertEquals(rev.branch, 'foo') + self.assertEquals(self.client.branches()[rev.branch], rev) + + def test_reset_with_name(self): + self.assertRaises(ValueError, self.client.branch, 'foo', clean=True) + + def test_reset(self): + self.client.branch('foo') + self.assertEquals(self.client.branch(clean=True), 'default') - self.assertEquals(rev, branches[rev.branch]) + def test_exists(self): + self.append('a', 'a') + self.client.commit('first', addremove=True) + self.client.branch('foo') + self.append('a', 'a') + self.client.commit('second') + self.assertRaises(hglib.error.CommandError, self.client.branch, 'default') + + def test_force(self): + self.append('a', 'a') + self.client.commit('first', addremove=True) + self.client.branch('foo') + self.append('a', 'a') + self.client.commit('second') + + self.assertRaises(hglib.error.CommandError, self.client.branch, 'default') + self.assertEquals(self.client.branch('default', force=True), 'default')