Thread (4 messages) flat view 4 messages, 3 authors, 2026-02-05

Re: [PATCH v2] merge-file: honor merge.conflictStyle outside of a repository

From: Yannik Tausch <hidden>
Date: 2026-02-05 21:56:15
Subsystem: documentation, the rest · Maintainers: Jonathan Corbet, Linus Torvalds

Possibly related (same subject, not in this thread)

Junio C Hamano [off-list ref] wrote:
Wouldn't it suffice to unconditionally execute the body of the if
(startup_info->have_repository) block to pass "repo" we obtained
from the caller to repo_config() instead of the_repository?  The
caller of this function passes us either the_repository or NULL and
repo_config() does the very-early thing when passed NULL as the
repo, signalling that we are outside a repository.
Jup, looks like I missed that. Implemented your suggestion!
Kristoffer Haugsbakk [off-list ref] wrote:
Preferably the message should discuss the code as it exists without the
patch applied in the present tense. (SubmittingPatches present-tense)
Fixed!
quoted
read from system and user configuration files using
read_very_early_config(), so that users can set their preferred
conflict style globally and have it honored even outside a repository.
The update to the documentation might merit an “also”? I dunno.
Added!
You need to replace this blank line with a `+` if you want this to be
the second paragraph on this option.
Fixed!
Some tests in this file already use the regular expect/actual but there
are also many one-off names like expect.c/myers_output.c. I don’t
understand why. But I’m just thinking out loud here.
I also don’t understand why, but considering your point, I don’t see a reason
to not use the regular expect/actual convention. Fixed.
It seems you might as well break the lines for this command further with
some `\` to get closer to the soft limit.
Done!

Here is the new patch:

From 9fa437c70bfd328cfdfe9cfca982b49b70ad033f Mon Sep 17 00:00:00 2001
From: Yannik Tausch <redacted>
Date: Thu, 5 Feb 2026 21:09:52 +0100
Subject: [PATCH v2] merge-file: honor merge.conflictStyle outside of a
 repository

When running outside a repository, git merge-file ignores the
merge.conflictStyle configuration variable entirely. Since the
function receives `repo` from the caller (which is NULL outside a
repository), and repo_config() falls back to reading system and user
configuration when passed NULL, pass `repo` to repo_config()
unconditionally.

Also document that merge.conflictStyle is honored.

Signed-off-by: Yannik Tausch <redacted>
---

Notes:
    Changes since v1:
    - Use repo parameter directly with repo_config() (Junio)
    - Fix AsciiDoc continuation, rename test files, break long
      lines (Kristoffer)

 Documentation/git-merge-file.adoc |  3 +++
 builtin/merge-file.c              | 12 +++++------
 t/t6403-merge-file.sh             | 36 +++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-merge-file.adoc b/Documentation/git-merge-file.adoc
index 71915a00fa..9dc5d8a370 100644
--- a/Documentation/git-merge-file.adoc
+++ b/Documentation/git-merge-file.adoc
@@ -85,6 +85,9 @@ object store and the object ID of its blob is written to standard output.
 
 --zdiff3::
 	Show conflicts in "zdiff3" style.
++
+The `--diff3` and `--zdiff3` options default to the value of the
+`merge.conflictStyle` configuration variable (see linkgit:git-config[1]).
 
 --ours::
 --theirs::
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 46775d0c79..f9de636884 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -60,7 +60,7 @@ static int diff_algorithm_cb(const struct option *opt,
 int cmd_merge_file(int argc,
 		   const char **argv,
 		   const char *prefix,
-		   struct repository *repo UNUSED)
+		   struct repository *repo)
 {
 	const char *names[3] = { 0 };
 	mmfile_t mmfs[3] = { 0 };
@@ -95,12 +95,10 @@ int cmd_merge_file(int argc,
 	xmp.style = 0;
 	xmp.favor = 0;
 
-	if (startup_info->have_repository) {
-		/* Read the configuration file */
-		repo_config(the_repository, git_xmerge_config, NULL);
-		if (0 <= git_xmerge_style)
-			xmp.style = git_xmerge_style;
-	}
+	/* Read the configuration file */
+	repo_config(repo, git_xmerge_config, NULL);
+	if (0 <= git_xmerge_style)
+		xmp.style = git_xmerge_style;
 
 	argc = parse_options(argc, argv, prefix, options, merge_file_usage, 0);
 	if (argc != 3)
diff --git a/t/t6403-merge-file.sh b/t/t6403-merge-file.sh
index 06ab4d7aed..4d6e748320 100755
--- a/t/t6403-merge-file.sh
+++ b/t/t6403-merge-file.sh
@@ -428,6 +428,42 @@ test_expect_success '"diff3 -m" style output (2)' '
 	test_cmp expect actual
 '
 
+test_expect_success 'merge.conflictStyle honored outside repo' '
+	test_config_global merge.conflictStyle diff3 &&
+	cat >nongit-base <<-\EOF &&
+	line1
+	original
+	line3
+	EOF
+	cat >nongit-ours <<-\EOF &&
+	line1
+	ours
+	line3
+	EOF
+	cat >nongit-theirs <<-\EOF &&
+	line1
+	theirs
+	line3
+	EOF
+	cat >expect <<-\EOF &&
+	line1
+	<<<<<<< ours
+	ours
+	||||||| base
+	original
+	=======
+	theirs
+	>>>>>>> theirs
+	line3
+	EOF
+	test_must_fail nongit git merge-file -p \
+		-L ours -L base -L theirs \
+		"$PWD/nongit-ours" \
+		"$PWD/nongit-base" \
+		"$PWD/nongit-theirs" >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'marker size' '
 	cat >expect <<-\EOF &&
 	Dominus regit me,
-- 
2.52.0


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help