X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin%2Fread-tree.c;h=eb1e3e7467ac722f4b6cc1da03f7671d21abc676;hb=a2f509e1d8d8103a719fd6784e859c0af8c1adf5;hp=8bdcab11389e8b4facab355f27f0e1926134b86f;hpb=56bfacef7966553530532d58c07787754add2465;p=git.git diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 8bdcab113..eb1e3e746 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -16,6 +16,7 @@ #include "resolve-undo.h" static int nr_trees; +static int read_empty; static struct tree *trees[MAX_UNPACK_TREES]; static int list_tree(unsigned char *sha1) @@ -32,7 +33,7 @@ static int list_tree(unsigned char *sha1) } static const char * const read_tree_usage[] = { - "git read-tree [[-m [--trivial] [--aggressive] | --reset | --prefix=] [-u [--exclude-per-directory=] | -i]] [--no-sparse-checkout] [--index-output=] [ []]", + "git read-tree [[-m [--trivial] [--aggressive] | --reset | --prefix=] [-u [--exclude-per-directory=] | -i]] [--no-sparse-checkout] [--index-output=] (--empty | [ []])", NULL }; @@ -106,6 +107,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix) { OPTION_CALLBACK, 0, "index-output", NULL, "FILE", "write resulting index to ", PARSE_OPT_NONEG, index_output_cb }, + OPT_SET_INT(0, "empty", &read_empty, + "only empty the index", 1), OPT__VERBOSE(&opts.verbose_update), OPT_GROUP("Merging"), OPT_SET_INT('m', NULL, &opts.merge, @@ -166,6 +169,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix) die("failed to unpack tree object %s", arg); stage++; } + if (nr_trees == 0 && !read_empty) + warning("read-tree: emptying the index with no arguments is deprecated; use --empty"); + else if (nr_trees > 0 && read_empty) + die("passing trees as arguments contradicts --empty"); + if (1 < opts.index_only + opts.update) die("-u and -i at the same time makes no sense"); if ((opts.update||opts.index_only) && !opts.merge) @@ -219,14 +227,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix) * "-m ent" or "--reset ent" form), we can obtain a fully * valid cache-tree because the index must match exactly * what came from the tree. - * - * The same holds true if we are switching between two trees - * using read-tree -m A B. The index must match B after that. */ if (nr_trees == 1 && !opts.prefix) prime_cache_tree(&active_cache_tree, trees[0]); - else if (nr_trees == 2 && opts.merge) - prime_cache_tree(&active_cache_tree, trees[1]); if (write_cache(newfd, active_cache, active_nr) || commit_locked_index(&lock_file))