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

[PATCH 1/2] clone: allow to clone from .git file

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Aug 21, 2011, 11:58 UTC
Message-ID
<1313927890-21227-1-git-send-email-pclouds@gmail.com>
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
Next: Nguyễn Thái Ngọc Duy
Message 1 of 9 in “clone: allow to clone from .git file”
  1. 1/2 clone: allow to clone from .git fileNguyễn Thái Ngọc Duy, Aug 21, 2011
  2. 2/2 Do not accept NUL in the path in .git fileNguyễn Thái Ngọc Duy, Aug 21, 2011
  3. Junio C HamanoAug 21, 2011
  4. Nguyen Thai Ngoc DuyAug 22, 2011
  5. Junio C HamanoAug 22, 2011
  6. Re* [PATCH 1/2] clone: allow to clone from .git fileJunio C Hamano, Aug 22, 2011
  7. Nguyen Thai Ngoc DuyAug 23, 2011
  8. Junio C HamanoAug 23, 2011
  9. Nguyen Thai Ngoc DuyAug 23, 2011

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.