Message ID | 615df98339e9451bc237decea087716ca15d157d.1727171197.git.ps@pks.im (mailing list archive) |
---|---|
State | Accepted |
Commit | 9cc2590ab988a357ffe214ecffbe78cfac29da17 |
Headers | show |
Series | config: fix evaluating "onbranch" with nonexistent git dir | expand |
Patrick Steinhardt <ps@pks.im> writes: > +test_expect_success 'onbranch without repository' ' > + test_when_finished "rm -f .gitconfig config.inc" && > + git config set -f .gitconfig "includeIf.onbranch:**.path" config.inc && > + git config set -f config.inc foo.bar baz && This assumes that the $(pwd) is the $HOME; so .gitconfig is the per-user configuration that ought to apply everywhere; since includeIf.<condition>.path that is relative is relative to the including file, config.inc would be in cluded when the condition holds in $HOME/.gitconfig. OK. > + git config get foo.bar && This assumes that the $(pwd) that is $HOME is a valid repository, and checks if includeIf.onbranch works from within a repository. OK. > + test_must_fail nongit git config get foo.bar > +' > +test_expect_failure 'onbranch without repository but explicit nonexistent Git directory' ' > + test_when_finished "rm -f .gitconfig config.inc" && > + git config set -f .gitconfig "includeIf.onbranch:**.path" config.inc && > + git config set -f config.inc foo.bar baz && The same set-up. > + git config get foo.bar && > + test_must_fail nongit git --git-dir=nonexistent config get foo.bar It has to work when $(pwd) is outside a repository, but is "nongit" strictly necessary? IOW, even when we _could_ discover the top level of a git-controlled working tree, wouldn't presence of --git-dir that points at elsewhere make $(pwd) and the repository there irrelevant to the operation? I am not suggesting to just drop "nongit" from this test. I am wondering if this is better split into two tests, with and without "nongit" to test different situations. > +' > + > test_done Other than that, looks like good additions to the test coverage. Thanks.
diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh index 5cde79ef8c4..ad08db72308 100755 --- a/t/t1305-config-include.sh +++ b/t/t1305-config-include.sh @@ -357,4 +357,44 @@ test_expect_success 'include cycles are detected' ' grep "exceeded maximum include depth" stderr ' +test_expect_success 'onbranch with unborn branch' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + git config set includeIf.onbranch:"*".path config.inc && + git config set -f .git/config.inc foo.bar baz && + git config get foo.bar + ) +' + +test_expect_success 'onbranch with detached HEAD' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + git config set "includeIf.onbranch:*.path" config.inc && + git config set -f .git/config.inc foo.bar baz && + test_commit initial && + git switch --detach HEAD && + test_must_fail git config get foo.bar + ) +' + +test_expect_success 'onbranch without repository' ' + test_when_finished "rm -f .gitconfig config.inc" && + git config set -f .gitconfig "includeIf.onbranch:**.path" config.inc && + git config set -f config.inc foo.bar baz && + git config get foo.bar && + test_must_fail nongit git config get foo.bar +' + +test_expect_failure 'onbranch without repository but explicit nonexistent Git directory' ' + test_when_finished "rm -f .gitconfig config.inc" && + git config set -f .gitconfig "includeIf.onbranch:**.path" config.inc && + git config set -f config.inc foo.bar baz && + git config get foo.bar && + test_must_fail nongit git --git-dir=nonexistent config get foo.bar +' + test_done
Add a couple more tests for "onbranch" includes for several edge cases. All tests except for the last one pass, so for the most part this change really only aims to nail down behaviour of include conditionals further. Signed-off-by: Patrick Steinhardt <ps@pks.im> --- t/t1305-config-include.sh | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)