From 0658569eb03e743ef46abd06abd9d0d81d53e72c Mon Sep 17 00:00:00 2001 From: Aaron Schrab Date: Mon, 8 Apr 2013 18:46:39 -0400 Subject: [PATCH 1/2] clone: Fix error message for reference repository Do not report that an argument to clone's --reference option is not a local directory. Nothing checks for the existence or type of the path as supplied by the user; checks are only done for particular contents of the supposed directory, so we have no way to know the status of the supplied path. Telling the user that a directory doesn't exist when that isn't actually known may lead him or her on the wrong path to finding the problem. Instead just state that the entered path is not a local repository which is really all that is known about it. It could be more helpful to state the actual paths which were checked, but I believe that giving a good description of that would be too verbose for a simple error message and would be too dependent on implementation details. Signed-off-by: Aaron Schrab Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/clone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/clone.c b/builtin/clone.c index f9c380eb6c..0a1e0bf5a4 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -241,7 +241,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data) free(ref_git); ref_git = ref_git_git; } else if (!is_directory(mkpath("%s/objects", ref_git))) - die(_("reference repository '%s' is not a local directory."), + die(_("reference repository '%s' is not a local repository."), item->string); strbuf_addf(&alternate, "%s/objects", ref_git); From b552b56df2c13885a67ca9ec9f76c21d3b7e2cde Mon Sep 17 00:00:00 2001 From: Aaron Schrab Date: Tue, 9 Apr 2013 18:22:00 -0400 Subject: [PATCH 2/2] clone: Allow repo using gitfile as a reference 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 Signed-off-by: Junio C Hamano --- builtin/clone.c | 14 ++++++++++++-- t/t5700-clone-reference.sh | 13 +++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 0a1e0bf5a4..58fee9874f 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -232,11 +232,21 @@ static void strip_trailing_slashes(char *dir) static int add_one_reference(struct string_list_item *item, void *cb_data) { char *ref_git; + const char *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 = read_gitfile(ref_git); + if (!repo) + repo = 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 60f1552ade..6537911a43 100755 --- a/t/t5700-clone-reference.sh +++ b/t/t5700-clone-reference.sh @@ -185,4 +185,17 @@ 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_expect_success 'clone using repo pointed at by gitfile as reference' ' + git clone --reference=M/.git A O && + echo "$base_dir/L/objects" >expected && + test_cmp expected "$base_dir/O/.git/objects/info/alternates" +' + test_done