git-check-attr: Error out if no pathnames are specified

If no pathnames are passed as command-line arguments and the --stdin option is not specified, fail with the error message "No file specified". Add tests of this behavior. 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 fdf6be8259fc59fc251b325f66e86df0fe905e79
2 files changed +9 -2
builtin/check-attr.c
+7 -2
@@ -111,8 +111,13 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
111 }
112
113 /* Check file argument(s): */
114 - if (stdin_paths && filei < argc)
115 - error_with_usage("Can't specify files with --stdin");
114 + if (stdin_paths) {
115 + if (filei < argc)
116 + error_with_usage("Can't specify files with --stdin");
117 + } else {
118 + if (filei >= argc)
119 + error_with_usage("No file specified");
120 + }
121
122 check = xcalloc(cnt, sizeof(*check));
123 for (i = 0; i < cnt; i++) {
t/t0003-attributes.sh
+2
@@ -46,6 +46,8 @@ test_expect_success 'command line checks' '
46
47 test_must_fail git check-attr &&
48 test_must_fail git check-attr -- &&
49 + test_must_fail git check-attr test &&
50 + test_must_fail git check-attr test -- &&
51 test_must_fail git check-attr -- f &&
52 echo "f" | test_must_fail git check-attr --stdin &&
53 echo "f" | test_must_fail git check-attr --stdin -- f &&