]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: complain about --worktree outside of a git repo
authorMatheus Tavares <matheus.bernardino@usp.br>
Wed, 9 Sep 2020 13:16:08 +0000 (10:16 -0300)
committerJunio C Hamano <gitster@pobox.com>
Wed, 9 Sep 2020 19:47:47 +0000 (12:47 -0700)
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>
builtin/config.c
t/t1300-config.sh

index 5e39f6188542bb28cd859e52b883d13fcbd281fe..53e411d68afe631280e4386ba2782e66787b6a42 100644 (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, "-")) {
index 97ebfe1f9d5cea7b37d70d8f7069f00bb5045b8e..825d9a184fbbf4c14a7b6b5d98125947d3336666 100755 (executable)
@@ -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]