From: Junio C Hamano Date: Sat, 10 Jan 2009 06:21:36 +0000 (-0800) Subject: Resurrect "git apply --flags -" to read from the standard input X-Git-Tag: v1.6.2-rc0~134^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=64912a67a43dec151906b93f96b07f16e17f71e9;p=git.git Resurrect "git apply --flags -" to read from the standard input The previous "parse-opt"ification broke git-apply reading from the standard input. "git apply A - C --- diff --git a/builtin-apply.c b/builtin-apply.c index cb988a352..2811c0fe4 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -3140,16 +3140,6 @@ static int git_apply_config(const char *var, const char *value, void *cb) return git_default_config(var, value, cb); } -static int option_parse_stdin(const struct option *opt, - const char *arg, int unset) -{ - int *errs = opt->value; - - *errs |= apply_patch(0, "", options); - read_stdin = 0; - return 0; -} - static int option_parse_exclude(const struct option *opt, const char *arg, int unset) { @@ -3218,9 +3208,6 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) const char *whitespace_option = NULL; struct option builtin_apply_options[] = { - { OPTION_CALLBACK, '-', NULL, &errs, NULL, - "read the patch from the standard input", - PARSE_OPT_NOARG, option_parse_stdin }, { OPTION_CALLBACK, 0, "exclude", NULL, "path", "don´t apply changes matching the given path", 0, option_parse_exclude }, @@ -3302,7 +3289,11 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) const char *arg = argv[i]; int fd; - if (0 < prefix_length) + if (!strcmp(arg, "-")) { + errs |= apply_patch(0, "", options); + read_stdin = 0; + continue; + } else if (0 < prefix_length) arg = prefix_filename(prefix, prefix_length, arg); fd = open(arg, O_RDONLY); diff --git a/t/t4106-apply-stdin.sh b/t/t4106-apply-stdin.sh new file mode 100755 index 000000000..72467a1e8 --- /dev/null +++ b/t/t4106-apply-stdin.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +test_description='git apply --numstat - text && + git add text && + echo goodbye >text && + git diff >patch +' + +test_expect_success 'git apply --numstat - < patch' ' + echo "1 1 text" >expect && + git apply --numstat - actual && + test_cmp expect actual +' + +test_expect_success 'git apply --numstat - < patch patch' ' + for i in 1 2; do echo "1 1 text"; done >expect && + git apply --numstat - < patch patch >actual && + test_cmp expect actual +' + +test_done