Subject: Re: [PATCH 1/3] init: correct re-initialization from a linked worktree

From: Junio C Hamano <[email-masked]>
Date: Thu, 08 Sep 2016 12:37:53 -0700

Nguyễn Thái Ngọc Duy  <[email-masked]> writes:

> When 'git init' is called from a linked worktree, '.git' dir as the main
> '.git' (i.e. $GIT_COMMON_DIR) and populate the whole repository skeleton
> in there. It does not harm anything (*) but it is still wrong.

-ECANNOTPARSE.  Did you mean "... worktree, we treat '.git' dir as
if it is the main '.git' ..." or something entirely different?

> diff --git a/builtin/init-db.c b/builtin/init-db.c
> index 3a45f0b..6d9552e 100644
> --- a/builtin/init-db.c
> +++ b/builtin/init-db.c
> @@ -138,7 +138,7 @@ static void copy_templates(const char *template_dir)
>  		goto close_free_return;
>  	}
>  
> -	strbuf_addstr(&path, get_git_dir());
> +	strbuf_addstr(&path, get_git_common_dir());
>  	strbuf_complete(&path, '/');
>  	copy_templates_1(&path, &template_path, dir);
>  close_free_return:
> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> index a6fdd5e..d64e5e3 100755
> --- a/t/t0001-init.sh
> +++ b/t/t0001-init.sh
> @@ -384,4 +384,19 @@ test_expect_success MINGW 'bare git dir not hidden' '
>  	! is_hidden newdir
>  '
>  
> +test_expect_success 're-init from a linked worktree' '
> +	git init main-worktree &&
> +	(
> +		cd main-worktree &&
> +		test_commit first &&
> +		git worktree add ../linked-worktree &&
> +		mv .git/info/exclude expected-exclude &&
> +		find .git/worktrees -print | sort >expected &&
> +		git -C ../linked-worktree init &&
> +		test_cmp expected-exclude .git/info/exclude &&
> +		find .git/worktrees -print | sort >actual &&
> +		test_cmp expected actual
> +	)
> +'
> +
>  test_done