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

Re: [PATCH 1/1] git-apply: Allow simultaneous --cached and --3way options

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 4, 2021, 01:02 UTC
Message-ID
<xmqq1rbq276g.fsf@gitster.g>
In-Reply-To
<xmqqy2e00zaf.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 23 quoted lines
> It might be OK to only allow the combination when everything auto
> resolves cleanly and fail the operation without touching either the
> index or the working tree.  Pretending there was no delete/modify
> conflicts or adding contents with unresolved conflicts as if nothing
> bad happened as stage 0 entries would never be acceptable.
>
> Perhaps
>
>  * Error out if the index does not match HEAD.
>
>  * Try applying to the contents in the index.  If there are any
>    structural conflicts, leave these paths at higher stage and do
>    not touch their contents.
>
>  * For paths without structural conflict but need content merges,
>    attempt ll-merge of the contents.  If autoresolves cleanly,
>    register the result at stage 0.  Otherwise, discard the failed
>    conflicted merge, and leave stages 1, 2 and 3 as they are.
>
>  * Exit with status 0 if and only if everything has resolved
>    cleanly.  Otherwise, exit with non-zero status.
>
> would be the minimally-acceptably-safe behaviour.

Note that, while a lot unsatisfactory than the above, the following would also be acceptable.

  * Error out if the index does not match HEAD.
  * Try applying to the contents in the index.  If there are any
    structural conflicts, abort without touching the index (or the
    working tree --- but that is best left unsaid as we all know we
    are talking about '--cached').
  * For paths without structural conflict but need content merges,
    attempt ll-merge of the contents.  If ALL SUCh PATHS autoresolve
    cleanly, register their result at stage 0.  Otherwise, abort
    without touching the index (or the working tree).
  * Exit with status 0 if and only if everything has resolved
    cleanly.  Otherwise, exit with non-zero status (and never touch
    the index or the working tree).

The version I earlier gave would give a good starting point to manually resolve the conflicts in the index and when resolved fully, it is safely recorded as the result of applying the patch on top of HEAD, because the non-final results are all in higher stages, and all the paths at stage 0 are either from the HEAD and unaffected by the merge, or the ones that cleanly resolved. The "the index must match HEAD" upfront is to ensure that. Otherwise it would make it very tempting, after spending all that time to resolve the conflicts only in the higher stages of the index, to commit the index as-is to make a child commit of HEAD and record that it is the result of applying the patch. But if the starting condition had a change unrelated to the change the patch brings in already in the index, the resulting commit would be _more_ than what the patch did to the codebase.

The simplified version would let the user proceed only when the conflicts can mechanically resolved, but it still has the "make sure what is recorded is only from the incoming patch" safety.

Of course, if the user is trying to cherry-pick parts of multiple patches and combine them to create a new single commit, the second and subsequent applycation of the patches would be thwarted by the "the index must match HEAD" rule, but it is far safer to make each step into its own snapshot commit during such a workflow to combine multiple patch pieces and then squash them together after finishing, than carrying an intermediate result only in the index and risk losing work you did in the previous step(s) to incorrect resolution in later step(s).

Previous: Junio C HamanoNext: Jerry Zhang
Message 5 of 29 in “git-apply: Allow simultaneous --cached and --3way options”
  1. 0/1 git-apply: Allow simultaneous --cached and --3way optionsJerry Zhang, Apr 3, 2021
  2. 1/1 git-apply: Allow simultaneous --cached and --3way optionsJerry Zhang, Apr 3, 2021
  3. Elijah NewrenApr 3, 2021
  4. Junio C HamanoApr 3, 2021
  5. Junio C HamanoApr 4, 2021
  6. Jerry ZhangApr 5, 2021
  7. Junio C HamanoApr 5, 2021
  8. Jerry ZhangApr 5, 2021
  9. Junio C HamanoApr 6, 2021
  10. Jerry ZhangApr 5, 2021
  11. git-apply: Allow simultaneous --cached and --3way optionsJerry Zhang, Apr 5, 2021
  12. Junio C HamanoApr 5, 2021
  13. Jerry ZhangApr 6, 2021
  14. Junio C HamanoApr 6, 2021
  15. Jerry ZhangApr 6, 2021
  16. Jerry ZhangApr 7, 2021
  17. git-apply: allow simultaneous --cached and --3way optionsJerry Zhang, Apr 6, 2021
  18. git-apply: allow simultaneous --cached and --3way optionsJerry Zhang, Apr 7, 2021
  19. Junio C HamanoApr 7, 2021
  20. git-apply: allow simultaneous --cached and --3way optionsJerry Zhang, Apr 8, 2021
  21. Junio C HamanoApr 8, 2021
  22. Elijah NewrenApr 12, 2021
  23. Junio C HamanoApr 12, 2021
  24. Elijah NewrenApr 12, 2021
  25. Junio C HamanoApr 12, 2021
  26. Elijah NewrenApr 3, 2021
  27. Jerry ZhangApr 5, 2021
  28. Bagas SanjayaApr 3, 2021
  29. Bagas SanjayaApr 3, 2021

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.