Skip to content

Commit ebe7e28

Browse files
sjbaraggitster
authored andcommitted
clone: validate --origin option before use
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 8434c2f (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 46220ca (remote.c: Fix overtight refspec validation, 2008-03-20), so that appears to be the desired behavior. Helped-by: Junio C Hamano <[email protected]> Helped-by: Derrick Stolee <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Sean Barag <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2c6fda commit ebe7e28

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

builtin/clone.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10121012
if (!option_origin)
10131013
option_origin = "origin";
10141014

1015+
if (!valid_remote_name(option_origin))
1016+
die(_("'%s' is not a valid remote name"), option_origin);
1017+
10151018
repo_name = argv[0];
10161019

10171020
path = get_repo_path(repo_name, &is_bundle);

0 commit comments

Comments
 (0)