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

Mark Drago markdrago at gmail.com
Mon Mar 7 07:36:02 CST 2011


# 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.

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.


More information about the Mercurial-devel mailing list