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

Re: git merge commits staged files (when two trees are identical)

From
Elijah Newren <newren@gmail.com>
Date
Dec 21, 2017, 18:50 UTC
Message-ID
<CABPp-BGy3_RyVQfCm+9O_AAfKA0_CZ5ajJE7NuLbToERWyWmqQ@mail.gmail.com>
In-Reply-To
<20171220114310.GA2049@inner.h.apk.li>
On Wed, Dec 20, 2017 at 3:43 AM, Andreas Krey <a.krey@gmx.de> wrote:
Show 31 quoted lines
> Hi everybody,
>
> we just stumbled over a situation in which a merge commits
> staged changes into the merge commit. This happens when the
> merged-in branch does have commits ('main') but has the same
> tree ('--allow-empty') as the merge base:
>
>     git init
>     echo eins >a
>     git add a
>     git commit -m initial
>     git branch sub
>     git commit -m main --allow-empty
>     git checkout sub
>     : two
>     echo zwei >>a
>     git add a
>     git commit -m underway
>     : three
>     echo drei >>a
>     git add a              # important
>     git status
>     git diff --cached
>     git merge master -m 'merge'
>     git status
>     git log --cc -1
>
> If the change isn't staged (comment out the '# important' line)
> the change survives as unstaged.
>
> That is a bug?

Yes, it's definitely a bug; thanks for reporting it. We have a specific set of tests for this type of situation in t6044, which was intended to test all the merge strategies and ensure they didn't have this class of bug. It turns out that there is an additional codepath within one of the strategies that wasn't tested, and which you've tripped over. I've got some patches to fix this up that I'll respond with shortly.

Previous: Andreas KreyNext: Elijah Newren
Message 2 of 15 in “git merge commits staged files (when two trees are identical)”
  1. Andreas KreyDec 20, 2017
  2. Elijah NewrenDec 21, 2017
  3. 1/3 t6044: recursive can silently incorporate dirty changes in a mergeElijah Newren, Dec 21, 2017
  4. 3/3 merge-recursive: Avoid incorporating uncommitted changes in a mergeElijah Newren, Dec 21, 2017
  5. Junio C HamanoDec 22, 2017
  6. Junio C HamanoJan 8, 2018
  7. merge-recursive: do not look at the index during recursive mergeJunio C Hamano, Jan 9, 2018
  8. Junio C HamanoJan 9, 2018
  9. Eric SunshineJan 9, 2018
  10. Elijah NewrenJan 9, 2018
  11. Junio C HamanoJan 9, 2018
  12. 2/3 move index_has_changes() from builtin/am.c to merge.c for reuseElijah Newren, Dec 21, 2017
  13. Elijah NewrenDec 21, 2017
  14. Junio C HamanoDec 22, 2017
  15. Elijah NewrenDec 23, 2017

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.