git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] clone: fix creation of explicitly named target directory

From
Clemens Buchacher <drizzd@aon.at>
Date
Sep 3, 2008, 18:55 UTC
Message-ID
<20080903185554.GA6738@localhost>
In-Reply-To
<7vk5dul7f5.fsf@gitster.siamese.dyndns.org>

'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.
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
On Tue, Sep 02, 2008 at 11:38:38AM -0700, Junio C Hamano wrote:
Show 5 quoted lines
> As a "bugfix" patch meant to apply to 'maint', I'd prefer a fix to the
> caller (builtin-clone.c that calls the function), which should be of much
> less impact.  It is fine to include the change to add strerror(errno) in
> that patch, whose title would be "clone: fix creation of explicitly named
> target directory".
 builtin-clone.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index f44ecea..bbfa7d1 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -147,6 +147,17 @@ static int is_directory(const char *path)
 	return !stat(path, &buf) && S_ISDIR(buf.st_mode);
 }
 
+static char *strip_dir_sep(char *dir)
+{
+	char *end = dir + strlen(dir);
+
+	while (dir < end && is_dir_sep(end[-1]))
+		end--;
+	*end = '\0';
+
+	return dir;
+}
+
 static void setup_reference(const char *repo)
 {
 	const char *ref_git;
@@ -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);
 
@@ -422,10 +433,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	if (!option_bare) {
 		junk_work_tree = work_tree;
 		if (safe_create_leading_directories_const(work_tree) < 0)
-			die("could not create leading directories of '%s'",
-					work_tree);
+			die("could not create leading directories of '%s': %s",
+					work_tree, strerror(errno));
 		if (mkdir(work_tree, 0755))
-			die("could not create work tree dir '%s'.", work_tree);
+			die("could not create work tree dir '%s': %s.",
+					work_tree, strerror(errno));
 		set_git_work_tree(work_tree);
 	}
 	junk_git_dir = git_dir;
-- 
1.6.0
Previous: Clemens BuchacherNext: Junio C Hamano
Message 8 of 9 in “ignore trailing slash when creating leading directories”
  1. ignore trailing slash when creating leading directoriesClemens Buchacher, Sep 2, 2008
  2. Junio C HamanoSep 2, 2008
  3. Clemens BuchacherSep 2, 2008
  4. ignore trailing slashes when creating leading directoriesClemens Buchacher, Sep 2, 2008
  5. Junio C HamanoSep 2, 2008
  6. Junio C HamanoSep 2, 2008
  7. Clemens BuchacherSep 3, 2008
  8. clone: fix creation of explicitly named target directoryClemens Buchacher, Sep 3, 2008
  9. Junio C HamanoSep 3, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.