Merge branch 'mm/maint-merge-ff-error-message-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 9 Dec 2009 06:42:23 +0000 (22:42 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 9 Dec 2009 06:42:23 +0000 (22:42 -0800)
* mm/maint-merge-ff-error-message-fix:
builtin-merge: show user-friendly error messages for fast-forward too.
merge-recursive: make the error-message generation an extern function

Conflicts:
merge-recursive.c

1  2 
builtin-merge.c
merge-recursive.c
diff --combined builtin-merge.c
index d3eb5092c8b20b157fe7c2560d293d6a232a37fd,56ecc682399b8bf80e29fadf86e057139b9ff0f4..921453949a1bdccd796b43f29137f419b6416baf
@@@ -70,7 -70,7 +70,7 @@@ static int option_parse_message(const s
        if (unset)
                strbuf_setlen(buf, 0);
        else if (arg) {
 -              strbuf_addf(buf, "%s\n\n", arg);
 +              strbuf_addf(buf, "%s%s", buf->len ? "\n\n" : "", arg);
                have_message = 1;
        } else
                return error("switch `m' requires a value");
@@@ -106,8 -106,8 +106,8 @@@ static struct strategy *get_strategy(co
                                        found = 1;
                        if (!found)
                                add_cmdname(&not_strategies, ent->name, ent->len);
 -                      exclude_cmds(&main_cmds, &not_strategies);
                }
 +              exclude_cmds(&main_cmds, &not_strategies);
        }
        if (!is_in_cmdlist(&main_cmds, name) && !is_in_cmdlist(&other_cmds, name)) {
                fprintf(stderr, "Could not find merge strategy '%s'.\n", name);
@@@ -650,6 -650,7 +650,7 @@@ static int checkout_fast_forward(unsign
        opts.verbose_update = 1;
        opts.merge = 1;
        opts.fn = twoway_merge;
+       opts.msgs = get_porcelain_error_msgs();
  
        trees[nr_trees] = parse_tree_indirect(head);
        if (!trees[nr_trees++])
@@@ -792,7 -793,7 +793,7 @@@ static int suggest_conflicts(void
  static struct commit *is_old_style_invocation(int argc, const char **argv)
  {
        struct commit *second_token = NULL;
 -      if (argc > 1) {
 +      if (argc > 2) {
                unsigned char second_sha1[20];
  
                if (get_sha1(argv[1], second_sha1))
@@@ -840,6 -841,7 +841,6 @@@ int cmd_merge(int argc, const char **ar
        const char *best_strategy = NULL, *wt_strategy = NULL;
        struct commit_list **remotes = &remoteheads;
  
 -      setup_work_tree();
        if (file_exists(git_path("MERGE_HEAD")))
                die("You have not concluded your merge. (MERGE_HEAD exists)");
        if (read_cache_unmerged())
                 * codepath so we discard the error in this
                 * loop.
                 */
 -              for (i = 0; i < argc; i++)
 -                      merge_name(argv[i], &msg);
 -              fmt_merge_msg(option_log, &msg, &merge_msg);
 -              if (merge_msg.len)
 -                      strbuf_setlen(&merge_msg, merge_msg.len-1);
 +              if (!have_message) {
 +                      for (i = 0; i < argc; i++)
 +                              merge_name(argv[i], &msg);
 +                      fmt_merge_msg(option_log, &msg, &merge_msg);
 +                      if (merge_msg.len)
 +                              strbuf_setlen(&merge_msg, merge_msg.len-1);
 +              }
        }
  
        if (head_invalid || !argc)
diff --combined merge-recursive.c
index 1870448d98d56fea31af56953dc33f6529d1d380,72bfbaf43a26a00aab901c5f30fe76b1a788e3ba..cd3628c4d9b1831c73e752b3b49c9d88b9e23098
@@@ -3,7 -3,6 +3,7 @@@
   * Fredrik Kuivinen.
   * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
   */
 +#include "advice.h"
  #include "cache.h"
  #include "cache-tree.h"
  #include "commit.h"
@@@ -171,23 -170,6 +171,6 @@@ static int git_merge_trees(int index_on
        int rc;
        struct tree_desc t[3];
        struct unpack_trees_options opts;
-       struct unpack_trees_error_msgs msgs = {
-               /* would_overwrite */
-               "Your local changes to '%s' would be overwritten by merge.  Aborting.",
-               /* not_uptodate_file */
-               "Your local changes to '%s' would be overwritten by merge.  Aborting.",
-               /* not_uptodate_dir */
-               "Updating '%s' would lose untracked files in it.  Aborting.",
-               /* would_lose_untracked */
-               "Untracked working tree file '%s' would be %s by merge.  Aborting",
-               /* bind_overlap -- will not happen here */
-               NULL,
-       };
-       if (advice_commit_before_merge) {
-               msgs.would_overwrite = msgs.not_uptodate_file =
-                       "Your local changes to '%s' would be overwritten by merge.  Aborting.\n"
-                       "Please, commit your changes or stash them before you can merge.";
-       }
  
        memset(&opts, 0, sizeof(opts));
        if (index_only)
        opts.fn = threeway_merge;
        opts.src_index = &the_index;
        opts.dst_index = &the_index;
-       opts.msgs = msgs;
+       opts.msgs = get_porcelain_error_msgs();
  
        init_tree_desc_from_tree(t+0, common);
        init_tree_desc_from_tree(t+1, head);
@@@ -1186,6 -1168,23 +1169,28 @@@ static int process_entry(struct merge_o
        return clean_merge;
  }
  
+ struct unpack_trees_error_msgs get_porcelain_error_msgs(void)
+ {
+       struct unpack_trees_error_msgs msgs = {
+               /* would_overwrite */
+               "Your local changes to '%s' would be overwritten by merge.  Aborting.",
+               /* not_uptodate_file */
+               "Your local changes to '%s' would be overwritten by merge.  Aborting.",
+               /* not_uptodate_dir */
+               "Updating '%s' would lose untracked files in it.  Aborting.",
+               /* would_lose_untracked */
+               "Untracked working tree file '%s' would be %s by merge.  Aborting",
+               /* bind_overlap -- will not happen here */
+               NULL,
+       };
++      if (advice_commit_before_merge) {
++              msgs.would_overwrite = msgs.not_uptodate_file =
++                      "Your local changes to '%s' would be overwritten by merge.  Aborting.\n"
++                      "Please, commit your changes or stash them before you can merge.";
++      }
+       return msgs;
+ }
  int merge_trees(struct merge_options *o,
                struct tree *head,
                struct tree *merge,