From: Clemens Buchacher <drizzd@aon.at>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH] clone: fix creation of explicitly named target directory
Date: Wed, 3 Sep 2008 20:55:55 +0200 [thread overview]
Message-ID: <20080903185554.GA6738@localhost> (raw)
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:
> 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
next prev parent reply other threads:[~2008-09-03 18:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-02 8:19 [PATCH] ignore trailing slash when creating leading directories Clemens Buchacher
2008-09-02 18:38 ` Junio C Hamano
2008-09-02 19:13 ` Clemens Buchacher
2008-09-02 20:07 ` [PATCH v2] ignore trailing slashes " Clemens Buchacher
2008-09-02 20:36 ` [PATCH] ignore trailing slash " Junio C Hamano
2008-09-02 21:10 ` Junio C Hamano
2008-09-03 19:02 ` Clemens Buchacher
2008-09-03 18:55 ` Clemens Buchacher [this message]
2008-09-03 19:24 ` [PATCH] clone: fix creation of explicitly named target directory Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080903185554.GA6738@localhost \
--to=drizzd@aon.at \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).