changeset 19482:499fc471296b stable

update: add tracking of interrupted updates (issue3113) This takes advantage of the new checkunfinished infrastructure
author Matt Mackall <mpm@selenic.com>
date Thu, 25 Jul 2013 00:33:28 -0500
parents ee1af0f33d0e
children a987972de0e6
files mercurial/cmdutil.py mercurial/commands.py mercurial/merge.py tests/test-merge1.t
diffstat 4 files changed, 42 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Thu Jul 25 00:00:47 2013 -0500
+++ b/mercurial/cmdutil.py	Thu Jul 25 00:33:28 2013 -0500
@@ -2110,7 +2110,9 @@
 # (state file, clearable, error, hint)
 unfinishedstates = [
     ('graftstate', True, _('graft in progress'),
-     _("use 'hg graft --continue' or 'hg update' to abort"))
+     _("use 'hg graft --continue' or 'hg update' to abort")),
+    ('updatestate', True, _('last update was interrupted'),
+     _("use 'hg update' to get a consistent checkout"))
     ]
 
 def checkunfinished(repo):
--- a/mercurial/commands.py	Thu Jul 25 00:00:47 2013 -0500
+++ b/mercurial/commands.py	Thu Jul 25 00:33:28 2013 -0500
@@ -5482,7 +5482,9 @@
     t = ', '.join(t)
     cleanworkdir = False
 
-    if len(parents) > 1:
+    if repo.vfs.exists('updatestate'):
+        t += _(' (interrupted update)')
+    elif len(parents) > 1:
         t += _(' (merge)')
     elif branch != parents[0].branch():
         t += _(' (new branch)')
--- a/mercurial/merge.py	Thu Jul 25 00:00:47 2013 -0500
+++ b/mercurial/merge.py	Thu Jul 25 00:33:28 2013 -0500
@@ -747,12 +747,17 @@
             fp1, fp2, xp1, xp2 = fp2, nullid, xp2, ''
         if not partial:
             repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2)
+            # note that we're in the middle of an update
+            repo.vfs.write('updatestate', p2.hex())
 
         stats = applyupdates(repo, actions, wc, p2, pa, overwrite)
 
         if not partial:
             repo.setparents(fp1, fp2)
             recordupdates(repo, actions, branchmerge)
+            # update completed, clear state
+            util.unlink(repo.join('updatestate'))
+
             if not branchmerge:
                 repo.dirstate.setbranch(p2.branch())
     finally:
--- a/tests/test-merge1.t	Thu Jul 25 00:00:47 2013 -0500
+++ b/tests/test-merge1.t	Thu Jul 25 00:33:28 2013 -0500
@@ -23,6 +23,37 @@
 
   $ hg update 0
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+
+Test interrupted updates by exploiting our non-handling of directory collisions
+
+  $ mkdir b
+  $ hg up
+  abort: Is a directory: '$TESTTMP/t/b'
+  [255]
+  $ hg ci
+  abort: last update was interrupted
+  (use 'hg update' to get a consistent checkout)
+  [255]
+  $ hg sum
+  parent: 0:538afb845929 
+   commit #0
+  branch: default
+  commit: (interrupted update)
+  update: 1 new changesets (update)
+  $ rmdir b
+  $ hg up
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg sum
+  parent: 1:b8bb4a988f25 tip
+   commit #1
+  branch: default
+  commit: (clean)
+  update: (current)
+
+Prepare a basic merge
+
+  $ hg up 0
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ echo This is file c1 > c
   $ hg add c
   $ hg commit -m "commit #2"