[PATCH 4 of 9 V2] addremove: warn when addremove fails to operate on a named path

Matt Harbison matt_harbison at yahoo.com
Sat Nov 29 23:52:32 CST 2014


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1417030056 18000
#      Wed Nov 26 14:27:36 2014 -0500
# Node ID 9559f266ac03e53d20b2a2035bf5e417f37b79d3
# Parent  37af995c0feea059692cc4ed423febb7c722a808
addremove: warn when addremove fails to operate on a named path

It looks like a bad path is the only mode of failure for addremove.  This
warning is probably useful for the standalone command, but more important for
'commit -A'.  That command doesn't currently abort if the addremove fails, but
it will be made to do so prior to adding subrepo support, since not all subrepos
will support addremove.  We could just abort here, but it looks like addremove
has always silently ignored bad paths, except for the exit code.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -721,9 +721,15 @@
         similarity = float(opts.get('similarity') or 0)
 
     rejected = []
-    m.bad = lambda x, y: rejected.append(x)
+    origbad = m.bad
+    def badfn(f, msg):
+        if f in m.files():
+            origbad(f, msg)
+        rejected.append(f)
 
+    m.bad = badfn
     added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m)
+    m.bad = origbad
 
     unknownset = set(unknown + forgotten)
     toprint = unknownset.copy()
diff --git a/tests/test-addremove.t b/tests/test-addremove.t
--- a/tests/test-addremove.t
+++ b/tests/test-addremove.t
@@ -22,6 +22,16 @@
   $ hg forget foo
   $ hg -v addremove
   adding foo
+  $ hg forget foo
+#if windows
+  $ hg -v addremove nonexistant
+  nonexistant: The system cannot find the file specified
+  [1]
+#else
+  $ hg -v addremove nonexistant
+  nonexistant: No such file or directory
+  [1]
+#endif
   $ cd ..
 
   $ hg init sim


More information about the Mercurial-devel mailing list