Skip to content

Commit f7d61c4

Browse files
pks-tgitster
authored andcommitted
config: don't depend on the_repository with branch conditions
When computing branch "includeIf" conditions we use `the_repository` to obtain the main ref store. We really shouldn't depend on this global repository though, but should instead use the repository that is being passed to us via `struct config_include_data`. Otherwise, when parsing configuration of e.g. submodules, we may end up evaluating the condition the via the wrong refdb. Fix this. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c2ba4e3 commit f7d61c4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

config.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,14 @@ static int include_by_gitdir(const struct key_value_info *kvi,
300300
return ret;
301301
}
302302

303-
static int include_by_branch(const char *cond, size_t cond_len)
303+
static int include_by_branch(struct config_include_data *data,
304+
const char *cond, size_t cond_len)
304305
{
305306
int flags;
306307
int ret;
307308
struct strbuf pattern = STRBUF_INIT;
308-
const char *refname = !the_repository->gitdir ?
309-
NULL : refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
309+
const char *refname = (!data->repo || !data->repo->gitdir) ?
310+
NULL : refs_resolve_ref_unsafe(get_main_ref_store(data->repo),
310311
"HEAD", 0, NULL, &flags);
311312
const char *shortname;
312313

@@ -406,7 +407,7 @@ static int include_condition_is_true(const struct key_value_info *kvi,
406407
else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
407408
return include_by_gitdir(kvi, opts, cond, cond_len, 1);
408409
else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
409-
return include_by_branch(cond, cond_len);
410+
return include_by_branch(inc, cond, cond_len);
410411
else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond,
411412
&cond_len))
412413
return include_by_remote_url(inc, cond, cond_len);

0 commit comments

Comments
 (0)