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

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

From: Yannik Tausch <hidden>
Date: 2026-02-05 20:27:43
Subsystem: documentation, the rest · Maintainers: Jonathan Corbet, Linus Torvalds

Possibly related (same subject, not in this thread)

Junio C Hamano [off-list ref] writes:

Yannik Tausch [off-list ref] writes:
quoted
We noticed that `git merge-file` only respects the `merge.conflictStyle`
configuration when run inside a repository. Outside a repository, the
setting is ignored and only the `--diff3`/`--zdiff3` flags work.

Looking at the history, this appears to be intentional since b541248467
("merge.conflictstyle: choose between merge and diff3 -m styles", 2008),
which explicitly gates config reading on being inside a repository.

This behavior surprised me, and I couldn't find it documented anywhere.
Would a small documentation patch to git-merge-file.txt be welcome,
noting that the config is only read when inside a repository?
Or even better, teach the command to read (limited set of)
configuration files.

By definition, you cannot read from per-repository configuration
file when working outside a repository, but these days we let our
commands read configuration from system and personal configuration
files, I think.  Back in 2008, it is understandable we couldn't.
Thanks for the suggestion. Here's a patch:

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

When running outside a repository, git merge-file previously ignored
the merge.conflictStyle configuration variable entirely. Teach it to
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.

Signed-off-by: Yannik Tausch <redacted>
---
 Documentation/git-merge-file.adoc |  3 +++
 builtin/merge-file.c              | 11 +++++-----
 t/t6403-merge-file.sh             | 34 +++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-merge-file.adoc b/Documentation/git-merge-file.adoc
index 71915a00fa..773037aa14 100644
--- a/Documentation/git-merge-file.adoc
+++ b/Documentation/git-merge-file.adoc
@@ -86,6 +86,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::
 --union::
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 46775d0c79..1b6e16b9cb 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -95,12 +95,13 @@ int cmd_merge_file(int argc,
 	xmp.style = 0;
 	xmp.favor = 0;
 
-	if (startup_info->have_repository) {
-		/* Read the configuration file */
+	if (startup_info->have_repository)
 		repo_config(the_repository, git_xmerge_config, NULL);
-		if (0 <= git_xmerge_style)
-			xmp.style = git_xmerge_style;
-	}
+	else
+		read_very_early_config(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..9df9f878c8 100755
--- a/t/t6403-merge-file.sh
+++ b/t/t6403-merge-file.sh
@@ -428,6 +428,40 @@ 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 >nongit-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" >nongit-actual &&
+	test_cmp nongit-expect nongit-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