[PATCH 2 of 8 V3] addremove: warn when addremove fails to operate on a named path

Matt Harbison mharbison72 at gmail.com
Thu Dec 11 21:35:14 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 c9c90f5a0d75593301d725a0784fca57f429e606
# Parent  b86d74857424e1869c51acd937dc38ba6a0009c8
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 subdir


More information about the Mercurial-devel mailing list