From: Junio C Hamano Date: Wed, 03 Sep 2008 19:24:31 GMT Subject: Re: [PATCH] clone: fix creation of explicitly named target directory Message-ID: <7vprnlav80.fsf@gitster.siamese.dyndns.org> In-Reply-To: <20080903185554.GA6738@localhost> Clemens Buchacher writes: > 'git clone 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. > @@ -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.