Merge branch 'jc/maint-branch-mergeoptions'

* jc/maint-branch-mergeoptions:
  merge: make branch.<name>.mergeoptions correctly override merge.<option>

Conflicts:
	builtin/merge.c
This commit is contained in:
Junio C Hamano 2011-05-11 11:38:36 -07:00
commit c7fe5b61e1
2 changed files with 58 additions and 15 deletions

View File

@ -56,6 +56,7 @@ static size_t use_strategies_nr, use_strategies_alloc;
static const char **xopts; static const char **xopts;
static size_t xopts_nr, xopts_alloc; static size_t xopts_nr, xopts_alloc;
static const char *branch; static const char *branch;
static char *branch_mergeoptions;
static int option_renormalize; static int option_renormalize;
static int verbosity; static int verbosity;
static int allow_rerere_auto; static int allow_rerere_auto;
@ -503,26 +504,34 @@ cleanup:
strbuf_release(&bname); strbuf_release(&bname);
} }
static int git_merge_config(const char *k, const char *v, void *cb) static void parse_branch_merge_options(char *bmo)
{ {
if (branch && !prefixcmp(k, "branch.") &&
!prefixcmp(k + 7, branch) &&
!strcmp(k + 7 + strlen(branch), ".mergeoptions")) {
const char **argv; const char **argv;
int argc; int argc;
char *buf;
buf = xstrdup(v); if (!bmo)
argc = split_cmdline(buf, &argv); return;
argc = split_cmdline(bmo, &argv);
if (argc < 0) if (argc < 0)
die(_("Bad branch.%s.mergeoptions string: %s"), branch, die(_("Bad branch.%s.mergeoptions string: %s"), branch,
split_cmdline_strerror(argc)); split_cmdline_strerror(argc));
argv = xrealloc(argv, sizeof(*argv) * (argc + 2)); argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
memmove(argv + 1, argv, sizeof(*argv) * (argc + 1)); memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
argc++; argc++;
argv[0] = "branch.*.mergeoptions";
parse_options(argc, argv, NULL, builtin_merge_options, parse_options(argc, argv, NULL, builtin_merge_options,
builtin_merge_usage, 0); builtin_merge_usage, 0);
free(buf); free(argv);
}
static int git_merge_config(const char *k, const char *v, void *cb)
{
if (branch && !prefixcmp(k, "branch.") &&
!prefixcmp(k + 7, branch) &&
!strcmp(k + 7 + strlen(branch), ".mergeoptions")) {
free(branch_mergeoptions);
branch_mergeoptions = xstrdup(v);
return 0;
} }
if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
@ -1010,6 +1019,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (diff_use_color_default == -1) if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default; diff_use_color_default = git_use_color_default;
if (branch_mergeoptions)
parse_branch_merge_options(branch_mergeoptions);
argc = parse_options(argc, argv, prefix, builtin_merge_options, argc = parse_options(argc, argv, prefix, builtin_merge_options,
builtin_merge_usage, 0); builtin_merge_usage, 0);

View File

@ -323,6 +323,38 @@ test_expect_success 'merge c1 with c2 (no-commit in config)' '
test_debug 'git log --graph --decorate --oneline --all' test_debug 'git log --graph --decorate --oneline --all'
test_expect_success 'merge c1 with c2 (log in config)' '
git config branch.master.mergeoptions "" &&
git reset --hard c1 &&
git merge --log c2 &&
git show -s --pretty=tformat:%s%n%b >expect &&
git config branch.master.mergeoptions --log &&
git reset --hard c1 &&
git merge c2 &&
git show -s --pretty=tformat:%s%n%b >actual &&
test_cmp expect actual
'
test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
(
git config --remove-section branch.master
git config --remove-section merge
)
git reset --hard c1 &&
git merge c2 &&
git show -s --pretty=tformat:%s%n%b >expect &&
git config branch.master.mergeoptions "--no-log" &&
git config merge.log true &&
git reset --hard c1 &&
git merge c2 &&
git show -s --pretty=tformat:%s%n%b >actual &&
test_cmp expect actual
'
test_expect_success 'merge c1 with c2 (squash in config)' ' test_expect_success 'merge c1 with c2 (squash in config)' '
git reset --hard c1 && git reset --hard c1 &&
git config branch.master.mergeoptions "--squash" && git config branch.master.mergeoptions "--squash" &&