Mercurial > python-hglib
changeset 205:2d0ec6097d78 2.6.1
util: fix handling of empty short option
This one was overlooked at 32e8d51ec16c. A dense form, '-sVALUE', shouldn't
be used if an empty value is specified.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 30 Apr 2018 15:43:29 +0900 |
parents | b8edcb693518 |
children | 6caf386ec54d |
files | hglib/util.py tests/test-log.py |
diffstat | 2 files changed, 27 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/hglib/util.py Wed Apr 25 13:32:18 2018 -0400 +++ b/hglib/util.py Mon Apr 30 15:43:29 2018 +0900 @@ -111,6 +111,14 @@ True >>> cmdbuilder(b('cmd'), b('-a')) == [b('cmd'), b('--'), b('-a')] True + >>> cmdbuilder(b('cmd'), b('')) == [b('cmd'), b('--'), b('')] + True + >>> cmdbuilder(b('cmd'), s=b('')) == [b('cmd'), b('-s'), b('')] + True + >>> cmdbuilder(b('cmd'), s=[b('')]) == [b('cmd'), b('-s'), b('')] + True + >>> cmdbuilder(b('cmd'), long=b('')) == [b('cmd'), b('--long=')] + True """ cmd = [name] for arg, val in kwargs.items(): @@ -118,8 +126,9 @@ continue arg = pfx = arg.encode('latin-1').replace(b('_'), b('-')) + short = (len(arg) == 1) if arg != b('-'): - if len(arg) == 1: + if short: arg = pfx = b('-') + arg else: arg = b('--') + arg @@ -129,9 +138,17 @@ cmd.append(arg) elif isinstance(val, list): for v in val: - cmd.append(pfx + _cmdval(v)) + s = _cmdval(v) + if s or not short: + cmd.append(pfx + s) + else: + cmd.extend([arg, s]) else: - cmd.append(pfx + _cmdval(val)) + s = _cmdval(val) + if s or not short: + cmd.append(pfx + s) + else: + cmd.extend([arg, s]) args = [a for a in args if a is not None] if args:
--- a/tests/test-log.py Wed Apr 25 13:32:18 2018 -0400 +++ b/tests/test-log.py Mon Apr 30 15:43:29 2018 +0900 @@ -27,6 +27,13 @@ self.assertTrue(len(revs) == 1) self.assertEquals(revs[0].rev, b('0')) + def test_empty_short_option(self): + self.append('foobar', 'foobar') + self.client.commit(b('first'), addremove=True) + revs = self.client.log(keyword=b(''), files=[b('foobar')]) + self.assertTrue(len(revs) == 1) + self.assertEquals(revs[0].rev, b('0')) + # def test_errors(self): # self.assertRaisesRegexp(CommandError, 'abort: unknown revision', # self.client.log, 'foo')