From: Junio C Hamano Date: Thu, 7 Mar 2019 00:59:51 +0000 (+0900) Subject: Merge branch 'tg/checkout-no-overlay' X-Git-Tag: v2.22.0-rc0~181 X-Git-Url: http://git.bitbasher.net/?a=commitdiff_plain;h=7d0c1f4556ad89b2f7eae97d31ea85c3bfdf7c87;p=git.git Merge branch 'tg/checkout-no-overlay' "git checkout --no-overlay" can be used to trigger a new mode of checking out paths out of the tree-ish, that allows paths that match the pathspec that are in the current index and working tree and are not in the tree-ish. * tg/checkout-no-overlay: revert "checkout: introduce checkout.overlayMode config" checkout: introduce checkout.overlayMode config checkout: introduce --{,no-}overlay option checkout: factor out mark_cache_entry_for_checkout function checkout: clarify comment read-cache: add invalidate parameter to remove_marked_cache_entries entry: support CE_WT_REMOVE flag in checkout_entry entry: factor out unlink_entry function move worktree tests to t24* --- 7d0c1f4556ad89b2f7eae97d31ea85c3bfdf7c87 diff --cc Documentation/git-checkout.txt index 8c3d4128c2,24e52b01e1..f179b43732 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@@ -276,10 -279,13 +279,17 @@@ Note that this option uses the no overl Just like linkgit:git-submodule[1], this will detach the submodules HEAD. +--no-guess:: + Do not attempt to create a branch if a remote tracking branch + of the same name exists. + + --[no-]overlay:: + In the default overlay mode, `git checkout` never + removes files from the index or the working tree. When + specifying `--no-overlay`, files that appear in the index and + working tree, but not in are removed, to make them + match exactly. + :: Branch to checkout; if it refers to a branch (i.e., a name that, when prepended with "refs/heads/", is a valid ref), then that diff --cc builtin/checkout.c index 24b8593b93,0c5fe948ef..bea08ef959 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -45,7 -44,7 +45,8 @@@ struct checkout_opts int ignore_skipworktree; int ignore_other_worktrees; int show_progress; + int count_checkout_paths; + int overlay_mode; /* * If new checkout options are added, skip_merge_working_tree * should be updated accordingly. @@@ -168,15 -169,18 +172,20 @@@ static int check_stages(unsigned stages } static int checkout_stage(int stage, const struct cache_entry *ce, int pos, - const struct checkout *state, int *nr_checkouts) - const struct checkout *state, int overlay_mode) ++ const struct checkout *state, int *nr_checkouts, ++ int overlay_mode) { while (pos < active_nr && !strcmp(active_cache[pos]->name, ce->name)) { if (ce_stage(active_cache[pos]) == stage) - return checkout_entry(active_cache[pos], state, NULL); + return checkout_entry(active_cache[pos], state, + NULL, nr_checkouts); pos++; } + if (!overlay_mode) { + unlink_entry(ce); + return 0; + } if (stage == 2) return error(_("path '%s' does not have our version"), ce->name); else @@@ -381,36 -414,15 +421,39 @@@ static int checkout_paths(const struct continue; } if (opts->writeout_stage) - errs |= checkout_stage(opts->writeout_stage, ce, pos, &state, opts->overlay_mode); + errs |= checkout_stage(opts->writeout_stage, + ce, pos, - &state, &nr_checkouts); ++ &state, ++ &nr_checkouts, opts->overlay_mode); else if (opts->merge) - errs |= checkout_merged(pos, &state); + errs |= checkout_merged(pos, &state, + &nr_unmerged); pos = skip_same_name(ce, pos) - 1; } } + remove_marked_cache_entries(&the_index, 1); + remove_scheduled_dirs(); - errs |= finish_delayed_checkout(&state); + 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_("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 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); + } if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) die(_("unable to write new index file")); diff --cc cache.h index 27fe635f62,1deee48f5b..473fa1eff1 --- a/cache.h +++ b/cache.h @@@ -1566,9 -1539,14 +1566,14 @@@ struct checkout #define CHECKOUT_INIT { NULL, "" } #define TEMPORARY_FILENAME_LENGTH 25 -extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); +extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath, int *nr_checkouts); extern void enable_delayed_checkout(struct checkout *state); -extern int finish_delayed_checkout(struct checkout *state); +extern int finish_delayed_checkout(struct checkout *state, int *nr_checkouts); + /* + * Unlink the last component and schedule the leading directories for + * removal, such that empty directories get removed. + */ + extern void unlink_entry(const struct cache_entry *ce); struct cache_def { struct strbuf path; diff --cc entry.c index 6fd72b30c8,3d3701e7ae..0e4f2f2910 --- a/entry.c +++ b/entry.c @@@ -506,7 -517,20 +517,22 @@@ int checkout_entry(struct cache_entry * return 0; create_directories(path.buf, path.len, state); + if (nr_checkouts) + (*nr_checkouts)++; return write_entry(ce, path.buf, state, 0); } + + void unlink_entry(const struct cache_entry *ce) + { + const struct submodule *sub = submodule_from_ce(ce); + if (sub) { + /* state.force is set at the caller. */ + submodule_move_head(ce->name, "HEAD", NULL, + SUBMODULE_MOVE_HEAD_FORCE); + } + if (!check_leading_path(ce->name, ce_namelen(ce))) + return; + if (remove_or_warn(ce->ce_mode, ce->name)) + return; + schedule_dir_for_removal(ce->name, ce_namelen(ce)); + } diff --cc t/t9902-completion.sh index 3a2c6326d8,5758fffa0d..f5e21bf970 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@@ -1434,9 -1434,9 +1434,10 @@@ test_expect_success 'double dash "git c --ignore-other-worktrees Z --recurse-submodules Z --progress Z - --no-quiet Z + --guess Z + --no-guess Z --no-... Z + --overlay Z EOF '