read-tree: deprecate syntax without tree-ish args
Currently, read-tree can be run without tree-ish arguments, in which case it will empty the index. Since this behavior is undocumented and perhaps a bit too invasive to be the "default" action for read-tree, deprecate it in favor of a new --empty option that does the same thing. Signed-off-by: Jan Krüger <jk@jk.gs> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jan Krüger committed
Sep 10, 2010 at 15:28 UTC
fb1bb96516d4bc985393c0bfb8bb7a6d6ce95045
2 files changed
+14
-2
Documentation/git-read-tree.txt
+5
-1
@@ -11,7 +11,7 @@ SYNOPSIS
11
'git read-tree' [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>]
12
[-u [--exclude-per-directory=<gitignore>] | -i]]
13
[--index-output=<file>] [--no-sparse-checkout]
14
- <tree-ish1> [<tree-ish2> [<tree-ish3>]]
14
+ (--empty | <tree-ish1> [<tree-ish2> [<tree-ish3>]])
15
16
17
DESCRIPTION
@@ -114,6 +114,10 @@ OPTIONS
114
Disable sparse checkout support even if `core.sparseCheckout`
115
is true.
116
117
+--empty::
118
+ Instead of reading tree object(s) into the index, just empty
119
+ it.
120
+
121
<tree-ish#>::
122
The id of the tree object(s) to be read/merged.
123
builtin/read-tree.c
+9
-1
@@ -16,6 +16,7 @@
16
#include "resolve-undo.h"
17
18
static int nr_trees;
19
+static int read_empty;
20
static struct tree *trees[MAX_UNPACK_TREES];
21
22
static int list_tree(unsigned char *sha1)
@@ -32,7 +33,7 @@ static int list_tree(unsigned char *sha1)
33
}
34
35
static const char * const read_tree_usage[] = {
35
- "git read-tree [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u [--exclude-per-directory=<gitignore>] | -i]] [--no-sparse-checkout] [--index-output=<file>] <tree-ish1> [<tree-ish2> [<tree-ish3>]]",
36
+ "git read-tree [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u [--exclude-per-directory=<gitignore>] | -i]] [--no-sparse-checkout] [--index-output=<file>] (--empty | <tree-ish1> [<tree-ish2> [<tree-ish3>]])",
37
NULL
38
};
39
@@ -106,6 +107,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
107
{ OPTION_CALLBACK, 0, "index-output", NULL, "FILE",
108
"write resulting index to <FILE>",
109
PARSE_OPT_NONEG, index_output_cb },
110
+ OPT_SET_INT(0, "empty", &read_empty,
111
+ "only empty the index", 1),
112
OPT__VERBOSE(&opts.verbose_update),
113
OPT_GROUP("Merging"),
114
OPT_SET_INT('m', NULL, &opts.merge,
@@ -166,6 +169,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
169
die("failed to unpack tree object %s", arg);
170
stage++;
171
}
172
+ if (nr_trees == 0 && !read_empty)
173
+ warning("read-tree: emptying the index with no arguments is deprecated; use --empty");
174
+ else if (nr_trees > 0 && read_empty)
175
+ die("passing trees as arguments contradicts --empty");
176
+
177
if (1 < opts.index_only + opts.update)
178
die("-u and -i at the same time makes no sense");
179
if ((opts.update||opts.index_only) && !opts.merge)