summaryrefslogtreecommitdiff
path: root/builtin-clone.c
diff options
context:
space:
mode:
authorClemens Buchacher <drizzd@aon.at>2008-09-03 20:55:55 +0200
committerJunio C Hamano <gitster@pobox.com>2008-09-03 12:32:41 -0700
commit44a68fd526a70f0aaf213143e22f1257f296e724 (patch)
treeca7712d5b61eb0de74fdd626bfc168a5fce9f9be /builtin-clone.c
parentdb3a95459cb873c302051b4b2b693be5ba248c13 (diff)
downloadgit-44a68fd526a70f0aaf213143e22f1257f296e724.tar.gz
clone: fix creation of explicitly named target directory
'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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-clone.c')
-rw-r--r--builtin-clone.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/builtin-clone.c b/builtin-clone.c
index f44eceab3a..c8435295ce 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -147,6 +147,15 @@ static int is_directory(const char *path)
return !stat(path, &buf) && S_ISDIR(buf.st_mode);
}
+static void strip_trailing_slashes(char *dir)
+{
+ char *end = dir + strlen(dir);
+
+ while (dir < end - 1 && is_dir_sep(end[-1]))
+ end--;
+ *end = '\0';
+}
+
static void setup_reference(const char *repo)
{
const char *ref_git;
@@ -397,6 +406,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
dir = xstrdup(argv[1]);
else
dir = guess_dir_name(repo_name, is_bundle, option_bare);
+ strip_trailing_slashes(dir);
if (!stat(dir, &buf))
die("destination directory '%s' already exists.", dir);
@@ -422,10 +432,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;