clone: validate --origin option before use
authorSean Barag <redacted>
Thu, 1 Oct 2020 03:46:14 +0000 (03:46 +0000)
committerJunio C Hamano <redacted>
Thu, 1 Oct 2020 05:09:13 +0000 (22:09 -0700)
Providing a bad origin name to `git clone` currently reports an
'invalid refspec' error instead of a more explicit message explaining
that the `--origin` option was malformed.  This behavior dates back to
since 8434c2f1 (Build in clone, 2008-04-27).  Reintroduce
validation for the provided `--origin` option, but notably _don't_
include a multi-level check (e.g. "foo/bar") that was present in the
original `git-clone.sh`.  `git remote` allows multi-level remote names
since at least 46220ca100 (remote.c: Fix overtight refspec validation,
2008-03-20), so that appears to be the desired behavior.

Helped-by: Junio C Hamano <redacted>
Helped-by: Derrick Stolee <redacted>
Helped-by: Jeff King <redacted>
Signed-off-by: Sean Barag <redacted>
Signed-off-by: Junio C Hamano <redacted>
builtin/clone.c

index 258bfd65b74a9995cc2dd975fec325af3284e08e..78364a08614f66b80146e98143733e06f5169e98 100644 (file)
@@ -1012,6 +1012,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (!option_origin)
                option_origin = "origin";
 
+       if (!valid_remote_name(option_origin))
+               die(_("'%s' is not a valid remote name"), option_origin);
+
        repo_name = argv[0];
 
        path = get_repo_path(repo_name, &is_bundle);
git clone https://git.99rst.org/PROJECT