Skip to content

Commit 2f0db1d

Browse files
committed
Merge branch 'jc/maint-branch-mergeoptions' into maint
* jc/maint-branch-mergeoptions: merge: make branch.<name>.mergeoptions correctly override merge.<option> Conflicts: builtin/merge.c
2 parents c69e8b6 + 0d8fc3e commit 2f0db1d

File tree

2 files changed

+58
-15
lines changed

2 files changed

+58
-15
lines changed

builtin/merge.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static size_t use_strategies_nr, use_strategies_alloc;
5656
static const char **xopts;
5757
static size_t xopts_nr, xopts_alloc;
5858
static const char *branch;
59+
static char *branch_mergeoptions;
5960
static int option_renormalize;
6061
static int verbosity;
6162
static int allow_rerere_auto;
@@ -503,26 +504,34 @@ static void merge_name(const char *remote, struct strbuf *msg)
503504
strbuf_release(&bname);
504505
}
505506

507+
static void parse_branch_merge_options(char *bmo)
508+
{
509+
const char **argv;
510+
int argc;
511+
512+
if (!bmo)
513+
return;
514+
argc = split_cmdline(bmo, &argv);
515+
if (argc < 0)
516+
die(_("Bad branch.%s.mergeoptions string: %s"), branch,
517+
split_cmdline_strerror(argc));
518+
argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
519+
memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
520+
argc++;
521+
argv[0] = "branch.*.mergeoptions";
522+
parse_options(argc, argv, NULL, builtin_merge_options,
523+
builtin_merge_usage, 0);
524+
free(argv);
525+
}
526+
506527
static int git_merge_config(const char *k, const char *v, void *cb)
507528
{
508529
if (branch && !prefixcmp(k, "branch.") &&
509530
!prefixcmp(k + 7, branch) &&
510531
!strcmp(k + 7 + strlen(branch), ".mergeoptions")) {
511-
const char **argv;
512-
int argc;
513-
char *buf;
514-
515-
buf = xstrdup(v);
516-
argc = split_cmdline(buf, &argv);
517-
if (argc < 0)
518-
die(_("Bad branch.%s.mergeoptions string: %s"), branch,
519-
split_cmdline_strerror(argc));
520-
argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
521-
memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
522-
argc++;
523-
parse_options(argc, argv, NULL, builtin_merge_options,
524-
builtin_merge_usage, 0);
525-
free(buf);
532+
free(branch_mergeoptions);
533+
branch_mergeoptions = xstrdup(v);
534+
return 0;
526535
}
527536

528537
if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
@@ -1010,6 +1019,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
10101019
if (diff_use_color_default == -1)
10111020
diff_use_color_default = git_use_color_default;
10121021

1022+
if (branch_mergeoptions)
1023+
parse_branch_merge_options(branch_mergeoptions);
10131024
argc = parse_options(argc, argv, prefix, builtin_merge_options,
10141025
builtin_merge_usage, 0);
10151026

t/t7600-merge.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,38 @@ test_expect_success 'merge c1 with c2 (no-commit in config)' '
324324

325325
test_debug 'git log --graph --decorate --oneline --all'
326326

327+
test_expect_success 'merge c1 with c2 (log in config)' '
328+
git config branch.master.mergeoptions "" &&
329+
git reset --hard c1 &&
330+
git merge --log c2 &&
331+
git show -s --pretty=tformat:%s%n%b >expect &&
332+
333+
git config branch.master.mergeoptions --log &&
334+
git reset --hard c1 &&
335+
git merge c2 &&
336+
git show -s --pretty=tformat:%s%n%b >actual &&
337+
338+
test_cmp expect actual
339+
'
340+
341+
test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
342+
(
343+
git config --remove-section branch.master
344+
git config --remove-section merge
345+
)
346+
git reset --hard c1 &&
347+
git merge c2 &&
348+
git show -s --pretty=tformat:%s%n%b >expect &&
349+
350+
git config branch.master.mergeoptions "--no-log" &&
351+
git config merge.log true &&
352+
git reset --hard c1 &&
353+
git merge c2 &&
354+
git show -s --pretty=tformat:%s%n%b >actual &&
355+
356+
test_cmp expect actual
357+
'
358+
327359
test_expect_success 'merge c1 with c2 (squash in config)' '
328360
git reset --hard c1 &&
329361
git config branch.master.mergeoptions "--squash" &&

0 commit comments

Comments
 (0)