[PATCH] commands.update() now works properly with a revision of 0

Mark Drago markdrago at gmail.com
Mon Mar 7 16:17:18 CST 2011


On Mon, Mar 7, 2011 at 16:33, Matt Mackall <mpm at selenic.com> wrote:
> On Mon, 2011-03-07 at 08:36 -0500, Mark Drago wrote:
>> # HG changeset patch
>> # User Mark Drago <markdrago at gmail.com>
>> # Date 1299504374 18000
>> # Node ID c3fc4daab4287029efc67f2a9b7b67c20847f027
>> # Parent  fac040b7e82277b765dfeb46561e130f8c63ed3e
>> commands.update() now works properly with a revision of 0
>>
>> Without this change commands.update() treats an integer 0 as if no revision
>> was passed and updates to the branch head.  This fix allows an integer 0 to
>> be detected as a revision number so the working directory is correctly
>> changed to revision 0 rather than the branch head.
>
> This looks fine except for the old-style test. See here for how to write
> a modern 'unified' test:
>
> http://mercurial.selenic.com/wiki/WritingTests#Writing_a_shell_script_test

I wasn't really confident that I had the unit test correct.  I can't
write this unit test in bash as the bug only occurs when calling
commands.update() directly.  I could write a test similar to the
example here: http://mercurial.selenic.com/wiki/WritingTests#Writing_a_Python_unit_test
.  However, the example there isn't very clear as to how to indicate
success vs. failure.  Perhaps starting a line of output with 'bad:' is
a failure?  Is there an existing test that I could use as a reference
in writing this test?

Thanks,
Mark.

>> diff -r fac040b7e822 -r c3fc4daab428 mercurial/commands.py
>> --- a/mercurial/commands.py   Sat Mar 05 16:34:59 2011 -0600
>> +++ b/mercurial/commands.py   Mon Mar 07 08:26:14 2011 -0500
>> @@ -4053,7 +4053,7 @@
>>      if rev and node:
>>          raise util.Abort(_("please specify just one revision"))
>>
>> -    if not rev:
>> +    if rev is None or rev == '':
>>          rev = node
>>
>>      # if we defined a bookmark, we have to remember the original bookmark name
>> diff -r fac040b7e822 -r c3fc4daab428 tests/test-update-rev-0
>> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
>> +++ b/tests/test-update-rev-0 Mon Mar 07 08:26:14 2011 -0500
>> @@ -0,0 +1,28 @@
>> +#!/usr/bin/env python
>> +"""
>> +Tests the behaviour of commands.update with a revision of 0
>> +"""
>> +from mercurial import ui, hg, commands
>> +
>> +myui = ui.ui()
>> +repo = hg.repository(myui, path='.', create=True)
>> +
>> +#create two revisions
>> +for i in range(2):
>> +    name = 'rev%d' % (i,)
>> +    f = open(name, 'w')
>> +    f.write('%s content' % (name,))
>> +    f.close()
>> +    commands.add(myui, repo, name)
>> +    commands.commit(myui, repo, message='%s commit' % (name,))
>> +
>> +#try updating to revision 0 via commands.update
>> +commands.update(myui, repo, rev=0)
>> +
>> +#see if we are at revision 0
>> +rev = repo[None].p1().rev()
>> +
>> +if rev == 0:
>> +    print 'OK.'
>> +else:
>> +    print 'ERROR: commands.update() does not properly switch to revision 0'
>> diff -r fac040b7e822 -r c3fc4daab428 tests/test-update-rev-0.out
>> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
>> +++ b/tests/test-update-rev-0.out     Mon Mar 07 08:26:14 2011 -0500
>> @@ -0,0 +1,2 @@
>> +0 files updated, 0 files merged, 1 files removed, 0 files unresolved
>> +OK.
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at selenic.com
>> http://selenic.com/mailman/listinfo/mercurial-devel
>
>
> --
> Mathematics is the supreme nostalgia of our time.
>
>
>


More information about the Mercurial-devel mailing list