From: Junio C Hamano Date: Sat, 9 Feb 2019 04:44:51 +0000 (-0800) Subject: Merge branch 'nd/checkout-noisy-unmerge' X-Git-Tag: v2.21.0-rc1~23 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/87c9831df0f5ae4e96ab2e5b9b5b50505baa8cf4?ds=inline;hp=-c Merge branch 'nd/checkout-noisy-unmerge' "git checkout [] " started reporting the number of paths that have got updated recently, but the same messages were given when "git checkout -m " 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 --- 87c9831df0f5ae4e96ab2e5b9b5b50505baa8cf4 diff --combined builtin/checkout.c index ece4eb14bf,12e9d7d1e4..24b8593b93 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -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"); @@@ -289,7 -287,7 +289,7 @@@ 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")); @@@ -386,23 -384,28 +386,28 @@@ &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, @@@ -844,7 -838,7 +849,7 @@@ 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. @@@ -1131,10 -1122,6 +1136,10 @@@ 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")), @@@ -1299,8 -1286,8 +1304,8 @@@ 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 '")), + OPT_BOOL(0, "no-guess", &no_dwim_new_local_branch, + N_("do not second guess 'git checkout '")), 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, @@@ -1323,7 -1310,6 +1328,7 @@@ 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;