public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Sverre Rabbelier <srabbelier@gmail•com>
Cc: Git List <git@vger•kernel.org>, Mario Ferraro <fadinlight@gmail•com>
Subject: Re: git am oddity
Date: Mon, 31 Mar 2014 15:15:22 -0700	[thread overview]
Message-ID: <xmqqbnwm2ex1.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <CAGdFq_gZoiE_ah0VT5ZfQwg-zHNj6Q-RSB80f=BTf=U6+9L5UA@mail.gmail.com> (Sverre Rabbelier's message of "Mon, 31 Mar 2014 14:58:22 -0700")

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

  reply	other threads:[~2014-03-31 22:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-31 21:58 git am oddity Sverre Rabbelier
2014-03-31 22:15 ` Junio C Hamano [this message]
2014-03-31 22:38   ` Sverre Rabbelier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqbnwm2ex1.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=fadinlight@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=srabbelier@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox