[PATCH] update: --check should fail if untracked files would be lost

Mark Kendrat swdev10 at live.com
Wed Jun 8 19:45:37 CDT 2011


# HG changeset patch
# User Mark Kendrat <swdev10 at live.com>
# Date 1307580278 14400
# Node ID 5dc56c7c6c6cce1109e6fe5202050474a764bdcc
# Parent  48ec0763afbbbbb4802fb836ae75256e82e5609c
update: --check should fail if untracked files would be lost

diff -r 48ec0763afbb -r 5dc56c7c6c6c mercurial/commands.py
--- a/mercurial/commands.py	Tue Jun 07 17:02:54 2011 -0500
+++ b/mercurial/commands.py	Wed Jun 08 20:44:38 2011 -0400
@@ -5027,7 +5027,7 @@
         rev = cmdutil.finddate(ui, repo, date)
 
     if clean or check:
-        ret = hg.clean(repo, rev)
+        ret = hg.clean(repo, rev, check=check)
     else:
         ret = hg.update(repo, rev)
 
diff -r 48ec0763afbb -r 5dc56c7c6c6c mercurial/hg.py
--- a/mercurial/hg.py	Tue Jun 07 17:02:54 2011 -0500
+++ b/mercurial/hg.py	Wed Jun 08 20:44:38 2011 -0400
@@ -395,9 +395,9 @@
 # naming conflict in clone()
 _update = update
 
-def clean(repo, node, show_stats=True):
+def clean(repo, node, show_stats=True, check=False):
     """forcibly switch the working directory to node, clobbering changes"""
-    stats = mergemod.update(repo, node, False, True, None)
+    stats = mergemod.update(repo, node, False, True, None, check=check)
     if show_stats:
         _showstats(repo, stats)
     return stats[3] > 0
diff -r 48ec0763afbb -r 5dc56c7c6c6c mercurial/merge.py
--- a/mercurial/merge.py	Tue Jun 07 17:02:54 2011 -0500
+++ b/mercurial/merge.py	Wed Jun 08 20:44:38 2011 -0400
@@ -443,7 +443,7 @@
                 if f:
                     repo.dirstate.drop(f)
 
-def update(repo, node, branchmerge, force, partial, ancestor=None):
+def update(repo, node, branchmerge, force, partial, ancestor=None, check=False):
     """
     Perform a merge between the working directory and the given node
 
@@ -538,7 +538,7 @@
         ### calculate phase
         action = []
         wc.status(unknown=True) # prime cache
-        if not force:
+        if not force or check:
             _checkunknown(wc, p2)
         if not util.checkcase(repo.path):
             _checkcollision(p2)
diff -r 48ec0763afbb -r 5dc56c7c6c6c tests/test-simple-update.t
--- a/tests/test-simple-update.t	Tue Jun 07 17:02:54 2011 -0500
+++ b/tests/test-simple-update.t	Wed Jun 08 20:44:38 2011 -0400
@@ -54,3 +54,42 @@
   $ hg upd -d foo 0
   abort: you can't specify a revision and a date
   [255]
+
+test for protection of untracked files using repo1 and repo2
+
+.. initial repo1
+  $ hg init repo1
+
+.. repo2 is a clone that adds newfile and pushes back to repo1
+  $ hg clone repo1 repo2
+  updating to branch default
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd $TESTTMP/repo2
+  cd: 42: can't cd to $TESTTMP/repo2
+  [2]
+  $ echo "finished work" > newfile
+  $ hg add newfile
+  $ hg commit -m "work 2"
+  $ hg push
+  pushing to default-push
+  abort: repository default-push not found!
+  [255]
+
+.. repo1 begins work in progress in newfile
+  $ cd $TESTTMP/repo1
+  cd: 52: can't cd to $TESTTMP/repo1
+  [2]
+  $ echo "work in progress" > newfile
+
+.. repo1 does an update and work in progress is protected
+  $ hg update
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+.. repo1 does an update --check and work in progress is protected
+  $ hg update --check
+  abort: uncommitted local changes
+  [255]
+
+.. repo1 does an update --clean and work in progress is removed
+  $ hg update --clean
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved


More information about the Mercurial-devel mailing list