git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git-apply fails on creating a new file, with both -p and --directory specified
@ 2009-11-23 19:45 Steven J. Murdoch
  2009-11-25 10:56 ` Junio C Hamano
  0 siblings, 1 reply; 16+ messages in thread
From: Steven J. Murdoch @ 2009-11-23 19:45 UTC (permalink / raw)
  To: git

While trying to apply a patch from one repository (created by
git-format-patch), to another (using git-am), git fails with:

"fatal: git apply: bad git-diff - inconsistent new filename on line X"

This appears to be because I was both using -p to strip some path
components, and --directory to add different ones in. Only creating
new files was affected.

This was the case in git 1.6.5.2, and also the development version
1.6.6.rc0.15.g4fa80. I have tested this on MacOS X Snow Leopard.

This appears related to the bug discussed in:
  http://marc.info/?l=git&m=122237537312597&w=2
in which the following fix was posted:
  http://git.kernel.org/?p=git/git.git;a=commitdiff;h=969c877506cf8cc760c7b251fef6c5b6850bfc19

I have included a patch below to the test cases, which currently fails
but, if I understand correctly, should succeed.

Steven Murdoch.

-- >8 --
Test git-apply creating a new file, combining --directory and -p flags

Signed-off-by: Steven Murdoch <Steven.Murdoch@cl.cam.ac.uk>
---
 t/t4128-apply-root.sh |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/t/t4128-apply-root.sh b/t/t4128-apply-root.sh
index 8f6aea4..6cc741a 100755
--- a/t/t4128-apply-root.sh
+++ b/t/t4128-apply-root.sh
@@ -58,6 +58,23 @@ test_expect_success 'apply --directory (new file)' '
 '
 
 cat > patch << EOF
+diff --git a/c/newfile2 b/c/newfile2
+new file mode 100644
+index 0000000..d95f3ad
+--- /dev/null
++++ b/c/newfile2
+@@ -0,0 +1 @@
++content
+EOF
+
+test_expect_success 'apply --directory -p (new file)' '
+	git reset --hard initial &&
+	git apply -p2 --directory=some/sub/dir/ --index patch &&
+	test content = $(git show :some/sub/dir/newfile2) &&
+	test content = $(cat some/sub/dir/newfile2)
+'
+
+cat > patch << EOF
 diff --git a/delfile b/delfile
 deleted file mode 100644
 index d95f3ad..0000000
-- 
1.6.5.2

-- 
http://www.cl.cam.ac.uk/users/sjm217/

^ permalink raw reply related	[flat|nested] 16+ messages in thread
* git-apply fails on creating a new file, with both -p and --directory specified
@ 2010-04-28 12:29 Matthias Lehmann
  2010-04-29  8:20 ` Matthias Lehmann
  0 siblings, 1 reply; 16+ messages in thread
From: Matthias Lehmann @ 2010-04-28 12:29 UTC (permalink / raw)
  To: git

Hi all,

the subject of this mail may read familiar to some - there was a discussion in 
November last year (see 
http://kerneltrap.org/mailarchive/git/2009/11/23/16899/) concerning this 
problem.

Today I had this same issue with git 1.7.0.4. Reading the above mentioned 
discussion and seaching the net did not help me in finding a solution to the 
problem. 

I have to apply patches from one repository to another repository, which have 
a different layout (I am working on splitting one big repository into several 
smaller ones, while development still continues on the big repository).

So I did

big-repo$ git format-patche -o /tmp/foo 
small-repo$ git apply -p2 --directory=some/path --check /tmp/foo/*

and get

fatal: git diff header lacks filename information when removing 2 leading 
pathname components (line 37)

the patch looks like this:

35| diff --git a/xyz/bar.jpg b/xyz/bar.jpg
36| new file mode 100644
37| index 
0000000000000000000000000000000000000000..3dcce2e1f68586ed2089d86b1bf4e7e41c818d97
38| GIT binary patch
39| literal 8791



Since this problem was discussed before - is there a solution?
This is something like a showstopper for me right now, so I am very thankful 
for any hints.

Best regards,

Mat

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-04-30 18:32 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-23 19:45 git-apply fails on creating a new file, with both -p and --directory specified Steven J. Murdoch
2009-11-25 10:56 ` Junio C Hamano
2009-12-07 21:35   ` James Vega
2009-12-08  2:59     ` Junio C Hamano
2009-12-08  3:20       ` Junio C Hamano
2009-12-08  5:47         ` Jeff King
2009-12-08  6:01           ` Jeff King
2009-12-08  6:49             ` James Vega
2009-12-08  7:28             ` Junio C Hamano
2009-12-08  7:49               ` Jeff King
2009-12-08  7:53                 ` Junio C Hamano
2009-12-08  7:11           ` Junio C Hamano
2009-12-08  7:38             ` Jeff King
2009-12-08  3:39       ` James Vega
  -- strict thread matches above, loose matches on Subject: below --
2010-04-28 12:29 Matthias Lehmann
2010-04-29  8:20 ` Matthias Lehmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).