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

[PATCH 2/2] clone: Allow repo using gitfile as a reference

From
Aaron Schrab <aaron@schrab.com>
Date
Apr 7, 2013, 23:17 UTC
Message-ID
<1365376629-16054-2-git-send-email-aaron@schrab.com>
In-Reply-To
<1365376629-16054-1-git-send-email-aaron@schrab.com>

Try reading gitfile files when processing --reference options to clone. This will allow, among other things, using a submodule checked out with a recent version of git as a reference repository without requiring the user to have internal knowledge of submodule layout.

Signed-off-by: Aaron Schrab <aaron@schrab.com>
---
 builtin/clone.c            | 13 ++++++++++---
 t/t5700-clone-reference.sh |  7 +++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 0a1e0bf..376ded8 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -231,12 +231,19 @@ static void strip_trailing_slashes(char *dir)
 
 static int add_one_reference(struct string_list_item *item, void *cb_data)
 {
-	char *ref_git;
+	char *ref_git, *repo;
 	struct strbuf alternate = STRBUF_INIT;
 
-	/* Beware: real_path() and mkpath() return static buffer */
+	/* Beware: read_gitfile(), real_path() and mkpath() return static buffer */
 	ref_git = xstrdup(real_path(item->string));
-	if (is_directory(mkpath("%s/.git/objects", ref_git))) {
+
+	repo = (char *)read_gitfile(mkpath("%s/.git", ref_git));
+	if (repo) {
+		free(ref_git);
+		ref_git = xstrdup(repo);
+	}
+
+	if (!repo && is_directory(mkpath("%s/.git/objects", ref_git))) {
 		char *ref_git_git = mkpathdup("%s/.git", ref_git);
 		free(ref_git);
 		ref_git = ref_git_git;
diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh
index 2a7b78b..7a9044c 100755
--- a/t/t5700-clone-reference.sh
+++ b/t/t5700-clone-reference.sh
@@ -185,4 +185,11 @@ test_expect_success 'fetch with incomplete alternates' '
 	! grep " want $tag_object" "$U.K"
 '
 
+test_expect_success 'clone using repo with gitfile as a reference' '
+	git clone --separate-git-dir=L A M &&
+	git clone --reference=M A N &&
+	echo "$base_dir/L/objects" > expected &&
+	test_cmp expected "$base_dir/N/.git/objects/info/alternates"
+'
+
 test_done
-- 
1.8.2.677.g7422c62
Previous: Aaron SchrabNext: Jonathan Nieder
Message 2 of 28 in “clone: Fix error message for reference repository”
  1. 1/2 clone: Fix error message for reference repositoryAaron Schrab, Apr 7, 2013
  2. 2/2 clone: Allow repo using gitfile as a referenceAaron Schrab, Apr 7, 2013
  3. Jonathan NiederApr 7, 2013
  4. Aaron SchrabApr 8, 2013
  5. Junio C HamanoApr 8, 2013
  6. Aaron SchrabApr 8, 2013
  7. 0/2 Using gitfile repository with clone --referenceAaron Schrab, Apr 8, 2013
  8. 1/2 clone: Fix error message for reference repositoryAaron Schrab, Apr 8, 2013
  9. Jonathan NiederApr 9, 2013
  10. 2/2 clone: Allow repo using gitfile as a referenceAaron Schrab, Apr 8, 2013
  11. Jonathan NiederApr 9, 2013
  12. Aaron SchrabApr 9, 2013
  13. Junio C HamanoApr 9, 2013
  14. Aaron SchrabApr 9, 2013
  15. 0/2 Using gitfile repository with clone --referenceAaron Schrab, Apr 9, 2013
  16. 1/2 clone: Fix error message for reference repositoryAaron Schrab, Apr 9, 2013
  17. 2/2 clone: Allow repo using gitfile as a referenceAaron Schrab, Apr 9, 2013
  18. Junio C HamanoApr 9, 2013
  19. Jonathan NiederApr 7, 2013
  20. Aaron SchrabApr 8, 2013
  21. Aaron SchrabApr 8, 2013
  22. Junio C HamanoApr 8, 2013
  23. Aaron SchrabApr 8, 2013
  24. Junio C HamanoApr 8, 2013
  25. Aaron SchrabApr 8, 2013
  26. Junio C HamanoApr 8, 2013
  27. Aaron SchrabApr 8, 2013
  28. Junio C HamanoApr 8, 2013

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.