]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-file: honor merge.conflictStyle outside of a repository
authorYannik Tausch <dev@ytausch.de>
Sat, 7 Feb 2026 21:37:48 +0000 (22:37 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 8 Feb 2026 01:04:26 +0000 (17:04 -0800)
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>
Documentation/git-merge-file.adoc
builtin/merge-file.c
t/t6403-merge-file.sh

index 71915a00fa472e73f5fadd2205f964919d3262db..9dc5d8a3707a5d01d14578a00a23c9a36e339add 100644 (file)
@@ -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::
index 46775d0c79f4547a23b9b7e9abdef976a2005832..f9de63688461cacee6834d4aa70b1a6aa51db206 100644 (file)
@@ -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)
index 06ab4d7aede08139165bfa27c1bbddb97cc06aad..4d6e74832010ba31acd192d8ded187caace526b4 100755 (executable)
@@ -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,