Skip to content

Commit 73f29c8

Browse files
committed
Merge branch 'yt/merge-file-outside-a-repository'
"git merge-file" can be run outside a repository, but it ignored all configuration, even the per-user ones. The command now uses available configuration files to find its customization. * yt/merge-file-outside-a-repository: merge-file: honor merge.conflictStyle outside of a repository
2 parents 6de2d14 + 8600b4e commit 73f29c8

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

Documentation/git-merge-file.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ object store and the object ID of its blob is written to standard output.
8585
8686
--zdiff3::
8787
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]).
8891
8992
--ours::
9093
--theirs::

builtin/merge-file.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int diff_algorithm_cb(const struct option *opt,
6060
int cmd_merge_file(int argc,
6161
const char **argv,
6262
const char *prefix,
63-
struct repository *repo UNUSED)
63+
struct repository *repo)
6464
{
6565
const char *names[3] = { 0 };
6666
mmfile_t mmfs[3] = { 0 };
@@ -95,12 +95,10 @@ int cmd_merge_file(int argc,
9595
xmp.style = 0;
9696
xmp.favor = 0;
9797

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;
104102

105103
argc = parse_options(argc, argv, prefix, options, merge_file_usage, 0);
106104
if (argc != 3)

t/t6403-merge-file.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,42 @@ test_expect_success '"diff3 -m" style output (2)' '
428428
test_cmp expect actual
429429
'
430430

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+
431467
test_expect_success 'marker size' '
432468
cat >expect <<-\EOF &&
433469
Dominus regit me,

0 commit comments

Comments
 (0)