Merge branch 'nd/checkout-noisy-unmerge'
authorJunio C Hamano <gitster@pobox.com>
Sat, 9 Feb 2019 04:44:51 +0000 (20:44 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 9 Feb 2019 04:44:51 +0000 (20:44 -0800)
"git checkout [<tree-ish>] <pathspec>" started reporting the number
of paths that have got updated recently, but the same messages were
given when "git checkout -m <pathspec>" to unresolve conflicts that
have just been resolved. The message now reports these unresolved
paths separately from the paths that are checked out from the index.

* nd/checkout-noisy-unmerge:
checkout: count and print -m paths separately
checkout: update count-checkouts messages

1  2 
builtin/checkout.c
diff --combined builtin/checkout.c
index ece4eb14bf1e92742b9fc0723a150e595883d8c6,12e9d7d1e4815093e65505176b7f89e15260baa2..24b8593b938b67baf4a662f2463efdd35562873a
@@@ -1,4 -1,3 +1,4 @@@
 +#define USE_THE_INDEX_COMPATIBILITY_MACROS
  #include "builtin.h"
  #include "config.h"
  #include "checkout.h"
@@@ -117,8 -116,7 +117,8 @@@ static int update_some(const struct obj
  
  static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
  {
 -      read_tree_recursive(tree, "", 0, 0, pathspec, update_some, NULL);
 +      read_tree_recursive(the_repository, tree, "", 0, 0,
 +                          pathspec, update_some, NULL);
  
        /* update the index with the given tree's info
         * for all args, expanding wildcards, and exit
@@@ -261,7 -259,7 +261,7 @@@ static int checkout_paths(const struct 
        struct commit *head;
        int errs = 0;
        struct lock_file lock_file = LOCK_INIT;
-       int nr_checkouts = 0;
+       int nr_checkouts = 0, nr_unmerged = 0;
  
        if (opts->track != BRANCH_TRACK_UNSPECIFIED)
                die(_("'%s' cannot be used with updating paths"), "--track");
                return run_add_interactive(revision, "--patch=checkout",
                                           &opts->pathspec);
  
 -      hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
 +      repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
        if (read_cache_preload(&opts->pathspec) < 0)
                return error(_("index file corrupt"));
  
                                                       &state, &nr_checkouts);
                        else if (opts->merge)
                                errs |= checkout_merged(pos, &state,
-                                                       &nr_checkouts);
+                                                       &nr_unmerged);
                        pos = skip_same_name(ce, pos) - 1;
                }
        }
        errs |= finish_delayed_checkout(&state, &nr_checkouts);
  
        if (opts->count_checkout_paths) {
+               if (nr_unmerged)
+                       fprintf_ln(stderr, Q_("Recreated %d merge conflict",
+                                             "Recreated %d merge conflicts",
+                                             nr_unmerged),
+                                  nr_unmerged);
                if (opts->source_tree)
-                       fprintf_ln(stderr, Q_("Checked out %d path out of %s",
-                                             "Checked out %d paths out of %s",
+                       fprintf_ln(stderr, Q_("Updated %d path from %s",
+                                             "Updated %d paths from %s",
                                              nr_checkouts),
                                   nr_checkouts,
                                   find_unique_abbrev(&opts->source_tree->object.oid,
                                                      DEFAULT_ABBREV));
-               else
-                       fprintf_ln(stderr, Q_("Checked out %d path out of the index",
-                                             "Checked out %d paths out of the index",
+               else if (!nr_unmerged || nr_checkouts)
+                       fprintf_ln(stderr, Q_("Updated %d path from the index",
+                                             "Updated %d paths from the index",
                                              nr_checkouts),
                                   nr_checkouts);
        }
@@@ -593,14 -596,6 +598,14 @@@ static int skip_merge_working_tree(cons
         * Remaining variables are not checkout options but used to track state
         */
  
 +       /*
 +        * Do the merge if this is the initial checkout. We cannot use
 +        * is_cache_unborn() here because the index hasn't been loaded yet
 +        * so cache_nr and timestamp.sec are always zero.
 +        */
 +      if (!file_exists(get_index_file()))
 +              return 0;
 +
        return 1;
  }
  
@@@ -702,7 -697,7 +707,7 @@@ static int merge_working_tree(const str
                         * a pain; plumb in an option to set
                         * o.renormalize?
                         */
 -                      init_merge_options(&o);
 +                      init_merge_options(&o, the_repository);
                        o.verbosity = 0;
                        work = write_tree_from_memory(&o);
  
@@@ -785,8 -780,7 +790,8 @@@ static void update_refs_for_switch(cons
                        free(refname);
                }
                else
 -                      create_branch(opts->new_branch, new_branch_info->name,
 +                      create_branch(the_repository,
 +                                    opts->new_branch, new_branch_info->name,
                                      opts->new_branch_force ? 1 : 0,
                                      opts->new_branch_force ? 1 : 0,
                                      opts->new_branch_log,
                                delete_reflog(old_branch_info->path);
                }
        }
 -      remove_branch_state();
 +      remove_branch_state(the_repository);
        strbuf_release(&msg);
        if (!opts->quiet &&
            (new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, "HEAD"))))
@@@ -1113,12 -1107,9 +1118,12 @@@ static int parse_branchname_arg(int arg
                 */
                int recover_with_dwim = dwim_new_local_branch_ok;
  
 -              if (!has_dash_dash &&
 -                  (check_filename(opts->prefix, arg) || !no_wildcard(arg)))
 +              int could_be_checkout_paths = !has_dash_dash &&
 +                      check_filename(opts->prefix, arg);
 +
 +              if (!has_dash_dash && !no_wildcard(arg))
                        recover_with_dwim = 0;
 +
                /*
                 * Accept "git checkout foo" and "git checkout foo --"
                 * as candidates for dwim.
                        const char *remote = unique_tracking_name(arg, rev,
                                                                  dwim_remotes_matched);
                        if (remote) {
 +                              if (could_be_checkout_paths)
 +                                      die(_("'%s' could be both a local file and a tracking branch.\n"
 +                                            "Please use -- (and optionally --no-guess) to disambiguate"),
 +                                          arg);
                                *new_branch = arg;
                                arg = remote;
                                /* DWIMmed to create local branch, case (3).(b) */
@@@ -1269,7 -1256,7 +1274,7 @@@ int cmd_checkout(int argc, const char *
        struct checkout_opts opts;
        struct branch_info new_branch_info;
        char *conflict_style = NULL;
 -      int dwim_new_local_branch = 1;
 +      int dwim_new_local_branch, no_dwim_new_local_branch = 0;
        int dwim_remotes_matched = 0;
        struct option options[] = {
                OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),
                OPT_BOOL('p', "patch", &opts.patch_mode, N_("select hunks interactively")),
                OPT_BOOL(0, "ignore-skip-worktree-bits", &opts.ignore_skipworktree,
                         N_("do not limit pathspecs to sparse entries only")),
 -              OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch,
 -                              N_("second guess 'git checkout <no-such-branch>'")),
 +              OPT_BOOL(0, "no-guess", &no_dwim_new_local_branch,
 +                       N_("do not second guess 'git checkout <no-such-branch>'")),
                OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
                         N_("do not check if another worktree is holding the given ref")),
                { OPTION_CALLBACK, 0, "recurse-submodules", NULL,
        argc = parse_options(argc, argv, prefix, options, checkout_usage,
                             PARSE_OPT_KEEP_DASHDASH);
  
 +      dwim_new_local_branch = !no_dwim_new_local_branch;
        if (opts.show_progress < 0) {
                if (opts.quiet)
                        opts.show_progress = 0;