Skip to content

Commit 4e0d673

Browse files
committed
Merge branch 'phase-out-reset-stdin'
This topic branch re-adds the deprecated --stdin/-z options to `git reset`. Those patches were overridden by a different set of options in the upstream Git project before we could propose `--stdin`. We offered this in MinGit to applications that wanted a safer way to pass lots of pathspecs to Git, and these applications will need to be adjusted. Instead of `--stdin`, `--pathspec-from-file=-` should be used, and instead of `-z`, `--pathspec-file-nul`. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 592c7ad + b7d6d7e commit 4e0d673

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Documentation/git-reset.txt

Lines changed: 11 additions & 0 deletions
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
-----------
@@ -131,6 +132,16 @@ OPTIONS
131132
+
132133
For more details, see the 'pathspec' entry in linkgit:gitglossary[7].
133134

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

builtin/reset.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "submodule.h"
2727
#include "submodule-config.h"
2828
#include "dir.h"
29+
#include "strbuf.h"
30+
#include "quote.h"
2931

3032
#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
3133

@@ -34,6 +36,7 @@ static const char * const git_reset_usage[] = {
3436
N_("git reset [-q] [<tree-ish>] [--] <pathspec>..."),
3537
N_("git reset [-q] [--pathspec-from-file [--pathspec-file-nul]] [<tree-ish>]"),
3638
N_("git reset --patch [<tree-ish>] [--] [<pathspec>...]"),
39+
N_("DEPRECATED: git reset [-q] [--stdin [-z]] [<tree-ish>]"),
3740
NULL
3841
};
3942

@@ -397,6 +400,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
397400
struct object_id oid;
398401
struct pathspec pathspec;
399402
int intent_to_add = 0;
403+
int nul_term_line = 0, read_from_stdin = 0;
400404
const struct option options[] = {
401405
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
402406
OPT_SET_INT(0, "mixed", &reset_type,
@@ -416,6 +420,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
416420
N_("record only the fact that removed paths will be added later")),
417421
OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
418422
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
423+
OPT_BOOL('z', NULL, &nul_term_line,
424+
N_("DEPRECATED (use --pathspec-file-nul instead): paths are separated with NUL character")),
425+
OPT_BOOL(0, "stdin", &read_from_stdin,
426+
N_("DEPRECATED (use --pathspec-from-file=- instead): read paths from <stdin>")),
419427
OPT_END()
420428
};
421429

@@ -426,6 +434,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
426434
PARSE_OPT_KEEP_DASHDASH);
427435
parse_args(&pathspec, argv, prefix, patch_mode, &rev);
428436

437+
if (read_from_stdin) {
438+
pathspec_from_file = "-";
439+
if (nul_term_line)
440+
pathspec_file_nul = 1;
441+
}
442+
429443
if (pathspec_from_file) {
430444
if (patch_mode)
431445
die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--patch");

t/t7108-reset-stdin.sh

Lines changed: 32 additions & 0 deletions
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)