git-check-attr: Fix command-line handling to match docs
According to the git-check-attr synopsis, if the '--stdin' option is used then no pathnames are expected on the command line. Change the behavior to match this description; namely, if '--stdin' is used but not '--', then treat all command-line arguments as attribute names. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Aug 4, 2011 at 06:36 UTC
ca64d061e0ddf7fa1496a15c75eb5e730c4360e0
3 files changed
+14
-9
Documentation/git-check-attr.txt
+5
-2
@@ -33,8 +33,11 @@ OPTIONS
33
34
\--::
35
Interpret all preceding arguments as attributes and all following
36
- arguments as path names. If not supplied, only the first argument will
37
- be treated as an attribute.
36
+ arguments as path names.
37
+
38
+If none of `--stdin`, `--all`, or `--` is used, the first argument
39
+will be treated as an attribute and the rest of the arguments as
40
+pathnames.
41
42
OUTPUT
43
------
builtin/check-attr.c
+9
-6
@@ -111,15 +111,18 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
111
} else if (doubledash == 0) {
112
error_with_usage("No attribute specified");
113
} else if (doubledash < 0) {
114
- /*
115
- * There is no double dash; treat the first
116
- * argument as an attribute.
117
- */
114
if (!argc)
115
error_with_usage("No attribute specified");
116
121
- cnt = 1;
122
- filei = 1;
117
+ if (stdin_paths) {
118
+ /* Treat all arguments as attribute names. */
119
+ cnt = argc;
120
+ filei = argc;
121
+ } else {
122
+ /* Treat exactly one argument as an attribute name. */
123
+ cnt = 1;
124
+ filei = 1;
125
+ }
126
} else {
127
cnt = doubledash;
128
filei = doubledash + 1;
t/t0003-attributes.sh
-1
@@ -70,7 +70,6 @@ test_expect_success 'command line checks' '
70
echo "f" | test_must_fail git check-attr --stdin &&
71
echo "f" | test_must_fail git check-attr --stdin -- f &&
72
echo "f" | test_must_fail git check-attr --stdin test -- f &&
73
- echo "f" | test_must_fail git check-attr --stdin test f &&
73
test_must_fail git check-attr "" -- f
74
75
'