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

Re: [PATCH v2 8/9] merge-recursive: enforce rule that index matches head before merging

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 3, 2018, 20:05 UTC
Message-ID
<xmqqwoucozje.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180701012503.14382-9-newren@gmail.com>
Elijah Newren <newren@gmail.com> writes:
Show 9 quoted lines
>     ...[merge will] abort if there are any changes registered in the index
>     relative to the `HEAD` commit.  (One exception is when the changed index
>     entries are in the state that would result from the merge already.)
>
> While this high-level description does describe conditions under which it
> would be safe to allow the index to diverge from HEAD, it does not match
> what is actually implemented.  In particular, unpack-trees.c has no
> knowledge of renames, and these two exceptions were written assuming that
> no renames take place.

I think the above analysis is quite correct (I even suspect that the rule was outlined long before any renaming merge was designed).

Show 15 quoted lines
> diff --git a/merge-recursive.c b/merge-recursive.c
> index 855ca39ca..8f7a8e828 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -3257,6 +3257,13 @@ int merge_trees(struct merge_options *o,
>  		struct tree **result)
>  {
>  	int code, clean;
> +	struct strbuf sb = STRBUF_INIT;
> +
> +	if (!o->call_depth && index_has_changes(&the_index, head, &sb)) {
> +		err(o, _("Your local changes to the following files would be overwritten by merge:\n  %s"),
> +		    sb.buf);
> +		return -1;
> +	}

This change to ensure the index is pristine upfront makes sense, too.

Previous: Elijah NewrenNext: Elijah Newren
Message 25 of 30 in “merge requirement: index matches head”
  1. 0/7 merge requirement: index matches headElijah Newren, Jun 3, 2018
  2. 3/7 merge-recursive: make sure when we say we abort that we actually abortElijah Newren, Jun 3, 2018
  3. 2/7 t6044: add a testcase for index matching head, when head doesn't match HEADElijah Newren, Jun 3, 2018
  4. 5/7 t6044: add more testcases with staged changes before a merge is invokedElijah Newren, Jun 3, 2018
  5. 6/7 merge-recursive: enforce rule that index matches head before mergingElijah Newren, Jun 3, 2018
  6. 7/7 merge: fix misleading pre-merge check documentationElijah Newren, Jun 3, 2018
  7. Elijah NewrenJun 7, 2018
  8. 4/7 merge-recursive: fix assumption that head tree being merged is HEADElijah Newren, Jun 3, 2018
  9. Ramsay JonesJun 3, 2018
  10. brian m. carlsonJun 3, 2018
  11. Ramsay JonesJun 4, 2018
  12. Junio C HamanoJun 4, 2018
  13. Elijah NewrenJun 5, 2018
  14. Elijah NewrenJun 11, 2018
  15. 1/7 t6044: verify that merges expected to abort actually abortElijah Newren, Jun 3, 2018
  16. 0/9 Fix merge issues with index not matching HEADElijah Newren, Jul 1, 2018
  17. 1/9 read-cache.c: move index_has_changes() from merge.cElijah Newren, Jul 1, 2018
  18. 2/9 index_has_changes(): avoid assuming operating on the_indexElijah Newren, Jul 1, 2018
  19. Junio C HamanoJul 3, 2018
  20. 3/9 t6044: verify that merges expected to abort actually abortElijah Newren, Jul 1, 2018
  21. 4/9 t6044: add a testcase for index matching head, when head doesn't match HEADElijah Newren, Jul 1, 2018
  22. SZEDER GáborJul 10, 2018
  23. Elijah NewrenJul 11, 2018
  24. 8/9 merge-recursive: enforce rule that index matches head before mergingElijah Newren, Jul 1, 2018
  25. Junio C HamanoJul 3, 2018
  26. 5/9 merge-recursive: make sure when we say we abort that we actually abortElijah Newren, Jul 1, 2018
  27. 6/9 merge-recursive: fix assumption that head tree being merged is HEADElijah Newren, Jul 1, 2018
  28. Junio C HamanoJul 3, 2018
  29. 7/9 t6044: add more testcases with staged changes before a merge is invokedElijah Newren, Jul 1, 2018
  30. 9/9 merge: fix misleading pre-merge check documentationElijah Newren, Jul 1, 2018

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.