Git fork

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

+49 -6
+9 -6
config.c
··· 306 306 int flags; 307 307 int ret; 308 308 struct strbuf pattern = STRBUF_INIT; 309 - const char *refname = (!data->repo || !data->repo->gitdir) ? 310 - NULL : refs_resolve_ref_unsafe(get_main_ref_store(data->repo), 311 - "HEAD", 0, NULL, &flags); 312 - const char *shortname; 309 + const char *refname, *shortname; 310 + 311 + if (!data->repo || data->repo->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN) 312 + return 0; 313 313 314 - if (!refname || !(flags & REF_ISSYMREF) || 315 - !skip_prefix(refname, "refs/heads/", &shortname)) 314 + refname = refs_resolve_ref_unsafe(get_main_ref_store(data->repo), 315 + "HEAD", 0, NULL, &flags); 316 + if (!refname || 317 + !(flags & REF_ISSYMREF) || 318 + !skip_prefix(refname, "refs/heads/", &shortname)) 316 319 return 0; 317 320 318 321 strbuf_add(&pattern, cond, cond_len);
+40
t/t1305-config-include.sh
··· 357 357 grep "exceeded maximum include depth" stderr 358 358 ' 359 359 360 + test_expect_success 'onbranch with unborn branch' ' 361 + test_when_finished "rm -rf repo" && 362 + git init repo && 363 + ( 364 + cd repo && 365 + git config set includeIf.onbranch:"*".path config.inc && 366 + git config set -f .git/config.inc foo.bar baz && 367 + git config get foo.bar 368 + ) 369 + ' 370 + 371 + test_expect_success 'onbranch with detached HEAD' ' 372 + test_when_finished "rm -rf repo" && 373 + git init repo && 374 + ( 375 + cd repo && 376 + git config set "includeIf.onbranch:*.path" config.inc && 377 + git config set -f .git/config.inc foo.bar baz && 378 + test_commit initial && 379 + git switch --detach HEAD && 380 + test_must_fail git config get foo.bar 381 + ) 382 + ' 383 + 384 + test_expect_success 'onbranch without repository' ' 385 + test_when_finished "rm -f .gitconfig config.inc" && 386 + git config set -f .gitconfig "includeIf.onbranch:**.path" config.inc && 387 + git config set -f config.inc foo.bar baz && 388 + git config get foo.bar && 389 + test_must_fail nongit git config get foo.bar 390 + ' 391 + 392 + test_expect_success 'onbranch without repository but explicit nonexistent Git directory' ' 393 + test_when_finished "rm -f .gitconfig config.inc" && 394 + git config set -f .gitconfig "includeIf.onbranch:**.path" config.inc && 395 + git config set -f config.inc foo.bar baz && 396 + git config get foo.bar && 397 + test_must_fail nongit git --git-dir=nonexistent config get foo.bar 398 + ' 399 + 360 400 test_done