From: Junio C Hamano <gitster@pobox•com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail•com>
Cc: git@vger•kernel.org, Ximin Luo <infinity0@gmx•com>
Subject: Re: [PATCH] Make setup_git_env() resolve .git file when $GIT_DIR is not specified
Date: Tue, 03 Sep 2013 11:14:32 -0700 [thread overview]
Message-ID: <xmqqr4d5srg7.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1377911054-20086-1-git-send-email-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Sat, 31 Aug 2013 08:04:14 +0700")
Nguyễn Thái Ngọc Duy <pclouds@gmail•com> writes:
> 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.
>
> 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 &&
prev parent reply other threads:[~2013-09-03 18:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-29 12:39 [BUG] git-init does not respect existing separate-git-dir Ximin Luo
2013-08-29 13:04 ` Duy Nguyen
2013-08-29 17:12 ` Junio C Hamano
2013-08-31 1:04 ` [PATCH] Make setup_git_env() resolve .git file when $GIT_DIR is not specified Nguyễn Thái Ngọc Duy
2013-09-03 18:14 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqr4d5srg7.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=infinity0@gmx$(echo .)com \
--cc=pclouds@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox