changeset 6031:7383384793fb

revert: don't assume ignored files will be returned in the unknown list That's just an artifact of the current implementation, and I'll change that soon. Bonus points: - we don't care about the unknown list at all - we don't print an extra message if we try to revert a removed file that is not present in the target revision
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Fri, 08 Feb 2008 18:07:55 -0200
parents d0dbae32517c
children b41f0d6a74fc
files mercurial/commands.py tests/test-revert tests/test-revert.out
diffstat 3 files changed, 72 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Feb 08 18:07:55 2008 -0200
+++ b/mercurial/commands.py	Fri Feb 08 18:07:55 2008 -0200
@@ -215,6 +215,7 @@
     revert_opts['date'] = None
     revert_opts['all'] = True
     revert_opts['rev'] = hex(parent)
+    revert_opts['no_backup'] = None
     revert(ui, repo, **revert_opts)
     commit_opts = opts.copy()
     commit_opts['addremove'] = False
@@ -2327,7 +2328,6 @@
     # but not other.
 
     names = {}
-    target_only = {}
 
     wlock = repo.wlock()
     try:
@@ -2335,8 +2335,6 @@
         for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
                                                  badmatch=mf.has_key):
             names[abs] = (rel, exact)
-            if src == 'b':
-                target_only[abs] = True
 
         # walk target manifest.
 
@@ -2354,10 +2352,9 @@
             if abs in names or src == 'b':
                 continue
             names[abs] = (rel, exact)
-            target_only[abs] = True
-
-        changes = repo.status(match=names.has_key)[:5]
-        modified, added, removed, deleted, unknown = map(dict.fromkeys, changes)
+
+        changes = repo.status(match=names.has_key)[:4]
+        modified, added, removed, deleted = map(dict.fromkeys, changes)
 
         # if f is a rename, also revert the source
         cwd = repo.getcwd()
@@ -2385,8 +2382,6 @@
             (added, revert, forget, True, False),
             (removed, undelete, None, False, False),
             (deleted, revert, remove, False, False),
-            (unknown, add, None, True, False),
-            (target_only, add, None, False, False),
             )
 
         entries = names.items()
@@ -2413,10 +2408,14 @@
                     handle(hitlist, backuphit)
                 elif misslist is not None:
                     handle(misslist, backupmiss)
-                else:
-                    if exact: ui.warn(_('file not managed: %s\n') % rel)
                 break
             else:
+                if abs not in repo.dirstate:
+                    if mfentry:
+                        handle(add, True)
+                    elif exact:
+                        ui.warn(_('file not managed: %s\n') % rel)
+                    continue
                 # file has not changed in dirstate
                 if node == parent:
                     if exact: ui.warn(_('no changes needed to %s\n') % rel)
--- a/tests/test-revert	Fri Feb 08 18:07:55 2008 -0200
+++ b/tests/test-revert	Fri Feb 08 18:07:55 2008 -0200
@@ -1,6 +1,7 @@
 #!/bin/sh
 
-hg init
+hg init repo
+cd repo
 echo 123 > a
 echo 123 > c
 echo 123 > e
@@ -40,19 +41,26 @@
 rm q
 echo %% should say file not found
 hg revert notfound
+touch d
+hg add d
 hg rm a
 hg commit -m "second" -d "1000000 0"
 echo z > z
 hg add z
 hg st
-echo %% should add a, forget z
+echo %% should add a, remove d, forget z
 hg revert --all -r0
-echo %% should forget a
+echo %% should forget a, undelete d
 hg revert --all -rtip
 rm a *.orig
 echo %% should silently add a
 hg revert -r0 a
 hg st a
+hg rm d
+hg st d
+echo %% should silently keep d removed
+hg revert -r0 d
+hg st d
 
 hg update -C
 chmod +x c
@@ -68,6 +76,8 @@
 echo %% should print executable
 test -x c && echo executable
 
+cd ..
+
 echo %% issue 241
 hg init a
 cd a
@@ -100,3 +110,33 @@
 hg revert newa
 hg st a newa
 
+cd ..
+
+hg init ignored
+cd ignored
+echo '^ignored$' > .hgignore
+echo '^ignoreddir$' >> .hgignore
+echo '^removed$' >> .hgignore
+
+mkdir ignoreddir
+touch ignoreddir/file
+touch ignoreddir/removed
+touch ignored
+touch removed
+echo '%% 4 ignored files (we will add/commit everything)'
+hg st -A -X .hgignore
+hg ci -qAm 'add files' ignored ignoreddir/file ignoreddir/removed removed
+
+echo >> ignored
+echo >> ignoreddir/file
+hg rm removed ignoreddir/removed
+echo '%% should revert ignored* and undelete *removed'
+hg revert -a --no-backup
+hg st -mardi
+
+hg up -qC
+echo >> ignored
+hg rm removed
+echo %% should silently revert the named files
+hg revert --no-backup ignored removed
+hg st -mardi
--- a/tests/test-revert.out	Fri Feb 08 18:07:55 2008 -0200
+++ b/tests/test-revert.out	Fri Feb 08 18:07:55 2008 -0200
@@ -37,14 +37,19 @@
 A z
 ? b
 ? e.orig
-%% should add a, forget z
+%% should add a, remove d, forget z
 adding a
+removing d
 forgetting z
-%% should forget a
+%% should forget a, undelete d
 forgetting a
+undeleting d
 %% should silently add a
 A a
-0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+R d
+%% should silently keep d removed
+R d
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
 reverting c
 %% should print non-executable
 non-executable
@@ -65,3 +70,14 @@
 reverting b/b
 % reverting a rename target should revert the source
 ? newa
+%% 4 ignored files (we will add/commit everything)
+? ignoreddir/file
+? ignoreddir/removed
+I ignored
+I removed
+%% should revert ignored* and undelete *removed
+reverting ignored
+reverting ignoreddir/file
+undeleting ignoreddir/removed
+undeleting removed
+%% should silently revert the named files