git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Make setup_git_env() resolve .git file when $GIT_DIR is not specified

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 3, 2013, 18:14 UTC
Message-ID
<xmqqr4d5srg7.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1377911054-20086-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 13 quoted lines
> This makes reinitializing on a .git file repository work.
>
> This is probably the only case that setup_git_env() (via
> set_git_dir()) is called on a .git file. Other cases in
> setup_git_dir_gently() and enter_repo() both cover .git file case
> explicitly because they need to verify the target repo is valid.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> Reported-by: Ximin Luo <infinity0@gmx.com>
> ---
>  Slight change in the patch to xstrdup(gitfile) because read_gitfile
>  returns a static buffer.
Thanks for fixing it up.  Will queue.
Show 43 quoted lines
>
>  environment.c   | 9 ++++-----
>  t/t0001-init.sh | 4 ++++
>  2 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/environment.c b/environment.c
> index 5398c36..378254c 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -123,14 +123,13 @@ static char *expand_namespace(const char *raw_namespace)
>  
>  static void setup_git_env(void)
>  {
> +	const char *gitfile;
> +
>  	git_dir = getenv(GIT_DIR_ENVIRONMENT);
> -	git_dir = git_dir ? xstrdup(git_dir) : NULL;
> -	if (!git_dir) {
> -		git_dir = read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
> -		git_dir = git_dir ? xstrdup(git_dir) : NULL;
> -	}
>  	if (!git_dir)
>  		git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
> +	gitfile = read_gitfile(git_dir);
> +	git_dir = xstrdup(gitfile ? gitfile : git_dir);
>  	git_object_dir = getenv(DB_ENVIRONMENT);
>  	if (!git_object_dir) {
>  		git_object_dir = xmalloc(strlen(git_dir) + 9);
> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> index ad66410..9fb582b 100755
> --- a/t/t0001-init.sh
> +++ b/t/t0001-init.sh
> @@ -379,6 +379,10 @@ test_expect_success 'init with separate gitdir' '
>  	test -d realgitdir/refs
>  '
>  
> +test_expect_success 're-init on .git file' '
> +	( cd newdir && git init )
> +'
> +
>  test_expect_success 're-init to update git link' '
>  	(
>  	cd newdir &&
Previous: Nguyễn Thái Ngọc Duy
Message 5 of 5 in “[BUG] git-init does not respect existing separate-git-dir”
  1. Ximin LuoAug 29, 2013
  2. Duy NguyenAug 29, 2013
  3. Junio C HamanoAug 29, 2013
  4. Make setup_git_env() resolve .git file when $GIT_DIR is not specifiedNguyễn Thái Ngọc Duy, Aug 31, 2013
  5. Junio C HamanoSep 3, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.