Patchwork [V2] import: report directory-relative paths in error messages (issue5224)

login
register
mail settings
Submitter liscju
Date Sept. 5, 2016, 8:24 p.m.
Message ID <63cb64dd80730bc01503.1473107050@liscju-VirtualBox>
Download mbox | patch
Permalink /patch/16561/
State Superseded
Headers show

Comments

liscju - Sept. 5, 2016, 8:24 p.m.
# HG changeset patch
# User liscju <piotr.listkiewicz@gmail.com>
# Date 1472208500 -7200
#      Fri Aug 26 12:48:20 2016 +0200
# Node ID 63cb64dd80730bc01503b2f28bd159535301f649
# Parent  b1809f5d7630a3fff0fa715bbd30dba0f07672a8
import: report directory-relative paths in error messages (issue5224)

Import uses paths relative to the root of the repository, so when
user imports patch with paths relative to the current working directory
import aborts with 'unable to find file for patching'.

This patch improves this situation by warning the user that paths are
relative to the root of repository when patching fails.
liscju - Sept. 5, 2016, 8:26 p.m.
I have no idea how but i sent this patch two times, so ignore second message

2016-09-05 22:24 GMT+02:00 liscju <piotr.listkiewicz@gmail.com>:

> # HG changeset patch
> # User liscju <piotr.listkiewicz@gmail.com>
> # Date 1472208500 -7200
> #      Fri Aug 26 12:48:20 2016 +0200
> # Node ID 63cb64dd80730bc01503b2f28bd159535301f649
> # Parent  b1809f5d7630a3fff0fa715bbd30dba0f07672a8
> import: report directory-relative paths in error messages (issue5224)
>
> Import uses paths relative to the root of the repository, so when
> user imports patch with paths relative to the current working directory
> import aborts with 'unable to find file for patching'.
>
> This patch improves this situation by warning the user that paths are
> relative to the root of repository when patching fails.
>
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -669,6 +669,8 @@ class patchfile(object):
>                  self.mode = (False, False)
>          if self.missing:
>              self.ui.warn(_("unable to find '%s' for patching\n") %
> self.fname)
> +            self.ui.warn(_("(use '--prefix' to apply patch relative to
> the "
> +                           "current directory)\n"))
>
>          self.hash = {}
>          self.dirty = 0
> diff --git a/tests/test-import-bypass.t b/tests/test-import-bypass.t
> --- a/tests/test-import-bypass.t
> +++ b/tests/test-import-bypass.t
> @@ -41,6 +41,7 @@ Test failure without --exact
>    $ hg import --bypass ../test.diff
>    applying ../test.diff
>    unable to find 'a' for patching
> +  (use '--prefix' to apply patch relative to the current directory)
>    abort: patch failed to apply
>    [255]
>    $ hg st
> diff --git a/tests/test-import.t b/tests/test-import.t
> --- a/tests/test-import.t
> +++ b/tests/test-import.t
> @@ -1623,6 +1623,7 @@ Importing with unknown file:
>    $ hg export --rev 'desc("extended jungle")' | hg import --partial -
>    applying patch from stdin
>    unable to find 'jungle' for patching
> +  (use '--prefix' to apply patch relative to the current directory)
>    1 out of 1 hunks FAILED -- saving rejects to file jungle.rej
>    patch applied partially
>    (fix the .rej files and run `hg commit --amend`)
> @@ -1764,3 +1765,31 @@ Importing some extra header
>    $ hg log --debug -r . | grep extra
>    extra:       branch=default
>    extra:       foo=bar
> +
> +Warn the user that paths are relative to the root of
> +repository when file not found for patching
> +
> +  $ mkdir filedir
> +  $ echo "file1" >> filedir/file1
> +  $ hg add filedir/file1
> +  $ hg commit -m "file1"
> +  $ cd filedir
> +  $ hg import -p 2 - <<EOF
> +  > # HG changeset patch
> +  > # User test
> +  > # Date 0 0
> +  > file2
> +  >
> +  > diff --git a/filedir/file1 b/filedir/file1
> +  > --- a/filedir/file1
> +  > +++ b/filedir/file1
> +  > @@ -1,1 +1,2 @@
> +  >  file1
> +  > +file2
> +  > EOF
> +  applying patch from stdin
> +  unable to find 'file1' for patching
> +  (use '--prefix' to apply patch relative to the current directory)
> +  1 out of 1 hunks FAILED -- saving rejects to file file1.rej
> +  abort: patch failed to apply
> +  [255]
> diff --git a/tests/test-mq-missingfiles.t b/tests/test-mq-missingfiles.t
> --- a/tests/test-mq-missingfiles.t
> +++ b/tests/test-mq-missingfiles.t
> @@ -42,6 +42,7 @@ Push patch with missing target:
>    $ hg qpush
>    applying changeb
>    unable to find 'b' for patching
> +  (use '--prefix' to apply patch relative to the current directory)
>    2 out of 2 hunks FAILED -- saving rejects to file b.rej
>    patch failed, unable to continue (try -v)
>    patch failed, rejects left in working directory
> @@ -147,6 +148,7 @@ Push git patch with missing target:
>    $ hg qpush
>    applying changeb
>    unable to find 'b' for patching
> +  (use '--prefix' to apply patch relative to the current directory)
>    1 out of 1 hunks FAILED -- saving rejects to file b.rej
>    patch failed, unable to continue (try -v)
>    patch failed, rejects left in working directory
>

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -669,6 +669,8 @@  class patchfile(object):
                 self.mode = (False, False)
         if self.missing:
             self.ui.warn(_("unable to find '%s' for patching\n") % self.fname)
+            self.ui.warn(_("(use '--prefix' to apply patch relative to the "
+                           "current directory)\n"))
 
         self.hash = {}
         self.dirty = 0
diff --git a/tests/test-import-bypass.t b/tests/test-import-bypass.t
--- a/tests/test-import-bypass.t
+++ b/tests/test-import-bypass.t
@@ -41,6 +41,7 @@  Test failure without --exact
   $ hg import --bypass ../test.diff
   applying ../test.diff
   unable to find 'a' for patching
+  (use '--prefix' to apply patch relative to the current directory)
   abort: patch failed to apply
   [255]
   $ hg st
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -1623,6 +1623,7 @@  Importing with unknown file:
   $ hg export --rev 'desc("extended jungle")' | hg import --partial -
   applying patch from stdin
   unable to find 'jungle' for patching
+  (use '--prefix' to apply patch relative to the current directory)
   1 out of 1 hunks FAILED -- saving rejects to file jungle.rej
   patch applied partially
   (fix the .rej files and run `hg commit --amend`)
@@ -1764,3 +1765,31 @@  Importing some extra header
   $ hg log --debug -r . | grep extra
   extra:       branch=default
   extra:       foo=bar
+
+Warn the user that paths are relative to the root of
+repository when file not found for patching
+
+  $ mkdir filedir
+  $ echo "file1" >> filedir/file1
+  $ hg add filedir/file1
+  $ hg commit -m "file1"
+  $ cd filedir
+  $ hg import -p 2 - <<EOF
+  > # HG changeset patch
+  > # User test
+  > # Date 0 0
+  > file2
+  > 
+  > diff --git a/filedir/file1 b/filedir/file1
+  > --- a/filedir/file1
+  > +++ b/filedir/file1
+  > @@ -1,1 +1,2 @@
+  >  file1
+  > +file2
+  > EOF
+  applying patch from stdin
+  unable to find 'file1' for patching
+  (use '--prefix' to apply patch relative to the current directory)
+  1 out of 1 hunks FAILED -- saving rejects to file file1.rej
+  abort: patch failed to apply
+  [255]
diff --git a/tests/test-mq-missingfiles.t b/tests/test-mq-missingfiles.t
--- a/tests/test-mq-missingfiles.t
+++ b/tests/test-mq-missingfiles.t
@@ -42,6 +42,7 @@  Push patch with missing target:
   $ hg qpush
   applying changeb
   unable to find 'b' for patching
+  (use '--prefix' to apply patch relative to the current directory)
   2 out of 2 hunks FAILED -- saving rejects to file b.rej
   patch failed, unable to continue (try -v)
   patch failed, rejects left in working directory
@@ -147,6 +148,7 @@  Push git patch with missing target:
   $ hg qpush
   applying changeb
   unable to find 'b' for patching
+  (use '--prefix' to apply patch relative to the current directory)
   1 out of 1 hunks FAILED -- saving rejects to file b.rej
   patch failed, unable to continue (try -v)
   patch failed, rejects left in working directory