Re: [PATCH] clone: fix creation of explicitly named target directory
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:17
Clemens Buchacher [off-list ref] writes:
'git clone <repo> path/' (note the trailing slash) fails, because the entire path is interpreted as leading directories. So when mkdir tries to create the actual path, it already exists. This makes sure trailing slashes are removed.
Thanks.
+static char *strip_dir_sep(char *dir)
+{
+ char *end = dir + strlen(dir);
+
+ while (dir < end && is_dir_sep(end[-1]))
+ end--;
+ *end = '\0';It does not matter in this particular context, but I'd do "dir < end - 1" to avoid returning the root directory as an empty string, just as a disciplined style; also I'd rename this to strip_trailing_slashes(), make it of type void to make it more clear that it munges the string that is given as the input parameter.
quoted hunk
@@ -394,7 +405,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) repo = repo_name; if (argc == 2) - dir = xstrdup(argv[1]); + dir = strip_dir_sep(xstrdup(argv[1])); else dir = guess_dir_name(repo_name, is_bundle, option_bare);
Made me wonder if guess_dir_name() can return something with trailing
slashes; it turns out that it doesn't, but not very nice. As people's
braincycle is more precious, I'd rather say:
if (argc == 2)
dir = xstrdup(argv[1]);
else
dir = guess_dir_name(repo_name, is_bundle, option_bare);
strip_trailing_slashes(dir);
I'll queue with the above changes to reduce one round of back-and-forth,
but if you see any flaws in my above reasoning, please say so.