git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git am oddity
@ 2014-03-31 21:58 Sverre Rabbelier
  2014-03-31 22:15 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Sverre Rabbelier @ 2014-03-31 21:58 UTC (permalink / raw)
  To: Git List; +Cc: Mario Ferraro

Hi,

I noticed something very odd with git am, and have been able to narrow
it down to a minimal example.

 git init tmp
 cd tmp
 mkdir -p foo/bar/baz
 cd foo/bar/baz
 echo file > file
 git add file
 git commit -m "1"
 echo other > other
 echo more >> file
 git add file other
 git commit -m "my test"
 git format-patch HEAD~..
 git reset --hard HEAD~
 # apply the patch in the current directory, chop off the leading directories
 git am -3 -p 3 0001-my-test.patch
 cd ../../..
 git ls-files

Expected output:
foo/bar/baz/file
foo/bar/baz/other

Actual output:
baz/other # the file addition was applied to the root of the
repository, instead of the current directory
foo/bar/baz/file # the file modification was correctly applied, yay

Is this expected behavior?

-- 
Cheers,

Sverre Rabbelier

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

* Re: git am oddity
  2014-03-31 21:58 git am oddity Sverre Rabbelier
@ 2014-03-31 22:15 ` Junio C Hamano
  2014-03-31 22:38   ` Sverre Rabbelier
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2014-03-31 22:15 UTC (permalink / raw)
  To: Sverre Rabbelier; +Cc: Git List, Mario Ferraro

Sverre Rabbelier <srabbelier@gmail.com> writes:

> Hi,
>
> I noticed something very odd with git am, and have been able to narrow
> it down to a minimal example.
>
>  git init tmp
>  cd tmp
>  mkdir -p foo/bar/baz
>  cd foo/bar/baz
>  echo file > file
>  git add file
>  git commit -m "1"
>  echo other > other
>  echo more >> file
>  git add file other
>  git commit -m "my test"
>  git format-patch HEAD~..
>  git reset --hard HEAD~
>  # apply the patch in the current directory, chop off the leading directories
>  git am -3 -p 3 0001-my-test.patch
>  cd ../../..
>  git ls-files
>
> Expected output:
> foo/bar/baz/file
> foo/bar/baz/other
>
> Actual output:
> baz/other # the file addition was applied to the root of the
> repository, instead of the current directory
> foo/bar/baz/file # the file modification was correctly applied, yay
>
> Is this expected behavior?

As you are doing -3 (not the -p3), it would have:

 * noticed that the patch is trying to update "baz/file";

 * noticed that there is no "baz/file" but it could salvage the
   patch by doing a three-way merge, in case that the patch was
   prepared against a tree that moved path "foo/bar/baz" to "baz";
   and

 * such a three-way merge succeeds cleanly for a path whose movement
   was detected correctly.

So it does not look odd at all to me (the use of "-p 3" does look
odd, but I know this is an effort to come up with a minimum example,
so it is understandable that it may look contribed ;-).

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

* Re: git am oddity
  2014-03-31 22:15 ` Junio C Hamano
@ 2014-03-31 22:38   ` Sverre Rabbelier
  0 siblings, 0 replies; 3+ messages in thread
From: Sverre Rabbelier @ 2014-03-31 22:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Mario Ferraro

On Mon, Mar 31, 2014 at 3:15 PM, Junio C Hamano <gitster@pobox.com> wrote:
> As you are doing -3 (not the -p3), it would have:
>
>  * noticed that the patch is trying to update "baz/file";
>
>  * noticed that there is no "baz/file" but it could salvage the
>    patch by doing a three-way merge, in case that the patch was
>    prepared against a tree that moved path "foo/bar/baz" to "baz";
>    and
>
>  * such a three-way merge succeeds cleanly for a path whose movement
>    was detected correctly.
>
> So it does not look odd at all to me (the use of "-p 3" does look
> odd, but I know this is an effort to come up with a minimum example,
> so it is understandable that it may look contribed ;-).

Ah, we were thinking that 'git am' (when run from a subdirectory),
would apply the patches "from the current directory". So the right
solution was to instead do:

$  git am --directory=foo/bar/baz -p 3 0001-my-test.patch

Thank you,

-- 
Cheers,

Sverre Rabbelier

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

end of thread, other threads:[~2014-03-31 22:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-31 21:58 git am oddity Sverre Rabbelier
2014-03-31 22:15 ` Junio C Hamano
2014-03-31 22:38   ` Sverre Rabbelier

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).