From: Junio C Hamano <gitster@pobox.com>
To: Matheus Tavares <matheus.bernardino@usp.br>
Cc: git@vger.kernel.org, peff@peff.net
Subject: Re: [PATCH] config: complain about --worktree outside of a git repo
Date: Wed, 09 Sep 2020 12:47:30 -0700 [thread overview]
Message-ID: <xmqqeenavijx.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <3dfd33eda3f9cbd0d87ba7bb31f4501aa7b8b8a8.1599657308.git.matheus.bernardino@usp.br> (Matheus Tavares's message of "Wed, 9 Sep 2020 10:16:08 -0300")
Matheus Tavares <matheus.bernardino@usp.br> writes:
> Running `git config --worktree` outside of a git repository hits a BUG()
> when trying to enumerate the worktrees. Let's catch this error earlier
> and die() with a friendlier message.
>
> Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
> ---
> builtin/config.c | 12 ++++++++----
> t/t1300-config.sh | 13 ++++++++-----
> 2 files changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/builtin/config.c b/builtin/config.c
> index 5e39f61885..53e411d68a 100644
> --- a/builtin/config.c
> +++ b/builtin/config.c
> @@ -628,11 +628,15 @@ int cmd_config(int argc, const char **argv, const char *prefix)
> usage_builtin_config();
> }
>
> - if (use_local_config && nongit)
> - die(_("--local can only be used inside a git repository"));
> + if (nongit) {
> + if (use_local_config)
> + die(_("--local can only be used inside a git repository"));
> + if (given_config_source.blob)
> + die(_("--blob can only be used inside a git repository"));
> + if (use_worktree_config)
> + die(_("--worktree can only be used inside a git repository"));
>
> - if (given_config_source.blob && nongit)
> - die(_("--blob can only be used inside a git repository"));
> + }
OK. The updated structure makes it more obvious that we handle
three special cases. Good jobs.
Thanks.
>
> if (given_config_source.file &&
> !strcmp(given_config_source.file, "-")) {
> diff --git a/t/t1300-config.sh b/t/t1300-config.sh
> index 97ebfe1f9d..825d9a184f 100755
> --- a/t/t1300-config.sh
> +++ b/t/t1300-config.sh
> @@ -1836,11 +1836,14 @@ test_expect_success '--show-scope with --show-origin' '
> test_cmp expect output
> '
>
> -test_expect_success '--local requires a repo' '
> - # we expect 128 to ensure that we do not simply
> - # fail to find anything and return code "1"
> - test_expect_code 128 nongit git config --local foo.bar
> -'
> +for opt in --local --worktree
> +do
> + test_expect_success "$opt requires a repo" '
> + # we expect 128 to ensure that we do not simply
> + # fail to find anything and return code "1"
> + test_expect_code 128 nongit git config $opt foo.bar
> + '
> +done
>
> cat >.git/config <<-\EOF &&
> [core]
prev parent reply other threads:[~2020-09-09 19:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 13:16 [PATCH] config: complain about --worktree outside of a git repo Matheus Tavares
2020-09-09 19:47 ` 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqeenavijx.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=matheus.bernardino@usp.br \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).