From: Junio C Hamano Date: Mon, 30 Sep 2019 04:19:27 +0000 (+0900) Subject: Merge branch 'nd/switch-and-restore' X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/3ff6af7753287f2cac8261ae5184c3381373b836?ds=inline;hp=-c Merge branch 'nd/switch-and-restore' Resurrect a performance hack. * nd/switch-and-restore: checkout: add simple check for 'git checkout -b' --- 3ff6af7753287f2cac8261ae5184c3381373b836 diff --combined builtin/checkout.c index 0a3679eb77,2bca5fe492..1283727761 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -126,7 -126,6 +126,7 @@@ static int update_some(const struct obj if (pos >= 0) { struct cache_entry *old = active_cache[pos]; if (ce->ce_mode == old->ce_mode && + !ce_intent_to_add(old) && oideq(&ce->oid, &old->oid)) { old->ce_flags |= CE_UPDATE; discard_cache_entry(ce); @@@ -486,7 -485,7 +486,7 @@@ static int checkout_paths(const struct ps_matched, opts); - if (report_path_error(ps_matched, &opts->pathspec, opts->prefix)) { + if (report_path_error(ps_matched, &opts->pathspec)) { free(ps_matched); return 1; } @@@ -685,7 -684,7 +685,7 @@@ static int merge_working_tree(const str topts.initial_checkout = is_cache_unborn(); topts.update = 1; topts.merge = 1; - topts.gently = opts->merge && old_branch_info->commit; + topts.quiet = opts->merge && old_branch_info->commit; topts.verbose_update = opts->show_progress; topts.fn = twoway_merge; if (opts->overwrite_ignore) { @@@ -711,10 -710,7 +711,10 @@@ */ struct tree *result; struct tree *work; + struct tree *old_tree; struct merge_options o; + struct strbuf sb = STRBUF_INIT; + if (!opts->merge) return 1; @@@ -724,12 -720,6 +724,12 @@@ */ if (!old_branch_info->commit) return 1; + old_tree = get_commit_tree(old_branch_info->commit); + + if (repo_index_has_changes(the_repository, old_tree, &sb)) + die(_("cannot continue with staged changes in " + "the following files:\n%s"), sb.buf); + strbuf_release(&sb); /* Do more real merge */ @@@ -767,7 -757,7 +767,7 @@@ ret = merge_trees(&o, new_tree, work, - get_commit_tree(old_branch_info->commit), + old_tree, &result); if (ret < 0) exit(128); @@@ -1708,6 -1698,15 +1708,15 @@@ int cmd_checkout(int argc, const char * opts.checkout_index = -2; /* default on */ opts.checkout_worktree = -2; /* default on */ + if (argc == 3 && !strcmp(argv[1], "-b")) { + /* + * User ran 'git checkout -b ' and expects + * the same behavior as 'git switch -c '. + */ + opts.switch_branch_doing_nothing_is_ok = 0; + opts.only_merge_on_switching_branches = 1; + } + options = parse_options_dup(checkout_options); options = add_common_options(&opts, options); options = add_common_switch_branch_options(&opts, options); @@@ -1763,7 -1762,7 +1772,7 @@@ int cmd_restore(int argc, const char ** struct option *options; struct option restore_options[] = { OPT_STRING('s', "source", &opts.from_treeish, "", - N_("where the checkout from")), + N_("which tree-ish to checkout from")), OPT_BOOL('S', "staged", &opts.checkout_index, N_("restore the index")), OPT_BOOL('W', "worktree", &opts.checkout_worktree,