Skip to content

Commit 30ee11c

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 67cdced + 0afea6a commit 30ee11c

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

Documentation/git-reset.adoc

+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
@@ -38,6 +38,8 @@
3838
#include "trace2.h"
3939
#include "dir.h"
4040
#include "add-interactive.h"
41+
#include "strbuf.h"
42+
#include "quote.h"
4143

4244
#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
4345

@@ -46,6 +48,7 @@ static const char * const git_reset_usage[] = {
4648
N_("git reset [-q] [<tree-ish>] [--] <pathspec>..."),
4749
N_("git reset [-q] [--pathspec-from-file [--pathspec-file-nul]] [<tree-ish>]"),
4850
N_("git reset --patch [<tree-ish>] [--] [<pathspec>...]"),
51+
N_("DEPRECATED: git reset [-q] [--stdin [-z]] [<tree-ish>]"),
4952
NULL
5053
};
5154

@@ -346,6 +349,7 @@ int cmd_reset(int argc,
346349
struct object_id oid;
347350
struct pathspec pathspec;
348351
int intent_to_add = 0;
352+
int nul_term_line = 0, read_from_stdin = 0;
349353
const struct option options[] = {
350354
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
351355
OPT_BOOL(0, "no-refresh", &no_refresh,
@@ -374,6 +378,10 @@ int cmd_reset(int argc,
374378
N_("record only the fact that removed paths will be added later")),
375379
OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
376380
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
381+
OPT_BOOL('z', NULL, &nul_term_line,
382+
N_("DEPRECATED (use --pathspec-file-nul instead): paths are separated with NUL character")),
383+
OPT_BOOL(0, "stdin", &read_from_stdin,
384+
N_("DEPRECATED (use --pathspec-from-file=- instead): read paths from <stdin>")),
377385
OPT_END()
378386
};
379387

@@ -383,6 +391,14 @@ int cmd_reset(int argc,
383391
PARSE_OPT_KEEP_DASHDASH);
384392
parse_args(&pathspec, argv, prefix, patch_mode, &rev);
385393

394+
if (read_from_stdin) {
395+
warning(_("--stdin is deprecated, please use --pathspec-from-file=- instead"));
396+
free(pathspec_from_file);
397+
pathspec_from_file = xstrdup("-");
398+
if (nul_term_line)
399+
pathspec_file_nul = 1;
400+
}
401+
386402
if (pathspec_from_file) {
387403
if (patch_mode)
388404
die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--patch");

t/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ integration_tests = [
861861
't7105-reset-patch.sh',
862862
't7106-reset-unborn-branch.sh',
863863
't7107-reset-pathspec-file.sh',
864+
't7108-reset-stdin.sh',
864865
't7110-reset-merge.sh',
865866
't7111-reset-table.sh',
866867
't7112-reset-submodule.sh',

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)