[PATCH] update: --check should fail if untracked files would be lost (issue2450)
Mark Kendrat
swdev10 at live.com
Wed Jun 8 20:59:37 CDT 2011
# HG changeset patch
# User Mark Kendrat <swdev10 at live.com>
# Date 1307584708 14400
# Node ID 4e0c59bfcdd8d234ba2e7ba7e8c83f5ab2e8998c
# Parent 48ec0763afbbbbb4802fb836ae75256e82e5609c
update: --check should fail if untracked files would be lost (issue2450)
diff -r 48ec0763afbb -r 4e0c59bfcdd8 mercurial/commands.py
--- a/mercurial/commands.py Tue Jun 07 17:02:54 2011 -0500
+++ b/mercurial/commands.py Wed Jun 08 21:58:28 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 4e0c59bfcdd8 mercurial/hg.py
--- a/mercurial/hg.py Tue Jun 07 17:02:54 2011 -0500
+++ b/mercurial/hg.py Wed Jun 08 21:58:28 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 4e0c59bfcdd8 mercurial/merge.py
--- a/mercurial/merge.py Tue Jun 07 17:02:54 2011 -0500
+++ b/mercurial/merge.py Wed Jun 08 21:58:28 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 4e0c59bfcdd8 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 21:58:28 2011 -0400
@@ -54,3 +54,43 @@
$ hg upd -d foo 0
abort: you can't specify a revision and a date
[255]
+
+update --check should protect untracked files (issue2450)
+
+initial repo1
+ $ cd $TESTTMP
+ $ 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 "newfile"
+ $ 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