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

[PATCH v2 6/8] merge-recursive: allow storing conflict hunks in index

From
Thomas Rast <tr@thomasrast.ch>
Date
Feb 22, 2014, 09:17 UTC
Message-ID
<a8898c0544850c5170ad76fa6fbed9991ad6aba1.1393059605.git.tr@thomasrast.ch>
In-Reply-To
<cover.1393059605.git.tr@thomasrast.ch>

Add a --conflicts-in-index option to merge-recursive, which instructs it to always store the 3-way merged result in the index. (Normally it only does so in recursive invocations, but not for the final result.)

This serves as a building block for the "remerge diff" feature coming up in a subsequent patch. The external option lets us easily use it from tests, where we'd otherwise need a new test-* helper to access the feature.

Furthermore, it might occasionally be useful for scripts that want to look at the result of invoking git-merge without tampering with the worktree. They could already get the _conflicts_ with --index-only, but not (conveniently) the conflict-hunk formatted files that would normally be written to the worktree.

Signed-off-by: Thomas Rast <tr@thomasrast.ch>
---
 Documentation/merge-strategies.txt |  5 +++++
 merge-recursive.c                  |  4 ++++
 merge-recursive.h                  |  1 +
 t/t3030-merge-recursive.sh         | 20 ++++++++++++++++++++
 4 files changed, 30 insertions(+)
diff --git a/Documentation/merge-strategies.txt b/Documentation/merge-strategies.txt
index 2934e99..3468d99 100644
--- a/Documentation/merge-strategies.txt
+++ b/Documentation/merge-strategies.txt
@@ -96,6 +96,11 @@ index-only;;
 	Write the merge result only to the index; do not touch the
 	worktree.
 
+conflicts-in-index;;
+	For conflicted files, write 3-way merged contents with
+	conflict hunks to the index, instead of leaving their entries
+	unresolved.
+
 octopus::
 	This resolves cases with more than two heads, but refuses to do
 	a complex merge that needs manual resolution.  It is
diff --git a/merge-recursive.c b/merge-recursive.c
index f59c1d3..b682812 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -724,6 +724,8 @@ static void update_file_flags(struct merge_options *o,
 			      int update_cache,
 			      int update_wd)
 {
+	if (o->conflicts_in_index)
+		update_cache = 1;
 	if (o->call_depth || o->no_worktree)
 		update_wd = 0;
 
@@ -2098,6 +2100,8 @@ int parse_merge_opt(struct merge_options *o, const char *s)
 	}
 	else if (!strcmp(s, "index-only"))
 		o->no_worktree = 1;
+	else if (!strcmp(s, "conflicts-in-index"))
+		o->conflicts_in_index = 1;
 	else
 		return -1;
 	return 0;
diff --git a/merge-recursive.h b/merge-recursive.h
index d8dd7a1..9b8e20b 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -16,6 +16,7 @@ struct merge_options {
 	unsigned buffer_output : 1;
 	unsigned renormalize : 1;
 	unsigned no_worktree : 1; /* do not touch worktree */
+	unsigned conflicts_in_index : 1; /* index will contain conflict hunks */
 	long xdl_opts;
 	int verbosity;
 	int diff_rename_limit;
diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh
index 2f3a16c..4192fd3 100755
--- a/t/t3030-merge-recursive.sh
+++ b/t/t3030-merge-recursive.sh
@@ -309,6 +309,26 @@ test_expect_success 'merge-recursive --index-only' '
 	test_cmp expected-diff actual-diff
 '
 
+test_expect_success 'merge-recursive --index-only --conflicts-in-index' '
+	# first pass: do a merge as usual to obtain "expected"
+	rm -fr [abcd] &&
+	git checkout -f "$c2" &&
+	test_expect_code 1 git merge-recursive "$c0" -- "$c2" "$c1" &&
+	git add [abcd] &&
+	git ls-files -s >expected &&
+	# second pass: actual test
+	rm -fr [abcd] &&
+	git checkout -f "$c2" &&
+	test_expect_code 1 \
+		git merge-recursive --index-only --conflicts-in-index \
+		"$c0" -- "$c2" "$c1" &&
+	git ls-files -s >actual &&
+	test_cmp expected actual &&
+	git diff HEAD >actual-diff &&
+	: >expected-diff &&
+	test_cmp expected-diff actual-diff
+'
+
 test_expect_success 'fail if the index has unresolved entries' '
 
 	rm -fr [abcd] &&
-- 
1.9.0.313.g3d0a325
Previous: Thomas RastNext: Thomas Rast
Message 10 of 16 in “log --remerge-diff”
  1. 0/8 log --remerge-diffThomas Rast, Feb 22, 2014
  2. 1/8 merge-recursive: remove dead conditional in update_stages()Thomas Rast, Feb 22, 2014
  3. 2/8 merge-recursive: internal flag to avoid touching the worktreeThomas Rast, Feb 22, 2014
  4. 3/8 merge-recursive: -Xindex-only to leave worktree unchangedThomas Rast, Feb 22, 2014
  5. Eric SunshineFeb 23, 2014
  6. Thomas RastFeb 23, 2014
  7. Eric SunshineFeb 23, 2014
  8. 4/8 combine-diff: do not pass revs->dense_combined_merges redundantlyThomas Rast, Feb 22, 2014
  9. 5/8 Fold all merge diff variants into an enumThomas Rast, Feb 22, 2014
  10. 6/8 merge-recursive: allow storing conflict hunks in indexThomas Rast, Feb 22, 2014
  11. 7/8 name-hash: allow dir hashing even when !ignore_caseThomas Rast, Feb 22, 2014
  12. Eric SunshineFeb 23, 2014
  13. Thomas RastSep 6, 2014
  14. Junio C HamanoFeb 27, 2014
  15. 8/8 log --remerge-diff: show what the conflict resolution changedThomas Rast, Feb 22, 2014
  16. Junio C HamanoFeb 27, 2014

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.