Message ID | 4aa88340132b03c9480c781cb5cb3c5b5513e944.1564602830.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Make the includeif:onbranch feature more robust | expand |
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes: > Let's work around this, simply by ignoring the `includeif.onbranch:` > setting when parsing the config when the ref store has not been > initialized (yet). Interesting chicken-and-egg problem. > Technically, there is a way to solve this properly: teach the refs > machinery to initialize the ref_store from a given gitdir/commondir pair > (which we _do_ have in the early config code path), and then use that in > `include_by_branch()`. This, however, is a pretty involved project, and > we're already in the feature freeze for Git v2.23.0. Postponing the proper fix to the next cycle (or later) is good.
diff --git a/config.c b/config.c index ed7f58e0fc..3900e4947b 100644 --- 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) || diff --git a/t/t1309-early-config.sh b/t/t1309-early-config.sh index 413642aa56..0c37e7180d 100755 --- a/t/t1309-early-config.sh +++ b/t/t1309-early-config.sh @@ -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