Skip to content

Commit fb1bb96

Browse files
jastgitster
authored andcommitted
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>
1 parent 8ac8cf5 commit fb1bb96

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Documentation/git-read-tree.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SYNOPSIS
1111
'git read-tree' [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>]
1212
[-u [--exclude-per-directory=<gitignore>] | -i]]
1313
[--index-output=<file>] [--no-sparse-checkout]
14-
<tree-ish1> [<tree-ish2> [<tree-ish3>]]
14+
(--empty | <tree-ish1> [<tree-ish2> [<tree-ish3>]])
1515

1616

1717
DESCRIPTION
@@ -114,6 +114,10 @@ OPTIONS
114114
Disable sparse checkout support even if `core.sparseCheckout`
115115
is true.
116116

117+
--empty::
118+
Instead of reading tree object(s) into the index, just empty
119+
it.
120+
117121
<tree-ish#>::
118122
The id of the tree object(s) to be read/merged.
119123

builtin/read-tree.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "resolve-undo.h"
1717

1818
static int nr_trees;
19+
static int read_empty;
1920
static struct tree *trees[MAX_UNPACK_TREES];
2021

2122
static int list_tree(unsigned char *sha1)
@@ -32,7 +33,7 @@ static int list_tree(unsigned char *sha1)
3233
}
3334

3435
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>]])",
3637
NULL
3738
};
3839

@@ -106,6 +107,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
106107
{ OPTION_CALLBACK, 0, "index-output", NULL, "FILE",
107108
"write resulting index to <FILE>",
108109
PARSE_OPT_NONEG, index_output_cb },
110+
OPT_SET_INT(0, "empty", &read_empty,
111+
"only empty the index", 1),
109112
OPT__VERBOSE(&opts.verbose_update),
110113
OPT_GROUP("Merging"),
111114
OPT_SET_INT('m', NULL, &opts.merge,
@@ -166,6 +169,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
166169
die("failed to unpack tree object %s", arg);
167170
stage++;
168171
}
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+
169177
if (1 < opts.index_only + opts.update)
170178
die("-u and -i at the same time makes no sense");
171179
if ((opts.update||opts.index_only) && !opts.merge)

0 commit comments

Comments
 (0)