config: stop checking whether the_repository is NULL
authorJeff King <peff@peff.net>
Tue, 6 Aug 2019 12:27:58 +0000 (08:27 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Aug 2019 20:09:01 +0000 (13:09 -0700)
Since the previous commit, our invariant that the_repository is never
NULL is restored, and we can stop being defensive in include_by_branch().

We can confirm the fix by showing that an onbranch config include will
not cause a segfault when run outside a git repository. I've put this in
t1309-early-config since it's related to the case added by 85fe0e800c
(config: work around bug with includeif:onbranch and early config,
2019-07-31), though technically the issue was with
read_very_early_config() and not read_early_config().

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c
t/t1309-early-config.sh
index 3900e4947be92b916ed9b531eb455e8f856105dc..cc637363bbae10f1b87b5b7ab0bd015e49cb56b8 100644 (file)
--- a/config.c
+++ b/config.c
@@ -275,7 +275,7 @@ static int include_by_branch(const char *cond, size_t cond_len)
        int flags;
        int ret;
        struct strbuf pattern = STRBUF_INIT;
-       const char *refname = !the_repository || !the_repository->gitdir ?
+       const char *refname = !the_repository->gitdir ?
                NULL : resolve_ref_unsafe("HEAD", 0, NULL, &flags);
        const char *shortname;
 
index eeb60e41437ddeaa99b48d16f9bafced65f8b8b0..3a0de0ddaa553e82b7db8594f4c45489237fb7db 100755 (executable)
@@ -94,4 +94,9 @@ test_expect_success 'early config and onbranch' '
        test_with_config "[includeif \"onbranch:master\"]path=../broken"
 '
 
+test_expect_success 'onbranch config outside of git repo' '
+       test_config_global includeIf.onbranch:master.path non-existent &&
+       nongit git help
+'
+
 test_done