{"thread":{"id":"36324","subject":"git am oddity","startedAt":"2014-03-31T21:58:22Z","lastAt":"2014-03-31T22:38:16Z","messageCount":3,"participants":["Sverre Rabbelier","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"238164","messageId":"CAGdFq_gZoiE_ah0VT5ZfQwg-zHNj6Q-RSB80f=BTf=U6+9L5UA@mail.gmail.com","threadId":"36324","inReplyTo":null,"subject":"git am oddity","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2014-03-31T21:58:22Z","receivedAt":"2014-03-31T21:58:22Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Hi,\n\nI noticed something very odd with git am, and have been able to narrow\nit down to a minimal example.\n\n git init tmp\n cd tmp\n mkdir -p foo/bar/baz\n cd foo/bar/baz\n echo file > file\n git add file\n git commit -m \"1\"\n echo other > other\n echo more >> file\n git add file other\n git commit -m \"my test\"\n git format-patch HEAD~..\n git reset --hard HEAD~\n # apply the patch in the current directory, chop off the leading directories\n git am -3 -p 3 0001-my-test.patch\n cd ../../..\n git ls-files\n\nExpected output:\nfoo/bar/baz/file\nfoo/bar/baz/other\n\nActual output:\nbaz/other # the file addition was applied to the root of the\nrepository, instead of the current directory\nfoo/bar/baz/file # the file modification was correctly applied, yay\n\nIs this expected behavior?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"238173","messageId":"xmqqbnwm2ex1.fsf@gitster.dls.corp.google.com","threadId":"36324","inReplyTo":"CAGdFq_gZoiE_ah0VT5ZfQwg-zHNj6Q-RSB80f=BTf=U6+9L5UA@mail.gmail.com","subject":"Re: git am oddity","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-31T22:15:22Z","receivedAt":"2014-03-31T22:15:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sverre Rabbelier <srabbelier@gmail.com> writes:\n\n> Hi,\n>\n> I noticed something very odd with git am, and have been able to narrow\n> it down to a minimal example.\n>\n>  git init tmp\n>  cd tmp\n>  mkdir -p foo/bar/baz\n>  cd foo/bar/baz\n>  echo file > file\n>  git add file\n>  git commit -m \"1\"\n>  echo other > other\n>  echo more >> file\n>  git add file other\n>  git commit -m \"my test\"\n>  git format-patch HEAD~..\n>  git reset --hard HEAD~\n>  # apply the patch in the current directory, chop off the leading directories\n>  git am -3 -p 3 0001-my-test.patch\n>  cd ../../..\n>  git ls-files\n>\n> Expected output:\n> foo/bar/baz/file\n> foo/bar/baz/other\n>\n> Actual output:\n> baz/other # the file addition was applied to the root of the\n> repository, instead of the current directory\n> foo/bar/baz/file # the file modification was correctly applied, yay\n>\n> Is this expected behavior?\n\nAs you are doing -3 (not the -p3), it would have:\n\n * noticed that the patch is trying to update \"baz/file\";\n\n * noticed that there is no \"baz/file\" but it could salvage the\n   patch by doing a three-way merge, in case that the patch was\n   prepared against a tree that moved path \"foo/bar/baz\" to \"baz\";\n   and\n\n * such a three-way merge succeeds cleanly for a path whose movement\n   was detected correctly.\n\nSo it does not look odd at all to me (the use of \"-p 3\" does look\nodd, but I know this is an effort to come up with a minimum example,\nso it is understandable that it may look contribed ;-).\n"},{"id":"238180","messageId":"CAGdFq_hM11bqhPsJqmx6x9wA-KcHvA=RJU+wQWWEuEQR1EU8GQ@mail.gmail.com","threadId":"36324","inReplyTo":"xmqqbnwm2ex1.fsf@gitster.dls.corp.google.com","subject":"Re: git am oddity","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2014-03-31T22:38:16Z","receivedAt":"2014-03-31T22:38:16Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"On Mon, Mar 31, 2014 at 3:15 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> As you are doing -3 (not the -p3), it would have:\n>\n>  * noticed that the patch is trying to update \"baz/file\";\n>\n>  * noticed that there is no \"baz/file\" but it could salvage the\n>    patch by doing a three-way merge, in case that the patch was\n>    prepared against a tree that moved path \"foo/bar/baz\" to \"baz\";\n>    and\n>\n>  * such a three-way merge succeeds cleanly for a path whose movement\n>    was detected correctly.\n>\n> So it does not look odd at all to me (the use of \"-p 3\" does look\n> odd, but I know this is an effort to come up with a minimum example,\n> so it is understandable that it may look contribed ;-).\n\nAh, we were thinking that 'git am' (when run from a subdirectory),\nwould apply the patches \"from the current directory\". So the right\nsolution was to instead do:\n\n$  git am --directory=foo/bar/baz -p 3 0001-my-test.patch\n\nThank you,\n\n-- \nCheers,\n\nSverre Rabbelier\n"}]}