Skip to content

Commit 22932d9

Browse files
peffgitster
authored andcommitted
config: stop checking whether the_repository is NULL
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 85fe0e8 (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>
1 parent 5732f2b commit 22932d9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static int include_by_branch(const char *cond, size_t cond_len)
275275
int flags;
276276
int ret;
277277
struct strbuf pattern = STRBUF_INIT;
278-
const char *refname = !the_repository || !the_repository->gitdir ?
278+
const char *refname = !the_repository->gitdir ?
279279
NULL : resolve_ref_unsafe("HEAD", 0, NULL, &flags);
280280
const char *shortname;
281281

t/t1309-early-config.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,9 @@ test_expect_success 'early config and onbranch' '
9494
test_with_config "[includeif \"onbranch:master\"]path=../broken"
9595
'
9696

97+
test_expect_success 'onbranch config outside of git repo' '
98+
test_config_global includeIf.onbranch:master.path non-existent &&
99+
nongit git help
100+
'
101+
97102
test_done

0 commit comments

Comments
 (0)