Skip to content

Commit b3b0597

Browse files
sunshinecogitster
authored andcommitted
clone: support 'clone --shared' from a worktree
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 744e469 (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 744e469, 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 <[email protected]> Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d78db84 commit b3b0597

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

builtin/clone.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ static void clone_local(const char *src_repo, const char *dest_repo)
423423
{
424424
if (option_shared) {
425425
struct strbuf alt = STRBUF_INIT;
426-
strbuf_addf(&alt, "%s/objects", src_repo);
426+
get_common_dir(&alt, src_repo);
427+
strbuf_addstr(&alt, "/objects");
427428
add_to_alternates_file(alt.buf);
428429
strbuf_release(&alt);
429430
} else {

t/t2025-worktree-add.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,10 @@ test_expect_success 'local clone from linked checkout' '
198198
( cd here-clone && git fsck )
199199
'
200200

201+
test_expect_success 'local clone --shared from linked checkout' '
202+
git -C bare worktree add --detach ../baretree &&
203+
git clone --local --shared baretree bare-clone &&
204+
grep /bare/ bare-clone/.git/objects/info/alternates
205+
'
206+
201207
test_done

0 commit comments

Comments
 (0)