Skip to content

Commit 897d509

Browse files
committed
reset: reinstate support for the deprecated --stdin option
The `--stdin` option was a well-established paradigm in other commands, therefore we implemented it in `git reset` for use by Visual Studio. Unfortunately, upstream Git decided that it is time to introduce `--pathspec-from-file` instead. To keep backwards-compatibility for some grace period, we therefore reinstate the `--stdin` option on top of the `--pathspec-from-file` option, but mark it firmly as deprecated. Helped-by: Victoria Dye <[email protected]> Helped-by: Matthew John Cheetham <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 5a7542d commit 897d509

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

Documentation/git-reset.txt

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SYNOPSIS
1212
'git reset' [-q] [--pathspec-from-file=<file> [--pathspec-file-nul]] [<tree-ish>]
1313
'git reset' (--patch | -p) [<tree-ish>] [--] [<pathspec>...]
1414
'git reset' [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]
15+
DEPRECATED: 'git reset' [-q] [--stdin [-z]] [<tree-ish>]
1516

1617
DESCRIPTION
1718
-----------
@@ -133,6 +134,16 @@ OPTIONS
133134
+
134135
For more details, see the 'pathspec' entry in linkgit:gitglossary[7].
135136

137+
--stdin::
138+
DEPRECATED (use `--pathspec-from-file=-` instead): Instead of taking
139+
list of paths from the command line, read list of paths from the
140+
standard input. Paths are separated by LF (i.e. one path per line) by
141+
default.
142+
143+
-z::
144+
DEPRECATED (use `--pathspec-file-nul` instead): Only meaningful with
145+
`--stdin`; paths are separated with NUL character instead of LF.
146+
136147
EXAMPLES
137148
--------
138149

builtin/reset.c

+16
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "trace2.h"
3636
#include "dir.h"
3737
#include "add-interactive.h"
38+
#include "strbuf.h"
39+
#include "quote.h"
3840

3941
#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
4042

@@ -43,6 +45,7 @@ static const char * const git_reset_usage[] = {
4345
N_("git reset [-q] [<tree-ish>] [--] <pathspec>..."),
4446
N_("git reset [-q] [--pathspec-from-file [--pathspec-file-nul]] [<tree-ish>]"),
4547
N_("git reset --patch [<tree-ish>] [--] [<pathspec>...]"),
48+
N_("DEPRECATED: git reset [-q] [--stdin [-z]] [<tree-ish>]"),
4649
NULL
4750
};
4851

@@ -331,6 +334,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
331334
struct object_id oid;
332335
struct pathspec pathspec;
333336
int intent_to_add = 0;
337+
int nul_term_line = 0, read_from_stdin = 0;
334338
const struct option options[] = {
335339
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
336340
OPT_BOOL(0, "no-refresh", &no_refresh,
@@ -359,6 +363,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
359363
N_("record only the fact that removed paths will be added later")),
360364
OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
361365
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
366+
OPT_BOOL('z', NULL, &nul_term_line,
367+
N_("DEPRECATED (use --pathspec-file-nul instead): paths are separated with NUL character")),
368+
OPT_BOOL(0, "stdin", &read_from_stdin,
369+
N_("DEPRECATED (use --pathspec-from-file=- instead): read paths from <stdin>")),
362370
OPT_END()
363371
};
364372

@@ -368,6 +376,14 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
368376
PARSE_OPT_KEEP_DASHDASH);
369377
parse_args(&pathspec, argv, prefix, patch_mode, &rev);
370378

379+
if (read_from_stdin) {
380+
warning(_("--stdin is deprecated, please use --pathspec-from-file=- instead"));
381+
free(pathspec_from_file);
382+
pathspec_from_file = xstrdup("-");
383+
if (nul_term_line)
384+
pathspec_file_nul = 1;
385+
}
386+
371387
if (pathspec_from_file) {
372388
if (patch_mode)
373389
die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--patch");

t/t7108-reset-stdin.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
test_description='reset --stdin'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'reset --stdin' '
8+
test_commit hello &&
9+
git rm hello.t &&
10+
test -z "$(git ls-files hello.t)" &&
11+
echo hello.t | git reset --stdin &&
12+
test hello.t = "$(git ls-files hello.t)"
13+
'
14+
15+
test_expect_success 'reset --stdin -z' '
16+
test_commit world &&
17+
git rm hello.t world.t &&
18+
test -z "$(git ls-files hello.t world.t)" &&
19+
printf world.tQworld.tQhello.tQ | q_to_nul | git reset --stdin -z &&
20+
printf "hello.t\nworld.t\n" >expect &&
21+
git ls-files >actual &&
22+
test_cmp expect actual
23+
'
24+
25+
test_expect_success '--stdin requires --mixed' '
26+
echo hello.t >list &&
27+
test_must_fail git reset --soft --stdin <list &&
28+
test_must_fail git reset --hard --stdin <list &&
29+
git reset --mixed --stdin <list
30+
'
31+
32+
test_done

0 commit comments

Comments
 (0)