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

Re: Question about pre-merge and git merge octopus strategy

From
Junio C Hamano <gitster@pobox.com>
Date
May 12, 2022, 15:39 UTC
Message-ID
<xmqqk0aqhia1.fsf@gitster.g>
In-Reply-To
<CABPp-BHmNBMypVDrE=gPMXoHT9uH-u4HJG1dAuY0tjSGrK0yPg@mail.gmail.com>
Elijah Newren <newren@gmail.com> writes:
Show 37 quoted lines
>     Merge with strategy octopus failed.
>
> Also, if we check `git status`:
>
>     $ git status
>     On branch main
>     Unmerged paths:
>       (use "git restore --staged <file>..." to unstage)
>       (use "git add <file>..." to mark resolution)
>     both modified:   base
>
>     no changes added to commit (use "git add" and/or "git commit -a")
>
> And in git-merge-octopus.sh we see:
>
>     case "$OCTOPUS_FAILURE" in
>     1)
>     # We allow only last one to have a hand-resolvable
>     # conflicts.  Last round failed and we still had
>     # a head to merge.
>     gettextln "Automated merge did not work."
>     gettextln "Should not be doing an octopus."
>     exit 2
>     esac
>
> and in builtin/merge.c, we see:
>
>     /*
>      * The backend exits with 1 when conflicts are
>      * left to be resolved, with 2 when it does not
>      * handle the given merge at all.
>      */
>
> Which means git-merge-octopus.sh is claiming it can't handle this type
> of merge, and some other merge strategy should be tried, and
> implicitly that it didn't leave any conflicts to be resolved because
> it can't handle this merge.

Correct. Near the beginning of the loop you found the above comment, there is this code:

	if (use_strategies_nr == 1 ||
	    /*
	     * Stash away the local changes so that we can try more than one.
	     */
	    save_state(&stash))
		oidclr(&stash);
	for (i = 0; !merge_was_ok && i < use_strategies_nr; i++) {
		int ret, cnt;
		if (i) {
			printf(_("Rewinding the tree to pristine...\n"));
			restore_state(&head_commit->object.oid, &stash);
		}

but that save-then-restore triggers ONLY when there are multiple strategies to try. Unfortunately, octopus has no friends to fall back on, so we do not do the save-restore dance on the calling side.

> But it clearly decides to leave the
> modifications it made to the index and working tree around, which just
> seems wrong to me.

If merge-recursive or merge-resolve is asked to merge a single commit to the current branch without any other strategies to use as a fallback, they leave the working tree and index into a state where the end-user can conclude the conflict resolution and commit the result. In spirit, we are in the same situation, aren't we?

The user, if they want to proceed against octopus's opinion, would resolve the current conflict, read-tree -m the next one, ..., to conclude and commit the result.

So I am not sure if it is a good idea to unconditionally "reset --merge" in this situation.

Show 5 quoted lines
> +# If octopus is inapplicable, make sure we undo any changes we made first
> +cannot_octopus() {
> +       git reset --merge
> +       exit 2
> +}
Previous: Elijah NewrenNext: Elijah Newren
Message 9 of 15 in “Question about pre-merge and git merge octopus strategy”
  1. ZheNing HuMay 6, 2022
  2. Christian CouderMay 6, 2022
  3. Elijah NewrenMay 7, 2022
  4. Junio C HamanoMay 7, 2022
  5. ZheNing HuMay 8, 2022
  6. Elijah NewrenMay 10, 2022
  7. ZheNing HuMay 11, 2022
  8. Elijah NewrenMay 12, 2022
  9. Junio C HamanoMay 12, 2022
  10. Elijah NewrenMay 13, 2022
  11. Junio C HamanoMay 13, 2022
  12. ZheNing HuMay 19, 2022
  13. Elijah NewrenMay 19, 2022
  14. ZheNing HuMay 8, 2022
  15. Carlo Marcelo Arenas BelónMay 8, 2022

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.