changeset 29900:50f2966f86ca

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.
author liscju <piotr.listkiewicz@gmail.com>
date Fri, 26 Aug 2016 12:48:20 +0200
parents a9b92164a1f4
children 4d1e6f91f1c7
files mercurial/patch.py tests/test-import-bypass.t tests/test-import.t tests/test-mq-missingfiles.t
diffstat 4 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Mon Sep 05 08:29:36 2016 +0000
+++ b/mercurial/patch.py	Fri Aug 26 12:48:20 2016 +0200
@@ -669,6 +669,8 @@
                 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
--- a/tests/test-import-bypass.t	Mon Sep 05 08:29:36 2016 +0000
+++ b/tests/test-import-bypass.t	Fri Aug 26 12:48:20 2016 +0200
@@ -41,6 +41,7 @@
   $ 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
--- a/tests/test-import.t	Mon Sep 05 08:29:36 2016 +0000
+++ b/tests/test-import.t	Fri Aug 26 12:48:20 2016 +0200
@@ -1623,6 +1623,7 @@
   $ 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 @@
   $ 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]
--- a/tests/test-mq-missingfiles.t	Mon Sep 05 08:29:36 2016 +0000
+++ b/tests/test-mq-missingfiles.t	Fri Aug 26 12:48:20 2016 +0200
@@ -42,6 +42,7 @@
   $ 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 @@
   $ 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