patch: add hint about mangled whitespace on bad patch
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 19 Nov 2021 09:17:30 -0800
changeset 48364 220506bb213e
parent 48363 6a454e7053a1
child 48365 67064c238ae7
patch: add hint about mangled whitespace on bad patch One of the most common reasons that a patch doesn't apply is because its whitespace has been mangled (e.g. by their mail client or though copy&paste). Let's provide a hint about that. Differential Revision: https://phab.mercurial-scm.org/D11825
mercurial/cmdutil.py
tests/test-import-git.t
tests/test-import.t
--- a/mercurial/cmdutil.py	Fri Nov 19 12:57:53 2021 -0800
+++ b/mercurial/cmdutil.py	Fri Nov 19 09:17:30 2021 -0800
@@ -2025,7 +2025,12 @@
                 similarity=sim / 100.0,
             )
         except error.PatchParseError as e:
-            raise error.InputError(pycompat.bytestr(e))
+            raise error.InputError(
+                pycompat.bytestr(e),
+                hint=_(
+                    b'check that whitespace in the patch has not been mangled'
+                ),
+            )
         except error.PatchApplicationError as e:
             if not partial:
                 raise error.StateError(pycompat.bytestr(e))
@@ -2086,7 +2091,12 @@
                     eolmode=None,
                 )
             except error.PatchParseError as e:
-                raise error.InputError(stringutil.forcebytestr(e))
+                raise error.InputError(
+                    stringutil.forcebytestr(e),
+                    hint=_(
+                        b'check that whitespace in the patch has not been mangled'
+                    ),
+                )
             except error.PatchApplicationError as e:
                 raise error.StateError(stringutil.forcebytestr(e))
             if opts.get(b'exact'):
--- a/tests/test-import-git.t	Fri Nov 19 12:57:53 2021 -0800
+++ b/tests/test-import-git.t	Fri Nov 19 09:17:30 2021 -0800
@@ -519,6 +519,7 @@
   > EOF
   applying patch from stdin
   abort: could not decode "binary2" binary patch: bad base85 character at position 6
+  (check that whitespace in the patch has not been mangled)
   [10]
 
   $ hg revert -aq
@@ -534,6 +535,7 @@
   > EOF
   applying patch from stdin
   abort: "binary2" length is 5 bytes, should be 6
+  (check that whitespace in the patch has not been mangled)
   [10]
 
   $ hg revert -aq
@@ -548,6 +550,7 @@
   > EOF
   applying patch from stdin
   abort: could not extract "binary2" binary data
+  (check that whitespace in the patch has not been mangled)
   [10]
 
 Simulate a copy/paste turning LF into CRLF (issue2870)
--- a/tests/test-import.t	Fri Nov 19 12:57:53 2021 -0800
+++ b/tests/test-import.t	Fri Nov 19 09:17:30 2021 -0800
@@ -234,6 +234,7 @@
   $ hg --cwd b import -mpatch ../broken.patch
   applying ../broken.patch
   abort: bad hunk #1
+  (check that whitespace in the patch has not been mangled)
   [10]
   $ rm -r b
 
@@ -2076,6 +2077,7 @@
   > EOF
   applying patch from stdin
   abort: bad hunk #1: incomplete hunk
+  (check that whitespace in the patch has not been mangled)
   [10]
 
   $ hg import - <<'EOF'
@@ -2087,4 +2089,5 @@
   > EOF
   applying patch from stdin
   abort: bad hunk #1: incomplete hunk
+  (check that whitespace in the patch has not been mangled)
   [10]