]> rtime.felk.cvut.cz Git - git.git/commitdiff
Merge branch 'mm/maint-merge-ff-error-message-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 30 Nov 2009 22:45:08 +0000 (14:45 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Nov 2009 22:45:08 +0000 (14:45 -0800)
Conflicts:
merge-recursive.c

1  2 
builtin-merge.c
merge-recursive.c

diff --combined builtin-merge.c
index 855cf6545eaca06260a7e0868425140850a590d8,56ecc682399b8bf80e29fadf86e057139b9ff0f4..fc7066e3c7053ba697c705f983f8dc7dac19963b
@@@ -43,7 -43,6 +43,7 @@@ static const char * const builtin_merge
  
  static int show_diffstat = 1, option_log, squash;
  static int option_commit = 1, allow_fast_forward = 1;
 +static int fast_forward_only;
  static int allow_trivial = 1, have_message;
  static struct strbuf merge_msg;
  static struct commit_list *remoteheads;
@@@ -107,8 -106,8 +107,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);
@@@ -167,9 -166,7 +167,9 @@@ static struct option builtin_merge_opti
        OPT_BOOLEAN(0, "commit", &option_commit,
                "perform a commit if the merge succeeds (default)"),
        OPT_BOOLEAN(0, "ff", &allow_fast_forward,
 -              "allow fast forward (default)"),
 +              "allow fast-forward (default)"),
 +      OPT_BOOLEAN(0, "ff-only", &fast_forward_only,
 +              "abort if fast-forward is not possible"),
        OPT_CALLBACK('s', "strategy", &use_strategies, "strategy",
                "merge strategy to use", option_parse_strategy),
        OPT_CALLBACK('m', "message", &merge_msg, "message",
@@@ -267,7 -264,6 +267,7 @@@ static void squash_message(void
        struct strbuf out = STRBUF_INIT;
        struct commit_list *j;
        int fd;
 +      struct pretty_print_context ctx = {0};
  
        printf("Squash commit -- not updating HEAD\n");
        fd = open(git_path("SQUASH_MSG"), O_WRONLY | O_CREAT, 0666);
        if (prepare_revision_walk(&rev))
                die("revision walk setup failed");
  
 +      ctx.abbrev = rev.abbrev;
 +      ctx.date_mode = rev.date_mode;
 +
        strbuf_addstr(&out, "Squashed commit of the following:\n");
        while ((commit = get_revision(&rev)) != NULL) {
                strbuf_addch(&out, '\n');
                strbuf_addf(&out, "commit %s\n",
                        sha1_to_hex(commit->object.sha1));
 -              pretty_print_commit(rev.commit_format, commit, &out, rev.abbrev,
 -                      NULL, NULL, rev.date_mode, 0);
 +              pretty_print_commit(rev.commit_format, commit, &out, &ctx);
        }
        if (write(fd, out.buf, out.len) < 0)
                die_errno("Writing SQUASH_MSG");
@@@ -656,6 -650,7 +656,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++])
@@@ -846,6 -841,7 +847,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())
                option_commit = 0;
        }
  
 +      if (!allow_fast_forward && fast_forward_only)
 +              die("You cannot combine --no-ff with --ff-only.");
 +
        if (!argc)
                usage_with_options(builtin_merge_usage,
                        builtin_merge_options);
                                hex,
                                find_unique_abbrev(remoteheads->item->object.sha1,
                                DEFAULT_ABBREV));
 -              strbuf_addstr(&msg, "Fast forward");
 +              strbuf_addstr(&msg, "Fast-forward");
                if (have_message)
                        strbuf_addstr(&msg,
                                " (no commit created; -m option ignored)");
        } else if (!remoteheads->next && common->next)
                ;
                /*
 -               * We are not doing octopus and not fast forward.  Need
 +               * We are not doing octopus and not fast-forward.  Need
                 * a real merge.
                 */
        else if (!remoteheads->next && !common->next && option_commit) {
                /*
 -               * We are not doing octopus, not fast forward, and have
 +               * We are not doing octopus, not fast-forward, and have
                 * only one common.
                 */
                refresh_cache(REFRESH_QUIET);
 -              if (allow_trivial) {
 +              if (allow_trivial && !fast_forward_only) {
                        /* See if it is really trivial. */
                        git_committer_info(IDENT_ERROR_ON_NO_NAME);
                        printf("Trying really trivial in-index merge...\n");
                }
        }
  
 +      if (fast_forward_only)
 +              die("Not possible to fast-forward, aborting.");
 +
        /* We are going to make a new commit. */
        git_committer_info(IDENT_ERROR_ON_NO_NAME);
  
diff --combined merge-recursive.c
index a91208f295d00d73b8fc0f5cd6a92ac422d9eeb4,72bfbaf43a26a00aab901c5f30fe76b1a788e3ba..dd4fbd0e6bc22f2e5f5667205b47165f8aebbbd0
@@@ -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"
@@@ -87,7 -86,6 +87,7 @@@ static void flush_output(struct merge_o
        }
  }
  
 +__attribute__((format (printf, 3, 4)))
  static void output(struct merge_options *o, int v, const char *fmt, ...)
  {
        int len;
@@@ -172,23 -170,6 +172,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);
@@@ -221,8 -202,7 +204,8 @@@ struct tree *write_tree_from_memory(str
                for (i = 0; i < active_nr; i++) {
                        struct cache_entry *ce = active_cache[i];
                        if (ce_stage(ce))
 -                              output(o, 0, "%d %.*s", ce_stage(ce), ce_namelen(ce), ce->name);
 +                              output(o, 0, "%d %.*s", ce_stage(ce),
 +                                     (int)ce_namelen(ce), ce->name);
                }
                return NULL;
        }
@@@ -1188,6 -1168,23 +1171,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,