[PATCH] update --check will protect untracked files
Mark Kendrat
swdev10 at live.com
Wed Jun 8 17:50:03 CDT 2011
# HG changeset patch
# User user at test-desktop
# Date 1307549746 14400
# Node ID 77aec111c4657cea543635067d18f0cd2e4cf112
# Parent 66b2e70a8c1e96e09134d67f977e07b181590c56
update --check will protect untracked files
- pass "check" argument from command line
diff -r 66b2e70a8c1e -r 77aec111c465 mercurial/commands.py
--- a/mercurial/commands.py Wed Jun 08 10:54:12 2011 -0400
+++ b/mercurial/commands.py Wed Jun 08 12:15:46 2011 -0400
@@ -5045,7 +5045,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 66b2e70a8c1e -r 77aec111c465 mercurial/hg.py
--- a/mercurial/hg.py Wed Jun 08 10:54:12 2011 -0400
+++ b/mercurial/hg.py Wed Jun 08 12:15:46 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 66b2e70a8c1e -r 77aec111c465 mercurial/merge.py
--- a/mercurial/merge.py Wed Jun 08 10:54:12 2011 -0400
+++ b/mercurial/merge.py Wed Jun 08 12:15:46 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 66b2e70a8c1e -r 77aec111c465 tests/test-update-protect-untracked.t
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-update-protect-untracked.t Wed Jun 08 12:15:46 2011 -0400
@@ -0,0 +1,38 @@
+test "update" and "update --check" for protection of untracked files
+
+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
+ $ echo "finished work" > newfile
+ $ hg add newfile
+ $ hg commit -m "work 2"
+ $ hg push
+ pushing to $TESTTMP/repo1
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 1 changes to 1 files
+
+repo1 begins work in progress in newfile
+ $ cd $TESTTMP/repo1
+ $ echo "work in progress" > newfile
+
+repo1 does an update and work in progress is protected
+ $ hg update
+ abort: untracked file in working directory differs from file in requested revision: 'newfile'
+ [255]
+
+repo1 does an update --check and work in progress is protected
+ $ hg update --check
+ abort: untracked file in working directory differs from file in requested revision: 'newfile'
+ [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