git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 1/2] clone: allow to clone from .git file
Date: Sun, 21 Aug 2011 18:58:09 +0700	[thread overview]
Message-ID: <1313927890-21227-1-git-send-email-pclouds@gmail.com> (raw)


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/clone.c  |   23 ++++++++++++++++++++++-
 t/t5601-clone.sh |    4 ++++
 2 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 7663bc2..eff3b5e 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -103,10 +103,31 @@ static char *get_repo_path(const char *repo, int *is_bundle)
 	for (i = 0; i < ARRAY_SIZE(suffix); i++) {
 		const char *path;
 		path = mkpath("%s%s", repo, suffix[i]);
-		if (is_directory(path)) {
+		if (stat(path, &st))
+			continue;
+		if (S_ISDIR(st.st_mode)) {
 			*is_bundle = 0;
 			return xstrdup(absolute_path(path));
 		}
+		else if (S_ISREG(st.st_mode) && st.st_size > 8) {
+			/* Despite the name read_gitfile_gently can be
+			   cruel on non .git file, check for signature
+			   ourselves */
+			char signature[8];
+			int len, fd = open(path, O_RDONLY);
+			if (fd < 0)
+				continue;
+			len = read_in_full(fd, signature, 8);
+			close(fd);
+			if (len != 8 || strncmp(signature, "gitdir: ", 8))
+				continue;
+
+			path = read_gitfile_gently(path);
+			if (path) {
+				*is_bundle = 0;
+				return xstrdup(absolute_path(path));
+			}
+		}
 	}
 
 	for (i = 0; i < ARRAY_SIZE(bundle_suffix); i++) {
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 151ea53..501bd3f 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -202,6 +202,10 @@ test_expect_success 'clone separate gitdir: output' '
 	test_cmp expected dst/.git
 '
 
+test_expect_success 'clone from .git file' '
+	git clone dst/.git dst2
+'
+
 test_expect_success 'clone separate gitdir where target already exists' '
 	rm -rf dst &&
 	test_must_fail git clone --separate-git-dir realgitdir src dst
-- 
1.7.4.74.g639db

             reply	other threads:[~2011-08-21 11:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-21 11:58 Nguyễn Thái Ngọc Duy [this message]
2011-08-21 11:58 ` [PATCH 2/2] Do not accept NUL in the path in .git file Nguyễn Thái Ngọc Duy
2011-08-21 18:54 ` [PATCH 1/2] clone: allow to clone from " Junio C Hamano
2011-08-22  3:08   ` Nguyen Thai Ngoc Duy
2011-08-22 19:02     ` Junio C Hamano
2011-08-22 21:01       ` Re* " Junio C Hamano
2011-08-23  1:11         ` Nguyen Thai Ngoc Duy
2011-08-23  3:53           ` Junio C Hamano
2011-08-23  4:11             ` Nguyen Thai Ngoc Duy

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=1313927890-21227-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /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).