git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: New directory lost by git am

From
Jeff King <peff@peff.net>
Date
Mar 5, 2014, 17:13 UTC
Message-ID
<20140305171334.GA31252@sigill.intra.peff.net>
In-Reply-To
<53175510.7020000@ubuntu.com>
On Wed, Mar 05, 2014 at 11:47:12AM -0500, Phillip Susi wrote:
Show 8 quoted lines
> > I can't get Chris's script to fail on any version of git. Can you
> > show us an example of a patch that does not behave (or better yet,
> > a reproduction recipe to generate the patch with "format-patch")?
> 
> AHA!  It requires a conflict.  There were simple conflicts in the NEWS
> file so I applied the patch with git am --reject and fixed up the
> NEWS, and ran git am --resolved.  The git am --reject fails to add the
> new directory to the index.

Thanks, I can reproduce here. I do not think it has anything to do with being in a subdirectory; any new file does not get added to the index. In fact, I do not think we update the index at all with "--reject". For example, try this:

    git init repo &&
    cd repo &&
    echo base >conflict &&
    echo base >modified &&
    git add . &&
    git commit -m base &&
    echo master >conflict &&
    git add . &&
    git commit -m master &&
    git checkout -b other HEAD^ &&
    echo other >conflict &&
    echo other >modified &&
    echo other >new &&
    git add . &&
    git commit -m other &&
    git checkout master &&
    git format-patch other -1 --stdout >patch &&
    git am --reject patch
Running "git status -s" shows:
   M modified
   ?? conflict.rej
   ?? new
   ?? patch

We apply the changes to "modified" and "new" to the working tree, but we do not stage anything in the index. I suspect this is because our invocation of "apply --index" (which is what is doing the real work with "--reject" here) bails before touching the index. In theory it should be able to update the index for files that applied cleanly and leave the other ones alone.

But I have not thought hard about it, so maybe there is a good reason not to (it is a little weird just because the resulting index is a partial application of the patch). The "am -3" path does what you want here, but it is much simpler: it knows it can represent the 3-way conflict in the index. So the index represents the complete state of the patch application at the end, including conflicts.

-Peff
Previous: Phillip SusiNext: Phillip Susi
Message 8 of 10 in “New directory lost by git am”
  1. Phillip SusiMar 5, 2014
  2. Chris PackhamMar 5, 2014
  3. Phillip SusiMar 5, 2014
  4. Chris PackhamMar 5, 2014
  5. Phillip SusiMar 5, 2014
  6. Jeff KingMar 5, 2014
  7. Phillip SusiMar 5, 2014
  8. Jeff KingMar 5, 2014
  9. Phillip SusiMar 5, 2014
  10. Junio C HamanoMar 5, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.