aboutsummaryrefslogtreecommitdiffstats
path: root/config.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-09-30 16:16:17 -0700
committerJunio C Hamano <gitster@pobox.com>2024-09-30 16:16:17 -0700
commit92198dd33575e1569e10814f144fe0256c88cced (patch)
tree813c84e18ad7fb2b5245de777eb980e00b7a4375 /config.c
parentMerge branch 'ds/background-maintenance-with-credential' (diff)
parentconfig: fix evaluating "onbranch" with nonexistent git dir (diff)
downloadgit-92198dd33575e1569e10814f144fe0256c88cced.tar.gz
git-92198dd33575e1569e10814f144fe0256c88cced.zip
Merge branch 'ps/includeif-onbranch-cornercase-fix'
"git --git-dir=nowhere cmd" failed to properly notice that it wasn't in any repository while processing includeIf.onbranch configuration and instead crashed. * ps/includeif-onbranch-cornercase-fix: config: fix evaluating "onbranch" with nonexistent git dir t1305: exercise edge cases of "onbranch" includes
Diffstat (limited to 'config.c')
-rw-r--r--config.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/config.c b/config.c
index 1266eab086..a11bb85da3 100644
--- a/config.c
+++ b/config.c
@@ -306,13 +306,16 @@ static int include_by_branch(struct config_include_data *data,
int flags;
int ret;
struct strbuf pattern = STRBUF_INIT;
- const char *refname = (!data->repo || !data->repo->gitdir) ?
- NULL : refs_resolve_ref_unsafe(get_main_ref_store(data->repo),
- "HEAD", 0, NULL, &flags);
- const char *shortname;
+ const char *refname, *shortname;
- if (!refname || !(flags & REF_ISSYMREF) ||
- !skip_prefix(refname, "refs/heads/", &shortname))
+ if (!data->repo || data->repo->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
+ return 0;
+
+ refname = refs_resolve_ref_unsafe(get_main_ref_store(data->repo),
+ "HEAD", 0, NULL, &flags);
+ if (!refname ||
+ !(flags & REF_ISSYMREF) ||
+ !skip_prefix(refname, "refs/heads/", &shortname))
return 0;
strbuf_add(&pattern, cond, cond_len);