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 <dev@ytausch.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Yannik Tausch committed Feb 7, 2026 at 22:37 UTC 8600b4ec9ef9577408194a99066c356f38139b06
3 files changed +44 -7
Documentation/git-merge-file.adoc
+3
@@ -85,6 +85,9 @@ object store and the object ID of its blob is written to standard output.
85
86 --zdiff3::
87 Show conflicts in "zdiff3" style.
88 ++
89 +The `--diff3` and `--zdiff3` options default to the value of the
90 +`merge.conflictStyle` configuration variable (see linkgit:git-config[1]).
91
92 --ours::
93 --theirs::
builtin/merge-file.c
+5 -7
@@ -60,7 +60,7 @@ static int diff_algorithm_cb(const struct option *opt,
60 int cmd_merge_file(int argc,
61 const char **argv,
62 const char *prefix,
63 - struct repository *repo UNUSED)
63 + struct repository *repo)
64 {
65 const char *names[3] = { 0 };
66 mmfile_t mmfs[3] = { 0 };
@@ -95,12 +95,10 @@ int cmd_merge_file(int argc,
95 xmp.style = 0;
96 xmp.favor = 0;
97
98 - if (startup_info->have_repository) {
99 - /* Read the configuration file */
100 - repo_config(the_repository, git_xmerge_config, NULL);
101 - if (0 <= git_xmerge_style)
102 - xmp.style = git_xmerge_style;
103 - }
98 + /* Read the configuration file */
99 + repo_config(repo, git_xmerge_config, NULL);
100 + if (0 <= git_xmerge_style)
101 + xmp.style = git_xmerge_style;
102
103 argc = parse_options(argc, argv, prefix, options, merge_file_usage, 0);
104 if (argc != 3)
t/t6403-merge-file.sh
+36
@@ -428,6 +428,42 @@ test_expect_success '"diff3 -m" style output (2)' '
428 test_cmp expect actual
429 '
430
431 +test_expect_success 'merge.conflictStyle honored outside repo' '
432 + test_config_global merge.conflictStyle diff3 &&
433 + cat >nongit-base <<-\EOF &&
434 + line1
435 + original
436 + line3
437 + EOF
438 + cat >nongit-ours <<-\EOF &&
439 + line1
440 + ours
441 + line3
442 + EOF
443 + cat >nongit-theirs <<-\EOF &&
444 + line1
445 + theirs
446 + line3
447 + EOF
448 + cat >expect <<-\EOF &&
449 + line1
450 + <<<<<<< ours
451 + ours
452 + ||||||| base
453 + original
454 + =======
455 + theirs
456 + >>>>>>> theirs
457 + line3
458 + EOF
459 + test_must_fail nongit git merge-file -p \
460 + -L ours -L base -L theirs \
461 + "$PWD/nongit-ours" \
462 + "$PWD/nongit-base" \
463 + "$PWD/nongit-theirs" >actual &&
464 + test_cmp expect actual
465 +'
466 +
467 test_expect_success 'marker size' '
468 cat >expect <<-\EOF &&
469 Dominus regit me,