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

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

From
Jerry Zhang <jerry@skydio.com>
Date
Apr 3, 2021, 01:34 UTC
Message-ID
<20210403013410.32064-2-jerry@skydio.com>
In-Reply-To
<20210403013410.32064-1-jerry@skydio.com>

Previously, --cached and --3way were not allowed to be used together, since --3way wrote conflict markers into the working tree.

These changes change semantics so that if these flags are given together and there is a conflict, the conflict markers are added directly to cache. If there is no conflict, the patch is applied directly to cache as expected.

Signed-off-by: Jerry Zhang <jerry@skydio.com>
Signed-off-by: Jerry Zhang <jerryxzha@googlemail.com>
---
 Documentation/git-apply.txt |  4 +++-
 apply.c                     | 13 +++++++------
 2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt
index 91d9a8601c..3dc0085066 100644
--- a/Documentation/git-apply.txt
+++ b/Documentation/git-apply.txt
@@ -89,7 +89,9 @@ OPTIONS
 	and we have those blobs available locally, possibly leaving the
 	conflict markers in the files in the working tree for the user to
 	resolve.  This option implies the `--index` option, and is incompatible
-	with the `--reject` and the `--cached` options.
+	with the `--reject` option. When used with the --cached option, any
+	conflict markers are added directly to the cache rather than the
+	working tree.
 
 --build-fake-ancestor=<file>::
 	Newer 'git diff' output has embedded 'index information'
diff --git a/apply.c b/apply.c
index 6695a931e9..fc94ca0e99 100644
--- a/apply.c
+++ b/apply.c
@@ -133,8 +133,6 @@ int check_apply_state(struct apply_state *state, int force_apply)
 
 	if (state->apply_with_reject && state->threeway)
 		return error(_("--reject and --3way cannot be used together."));
-	if (state->cached && state->threeway)
-		return error(_("--cached and --3way cannot be used together."));
 	if (state->threeway) {
 		if (is_not_gitdir)
 			return error(_("--3way outside a repository"));
@@ -4490,13 +4488,16 @@ static int create_file(struct apply_state *state, struct patch *patch)
 
 	if (!mode)
 		mode = S_IFREG | 0644;
-	if (create_one_file(state, path, mode, buf, size))
-		return -1;
+	if (!state->cached) {
+		if (create_one_file(state, path, mode, buf, size))
+			return -1;
+	}
 
-	if (patch->conflicted_threeway)
+	if (patch->conflicted_threeway && !state->cached)
 		return add_conflicted_stages_file(state, patch);
-	else if (state->update_index)
+	else if (state->update_index) {
 		return add_index_file(state, path, mode, buf, size);
+	}
 	return 0;
 }
 
-- 
2.29.0
Previous: Jerry ZhangNext: Elijah Newren
Message 2 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.