clone: support 'clone --shared' from a worktree
authorEric Sunshine <sunshine@sunshineco.com>
Mon, 11 Dec 2017 23:16:12 +0000 (18:16 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 Dec 2017 00:05:50 +0000 (16:05 -0800)
When worktree functionality was originally implemented, the possibility
of 'clone --local' from within a worktree was overlooked, with the
result that the location of the "objects" directory of the source
repository was computed incorrectly, thus the objects could not be
copied or hard-linked by the clone. This shortcoming was addressed by
744e469755 (clone: allow --local from a linked checkout, 2015-09-28).

However, the related case of 'clone --shared' (despite being handled
only a few lines away from the 'clone --local' case) was not fixed by
744e469755, with a similar result of the "objects" directory location
being incorrectly computed for insertion into the 'alternates' file.
Fix this.

Reported-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clone.c
t/t2025-worktree-add.sh
index 3e14491a340cdce70308b31cdf96612344644c15..69eabc0d8802804d59bd03d443bdcd8b8a1da750 100644 (file)
@@ -423,7 +423,8 @@ static void clone_local(const char *src_repo, const char *dest_repo)
 {
        if (option_shared) {
                struct strbuf alt = STRBUF_INIT;
-               strbuf_addf(&alt, "%s/objects", src_repo);
+               get_common_dir(&alt, src_repo);
+               strbuf_addstr(&alt, "/objects");
                add_to_alternates_file(alt.buf);
                strbuf_release(&alt);
        } else {
index 369417498946fcebb901d8593bb584f3767b1e67..8f3e726d351b37fdd4f6e1cb9cb1d2f6a9400ea6 100755 (executable)
@@ -198,4 +198,10 @@ test_expect_success 'local clone from linked checkout' '
        ( cd here-clone && git fsck )
 '
 
+test_expect_success 'local clone --shared from linked checkout' '
+       git -C bare worktree add --detach ../baretree &&
+       git clone --local --shared baretree bare-clone &&
+       grep /bare/ bare-clone/.git/objects/info/alternates
+'
+
 test_done