config: complain about --worktree outside of a git repo

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Matheus Tavares
2020-09-09 10:16:08 -03:00
committed by Junio C Hamano
parent 47ae905ffb
commit 378fe5fc3d
2 changed files with 16 additions and 9 deletions

View File

@ -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"));
}
if (given_config_source.file &&
!strcmp(given_config_source.file, "-")) {