Skip to content

Commit

Permalink
Merge branch 'phase-out-reset-stdin'
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed May 15, 2020
2 parents 6845697 + 123c91b commit 5d51859
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Documentation/git-reset.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ SYNOPSIS
'git reset' [-q] [--pathspec-from-file=<file> [--pathspec-file-nul]] [<tree-ish>]
'git reset' (--patch | -p) [<tree-ish>] [--] [<pathspec>...]
'git reset' [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]
DEPRECATED: 'git reset' [-q] [--stdin [-z]] [<tree-ish>]

DESCRIPTION
-----------
Expand Down Expand Up @@ -130,6 +131,16 @@ OPTIONS
+
For more details, see the 'pathspec' entry in linkgit:gitglossary[7].

--stdin::
DEPRECATED (use `--pathspec-from-file=-` instead): Instead of taking
list of paths from the command line, read list of paths from the
standard input. Paths are separated by LF (i.e. one path per line) by
default.

-z::
DEPRECATED (use `--pathspec-file-nul` instead): Only meaningful with
`--stdin`; paths are separated with NUL character instead of LF.

EXAMPLES
--------

Expand Down
14 changes: 14 additions & 0 deletions builtin/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "cache-tree.h"
#include "submodule.h"
#include "submodule-config.h"
#include "strbuf.h"
#include "quote.h"

#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)

Expand All @@ -33,6 +35,7 @@ static const char * const git_reset_usage[] = {
N_("git reset [-q] [<tree-ish>] [--] <pathspec>..."),
N_("git reset [-q] [--pathspec-from-file [--pathspec-file-nul]] [<tree-ish>]"),
N_("git reset --patch [<tree-ish>] [--] [<pathspec>...]"),
N_("DEPRECATED: git reset [-q] [--stdin [-z]] [<tree-ish>]"),
NULL
};

Expand Down Expand Up @@ -291,6 +294,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
struct object_id oid;
struct pathspec pathspec;
int intent_to_add = 0;
int nul_term_line = 0, read_from_stdin = 0;
const struct option options[] = {
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
OPT_SET_INT(0, "mixed", &reset_type,
Expand All @@ -310,6 +314,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
N_("record only the fact that removed paths will be added later")),
OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
OPT_BOOL('z', NULL, &nul_term_line,
N_("DEPRECATED (use --pathspec-file-nul instead): paths are separated with NUL character")),
OPT_BOOL(0, "stdin", &read_from_stdin,
N_("DEPRECATED (use --pathspec-from-file=- instead): read paths from <stdin>")),
OPT_END()
};

Expand All @@ -320,6 +328,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
PARSE_OPT_KEEP_DASHDASH);
parse_args(&pathspec, argv, prefix, patch_mode, &rev);

if (read_from_stdin) {
pathspec_from_file = "-";
if (nul_term_line)
pathspec_file_nul = 1;
}

if (pathspec_from_file) {
if (patch_mode)
die(_("--pathspec-from-file is incompatible with --patch"));
Expand Down
32 changes: 32 additions & 0 deletions t/t7108-reset-stdin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

test_description='reset --stdin'

. ./test-lib.sh

test_expect_success 'reset --stdin' '
test_commit hello &&
git rm hello.t &&
test -z "$(git ls-files hello.t)" &&
echo hello.t | git reset --stdin &&
test hello.t = "$(git ls-files hello.t)"
'

test_expect_success 'reset --stdin -z' '
test_commit world &&
git rm hello.t world.t &&
test -z "$(git ls-files hello.t world.t)" &&
printf world.tQworld.tQhello.tQ | q_to_nul | git reset --stdin -z &&
printf "hello.t\nworld.t\n" >expect &&
git ls-files >actual &&
test_cmp expect actual
'

test_expect_success '--stdin requires --mixed' '
echo hello.t >list &&
test_must_fail git reset --soft --stdin <list &&
test_must_fail git reset --hard --stdin <list &&
git reset --mixed --stdin <list
'

test_done

0 comments on commit 5d51859

Please sign in to comment.