Skip to contentSkip to conversation

clone,fetch: catch non positive --depth option value

PATCH New Nguyễn Thái Ngọc Duy 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clone,fetch: catch non positive --depth option value

Instead of simply ignoring the value passed to --depth option when it is zero or negative, catch and report it as an error to let people know that they were using the option incorrectly.

---
This replaces aa/transport-non-positive-depth-only

 builtin/clone.c | 4 ++++
 builtin/fetch.c | 4 ++++
 2 files changed, 8 insertions(+)
builtin/clone.c +4 -0
index 552f340..535b52f 100644
@@ -797,6 +797,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	if (option_local > 0 && !is_local)
 		warning(_("--local is ignored"));
 
+	/* no need to be strict, transport_set_option() will validate it again */
+	if (option_depth && atoi(option_depth) < 1)
+		die(_("depth %s is not a positive number"), option_depth);
+
 	if (argc == 2)
 		dir = xstrdup(argv[1]);
 	else
builtin/fetch.c +4 -0
index 2496ad2..ed399eb 100644
@@ -1047,6 +1047,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 		}
 	}
 
+	/* no need to be strict, transport_set_option() will validate it again */
+	if (depth && atoi(depth) < 1)
+		die(_("depth %s is not a positive number"), depth);
+
 	if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
 		if (recurse_submodules_default) {
 			int arg = parse_fetch_recurse_submodules_arg("--recurse-submodules-default", recurse_submodules_default);
Signature · 1 line
1.8.5.1.25.g8667982