Merge branch 'js/early-config-with-onbranch'
authorJunio C Hamano <gitster@pobox.com>
Fri, 2 Aug 2019 20:12:02 +0000 (13:12 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Aug 2019 20:12:02 +0000 (13:12 -0700)
The recently added [includeif "onbranch:branch"] feature does not
work well with an early config mechanism, as it attempts to find
out what branch we are on before we even haven't located the git
repository. The inclusion during early config scan is ignored to
work around this issue.

* js/early-config-with-onbranch:
config: work around bug with includeif:onbranch and early config

config.c
t/t1309-early-config.sh
index ed7f58e0fcf221733165f3dd6a9d095d727a0a5e..3900e4947be92b916ed9b531eb455e8f856105dc 100644 (file)
--- a/config.c
+++ b/config.c
@@ -275,7 +275,8 @@ static int include_by_branch(const char *cond, size_t cond_len)
        int flags;
        int ret;
        struct strbuf pattern = STRBUF_INIT;
-       const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, &flags);
+       const char *refname = !the_repository || !the_repository->gitdir ?
+               NULL : resolve_ref_unsafe("HEAD", 0, NULL, &flags);
        const char *shortname;
 
        if (!refname || !(flags & REF_ISSYMREF) ||
index 413642aa5672800d1b7be448bc97d175add07ee4..0c37e7180d1cde57d49c12deb28239c509d9207d 100755 (executable)
@@ -89,4 +89,9 @@ test_expect_failure 'ignore .git/ with invalid config' '
        test_with_config "["
 '
 
+test_expect_success 'early config and onbranch' '
+       echo "[broken" >broken &&
+       test_with_config "[includeif \"onbranch:refs/heads/master\"]path=../broken"
+'
+
 test_done