git-check-attr: Process command-line args more systematically
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
72541040c3ed00084344de5bf75cbc5a514504bb
1 file changed
+12
-7
builtin/check-attr.c
+12
-7
@@ -81,8 +81,6 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
81
82
argc = parse_options(argc, argv, prefix, check_attr_options,
83
check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
84
- if (!argc)
85
- usage_with_options(check_attr_usage, check_attr_options);
84
85
if (read_cache() < 0) {
86
die("invalid cache");
@@ -94,8 +92,17 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
92
doubledash = i;
93
}
94
97
- /* If there is no double dash, we handle only one attribute */
98
- if (doubledash < 0) {
95
+ /* Check attribute argument(s): */
96
+ if (doubledash == 0) {
97
+ error_with_usage("No attribute specified");
98
+ } else if (doubledash < 0) {
99
+ /*
100
+ * There is no double dash; treat the first
101
+ * argument as an attribute.
102
+ */
103
+ if (!argc)
104
+ error_with_usage("No attribute specified");
105
+
106
cnt = 1;
107
filei = 1;
108
} else {
@@ -103,9 +110,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
110
filei = doubledash + 1;
111
}
112
106
- if (cnt <= 0)
107
- error_with_usage("No attribute specified");
108
-
113
+ /* Check file argument(s): */
114
if (stdin_paths && filei < argc)
115
error_with_usage("Can't specify files with --stdin");
116