Merge branch 'jc/maint-branch-mergeoptions'
authorJunio C Hamano <gitster@pobox.com>
Wed, 11 May 2011 18:38:36 +0000 (11:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 May 2011 18:38:36 +0000 (11:38 -0700)
* jc/maint-branch-mergeoptions:
  merge: make branch.<name>.mergeoptions correctly override merge.<option>

Conflicts:
builtin/merge.c

1  2 
builtin/merge.c
t/t7600-merge.sh

diff --cc builtin/merge.c
index d171c63c52160f082bbc04c90ffebc9545090357,b0d3c09bf90a6714119e349d2a5e328f9cdf20e7..9661c8f425b82866552d435413928c60d59cb9ad
@@@ -56,12 -54,9 +56,13 @@@ static size_t use_strategies_nr, use_st
  static const char **xopts;
  static size_t xopts_nr, xopts_alloc;
  static const char *branch;
+ static char *branch_mergeoptions;
 +static int option_renormalize;
  static int verbosity;
  static int allow_rerere_auto;
 +static int abort_current_merge;
 +static int show_progress = -1;
 +static int default_to_upstream;
  
  static struct strategy all_strategy[] = {
        { "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
@@@ -503,6 -475,25 +504,26 @@@ cleanup
        strbuf_release(&bname);
  }
  
 -              die("Bad branch.%s.mergeoptions string", branch);
+ static void parse_branch_merge_options(char *bmo)
+ {
+       const char **argv;
+       int argc;
+       if (!bmo)
+               return;
+       argc = split_cmdline(bmo, &argv);
+       if (argc < 0)
++              die(_("Bad branch.%s.mergeoptions string: %s"), branch,
++                  split_cmdline_strerror(argc));
+       argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
+       memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
+       argc++;
+       argv[0] = "branch.*.mergeoptions";
+       parse_options(argc, argv, NULL, builtin_merge_options,
+                     builtin_merge_usage, 0);
+       free(argv);
+ }
  static int git_merge_config(const char *k, const char *v, void *cb)
  {
        if (branch && !prefixcmp(k, "branch.") &&
@@@ -1010,46 -927,10 +1019,48 @@@ int cmd_merge(int argc, const char **ar
        if (diff_use_color_default == -1)
                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,
                        builtin_merge_usage, 0);
 +
 +      if (verbosity < 0 && show_progress == -1)
 +              show_progress = 0;
 +
 +      if (abort_current_merge) {
 +              int nargc = 2;
 +              const char *nargv[] = {"reset", "--merge", NULL};
 +
 +              if (!file_exists(git_path("MERGE_HEAD")))
 +                      die(_("There is no merge to abort (MERGE_HEAD missing)."));
 +
 +              /* Invoke 'git reset --merge' */
 +              return cmd_reset(nargc, nargv, prefix);
 +      }
 +
 +      if (read_cache_unmerged())
 +              die_resolve_conflict("merge");
 +
 +      if (file_exists(git_path("MERGE_HEAD"))) {
 +              /*
 +               * There is no unmerged entry, don't advise 'git
 +               * add/rm <file>', just 'git commit'.
 +               */
 +              if (advice_resolve_conflict)
 +                      die(_("You have not concluded your merge (MERGE_HEAD exists).\n"
 +                                "Please, commit your changes before you can merge."));
 +              else
 +                      die(_("You have not concluded your merge (MERGE_HEAD exists)."));
 +      }
 +      if (file_exists(git_path("CHERRY_PICK_HEAD"))) {
 +              if (advice_resolve_conflict)
 +                      die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
 +                          "Please, commit your changes before you can merge."));
 +              else
 +                      die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)."));
 +      }
 +      resolve_undo_clear();
 +
        if (verbosity < 0)
                show_diffstat = 0;
  
index b7cac228fd610652aba1bcba08bcf15f03c9d714,56c653d020be7c6096a6683bf67812dce8169b15..a07caa8eaec1cd148f68d7190880fbe537a14162
@@@ -321,8 -370,40 +321,40 @@@ test_expect_success 'merge c1 with c2 (
        verify_mergeheads $c2
  '
  
 -test_debug 'gitk --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)' '
        git reset --hard c1 &&
        git config branch.master.mergeoptions "--squash" &&