From dbc92b072dd7023f8ba1f682a8060022fc72504a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 22 Aug 2011 18:05:15 -0700 Subject: clone: allow more than one --reference Also add a test to expose a long-standing bug that is triggered when cloning with --reference option from a local repository that has its own alternates. The alternate object stores specified on the command line are lost, and only alternates copied from the source repository remain. The bug will be fixed in the next patch. Signed-off-by: Junio C Hamano --- t/t5601-clone.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 't') diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 151ea531b..0163ad1e2 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -207,4 +207,19 @@ test_expect_success 'clone separate gitdir where target already exists' ' test_must_fail git clone --separate-git-dir realgitdir src dst ' +test_expect_failure 'clone --reference from original' ' + git clone --shared --bare src src-1 && + git clone --bare src src-2 && + git clone --reference=src-2 --bare src-1 target-8 && + grep /src-2/ target-8/objects/info/alternates +' + +test_expect_success 'clone with more than one --reference' ' + git clone --bare src src-3 && + git clone --bare src src-4 && + git clone --reference=src-3 --reference=src-4 src target-9 && + grep /src-3/ target-9/.git/objects/info/alternates && + grep /src-4/ target-9/.git/objects/info/alternates +' + test_done -- cgit v1.2.1 From e6baf4a1ae1bb75d59967066ade1290cf105dcd8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 22 Aug 2011 18:05:16 -0700 Subject: clone: clone from a repository with relative alternates Cloning from a local repository blindly copies or hardlinks all the files under objects/ hierarchy. This results in two issues: - If the repository cloned has an "objects/info/alternates" file, and the command line of clone specifies --reference, the ones specified on the command line get overwritten by the copy from the original repository. - An entry in a "objects/info/alternates" file can specify the object stores it borrows objects from as a path relative to the "objects/" directory. When cloning a repository with such an alternates file, if the new repository is not sitting next to the original repository, such relative paths needs to be adjusted so that they can be used in the new repository. This updates add_to_alternates_file() to take the path to the alternate object store, including the "/objects" part at the end (earlier, it was taking the path to $GIT_DIR and was adding "/objects" itself), as it is technically possible to specify in objects/info/alternates file the path of a directory whose name does not end with "/objects". Signed-off-by: Junio C Hamano --- t/t5601-clone.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 0163ad1e2..d87214cfb 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -207,7 +207,7 @@ test_expect_success 'clone separate gitdir where target already exists' ' test_must_fail git clone --separate-git-dir realgitdir src dst ' -test_expect_failure 'clone --reference from original' ' +test_expect_success 'clone --reference from original' ' git clone --shared --bare src src-1 && git clone --bare src src-2 && git clone --reference=src-2 --bare src-1 target-8 && @@ -222,4 +222,12 @@ test_expect_success 'clone with more than one --reference' ' grep /src-4/ target-9/.git/objects/info/alternates ' +test_expect_success 'clone from original with relative alternate' ' + mkdir nest && + git clone --bare src nest/src-5 && + echo ../../../src/.git/objects >nest/src-5/objects/info/alternates && + git clone --bare nest/src-5 target-10 && + grep /src/\\.git/objects target-10/objects/info/alternates +' + test_done -- cgit v1.2.1