{"thread":{"id":"56393","subject":"[PATCH] test-lib: set GIT_CEILING_DIRECTORIES to protect the surrounding repository","startedAt":"2021-08-28T12:13:36Z","lastAt":"2021-09-01T04:58:54Z","messageCount":6,"participants":["SZEDER Gábor","Carlo Arenas","Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"434016","messageId":"20210828121329.1971762-1-szeder.dev@gmail.com","threadId":"56393","inReplyTo":null,"subject":"[PATCH] test-lib: set GIT_CEILING_DIRECTORIES to protect the surrounding repository","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2021-08-28T12:13:29Z","receivedAt":"2021-08-28T12:13:36Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Every once in a while a test somehow manages to escape from its trash\ndirectory and modifies the surrounding repository, whether because of\na bug in git itself, a bug in a test [1], or e.g. when trying to run\ntests with a shell that is, in general, unable to run our tests [2].\n\nSet GIT_CEILING_DIRECTORIES=\"$GIT_BUILD_DIR\" as an additional safety\nmeasure to protect the surrounding repository at least from\nmodifications by git commands executed in the tests (though it won't\nsave us from regular shell commands, e.g. 'cd .. && rm -f ...').\n\n[1] e.g. https://public-inbox.org/git/20210423051255.GD2947267@szeder.dev\n[2] $ git symbolic-ref HEAD\n    refs/heads/master\n    $ ksh ./t2011-checkout-invalid-head.sh\n    [... a lot of \"not ok\" ...]\n    $ git symbolic-ref HEAD\n    refs/heads/other\n\n    (In short: 'ksh' doesn't support the 'local' builtin command,\n    which is used by 'test_oid', causing it to return with error\n    whenever called, leaving ZERO_OID set to empty, so when 'checkout\n    main from invalid HEAD' runs 'echo $ZERO_OID >.git/HEAD' writes a\n    corrupt (not invalid) HEAD, and subsequent git commands don't\n    recognize the repository in the trash directory anymore, but\n    operate on the surrounding repo.)\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n t/test-lib.sh | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex abcfbed6d6..a1e0182c2f 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -1343,7 +1343,8 @@ fi\n GIT_TEMPLATE_DIR=\"$GIT_BUILD_DIR\"/templates/blt\n GIT_CONFIG_NOSYSTEM=1\n GIT_ATTR_NOSYSTEM=1\n-export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM\n+GIT_CEILING_DIRECTORIES=\"$GIT_BUILD_DIR\"\n+export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES\n \n if test -z \"$GIT_TEST_CMP\"\n then\n-- \n2.33.0.358.g803110d36e\n\n"},{"id":"434021","messageId":"CAPUEspg43gxRiVydtaYdM06ObQGYUVn6oThjg1VTR+EfsxRVjA@mail.gmail.com","threadId":"56393","inReplyTo":"20210828121329.1971762-1-szeder.dev@gmail.com","subject":"Re: [PATCH] test-lib: set GIT_CEILING_DIRECTORIES to protect the surrounding repository","fromName":"Carlo Arenas","fromEmail":"carenas@gmail.com","sentAt":"2021-08-28T19:56:24Z","receivedAt":"2021-08-28T19:56:40Z","isPatch":true,"sender":{"key":"carenas@gmail.com","avatar":"https://avatars.githubusercontent.com/u/76036?v=4"},"body":"On Sat, Aug 28, 2021 at 5:15 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:\n> diff --git a/t/test-lib.sh b/t/test-lib.sh\n> index abcfbed6d6..a1e0182c2f 100644\n> --- a/t/test-lib.sh\n> +++ b/t/test-lib.sh\n> @@ -1343,7 +1343,8 @@ fi\n>  GIT_TEMPLATE_DIR=\"$GIT_BUILD_DIR\"/templates/blt\n>  GIT_CONFIG_NOSYSTEM=1\n>  GIT_ATTR_NOSYSTEM=1\n> -export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM\n> +GIT_CEILING_DIRECTORIES=\"$GIT_BUILD_DIR\"\n\nthis wouldn't work as expected with --root and would be IMHO safer\nanyway if using instead\n\n  GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\"\n\nCarlo\n"},{"id":"434023","messageId":"20210829091546.GH2257957@szeder.dev","threadId":"56393","inReplyTo":"CAPUEspg43gxRiVydtaYdM06ObQGYUVn6oThjg1VTR+EfsxRVjA@mail.gmail.com","subject":"Re: [PATCH] test-lib: set GIT_CEILING_DIRECTORIES to protect the surrounding repository","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2021-08-29T09:15:46Z","receivedAt":"2021-08-29T09:15:52Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Sat, Aug 28, 2021 at 12:56:24PM -0700, Carlo Arenas wrote:\n> On Sat, Aug 28, 2021 at 5:15 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:\n> > diff --git a/t/test-lib.sh b/t/test-lib.sh\n> > index abcfbed6d6..a1e0182c2f 100644\n> > --- a/t/test-lib.sh\n> > +++ b/t/test-lib.sh\n> > @@ -1343,7 +1343,8 @@ fi\n> >  GIT_TEMPLATE_DIR=\"$GIT_BUILD_DIR\"/templates/blt\n> >  GIT_CONFIG_NOSYSTEM=1\n> >  GIT_ATTR_NOSYSTEM=1\n> > -export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM\n> > +GIT_CEILING_DIRECTORIES=\"$GIT_BUILD_DIR\"\n> \n> this wouldn't work as expected with --root and would be IMHO safer\n> anyway if using instead\n> \n>   GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\"\n\nThanks, I completely forgot about '--root'.\n\n"},{"id":"434024","messageId":"20210829092536.2582899-1-szeder.dev@gmail.com","threadId":"56393","inReplyTo":"20210828121329.1971762-1-szeder.dev@gmail.com","subject":"[PATCH v2] test-lib: set GIT_CEILING_DIRECTORIES to protect the surrounding repository","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2021-08-29T09:25:36Z","receivedAt":"2021-08-29T09:25:45Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Every once in a while a test somehow manages to escape from its trash\ndirectory and modifies the surrounding repository, whether because of\na bug in git itself, a bug in a test [1], or e.g. when trying to run\ntests with a shell that is, in general, unable to run our tests [2].\n\nSet GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\" as an additional\nsafety measure to protect the surrounding repository at least from\nmodifications by git commands executed in the tests (assuming that\nhandling of ceiling directories during repository discovery is not\nbroken, and, of course, it won't save us from regular shell commands,\ne.g. 'cd .. && rm -f ...').\n\n[1] e.g. https://public-inbox.org/git/20210423051255.GD2947267@szeder.dev\n[2] $ git symbolic-ref HEAD\n    refs/heads/master\n    $ ksh ./t2011-checkout-invalid-head.sh\n    [... a lot of \"not ok\" ...]\n    $ git symbolic-ref HEAD\n    refs/heads/other\n\n    (In short: 'ksh' doesn't support the 'local' builtin command,\n    which is used by 'test_oid', causing it to return with error\n    whenever it's called, leaving ZERO_OID set to empty, so when the\n    test 'checkout main from invalid HEAD' runs 'echo $ZERO_OID\n    >.git/HEAD' it writes a corrupt (not invalid) HEAD, and subsequent\n    git commands don't recognize the repository in the trash directory\n    anymore, but operate on the surrounding repo.)\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\nChanges since v1:\n - Set \"$TRASH_DIRECTORY/..\" instead of $GIT_BUILD_DIR.\n - Minor commit message tweaks.\n\n t/test-lib.sh | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex abcfbed6d6..fc1e521519 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -1343,7 +1343,8 @@ fi\n GIT_TEMPLATE_DIR=\"$GIT_BUILD_DIR\"/templates/blt\n GIT_CONFIG_NOSYSTEM=1\n GIT_ATTR_NOSYSTEM=1\n-export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM\n+GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\"\n+export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES\n \n if test -z \"$GIT_TEST_CMP\"\n then\n-- \n2.33.0.361.g6f8e582daa\n\n"},{"id":"434288","messageId":"87pmttwuaw.fsf@evledraar.gmail.com","threadId":"56393","inReplyTo":"20210829092536.2582899-1-szeder.dev@gmail.com","subject":"Re: [PATCH v2] test-lib: set GIT_CEILING_DIRECTORIES to protect the surrounding repository","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-08-31T14:40:39Z","receivedAt":"2021-08-31T14:41:34Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sun, Aug 29 2021, SZEDER Gábor wrote:\n\n> Every once in a while a test somehow manages to escape from its trash\n> directory and modifies the surrounding repository, whether because of\n> a bug in git itself, a bug in a test [1], or e.g. when trying to run\n> tests with a shell that is, in general, unable to run our tests [2].\n>\n> Set GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\" as an additional\n> safety measure to protect the surrounding repository at least from\n> modifications by git commands executed in the tests (assuming that\n> handling of ceiling directories during repository discovery is not\n> broken, and, of course, it won't save us from regular shell commands,\n> e.g. 'cd .. && rm -f ...').\n>\n> [1] e.g. https://public-inbox.org/git/20210423051255.GD2947267@szeder.dev\n> [2] $ git symbolic-ref HEAD\n>     refs/heads/master\n>     $ ksh ./t2011-checkout-invalid-head.sh\n>     [... a lot of \"not ok\" ...]\n>     $ git symbolic-ref HEAD\n>     refs/heads/other\n>\n>     (In short: 'ksh' doesn't support the 'local' builtin command,\n>     which is used by 'test_oid', causing it to return with error\n>     whenever it's called, leaving ZERO_OID set to empty, so when the\n>     test 'checkout main from invalid HEAD' runs 'echo $ZERO_OID\n>     >.git/HEAD' it writes a corrupt (not invalid) HEAD, and subsequent\n>     git commands don't recognize the repository in the trash directory\n>     anymore, but operate on the surrounding repo.)\n>\n> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n> ---\n> Changes since v1:\n>  - Set \"$TRASH_DIRECTORY/..\" instead of $GIT_BUILD_DIR.\n>  - Minor commit message tweaks.\n>\n>  t/test-lib.sh | 3 ++-\n>  1 file changed, 2 insertions(+), 1 deletion(-)\n>\n> diff --git a/t/test-lib.sh b/t/test-lib.sh\n> index abcfbed6d6..fc1e521519 100644\n> --- a/t/test-lib.sh\n> +++ b/t/test-lib.sh\n> @@ -1343,7 +1343,8 @@ fi\n>  GIT_TEMPLATE_DIR=\"$GIT_BUILD_DIR\"/templates/blt\n>  GIT_CONFIG_NOSYSTEM=1\n>  GIT_ATTR_NOSYSTEM=1\n> -export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM\n> +GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\"\n> +export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES\n>  \n>  if test -z \"$GIT_TEST_CMP\"\n>  then\n\nFor what it's worth I'm very happy with this, and have been running this\nin my own daily build of git, I've occasionally ran into e.g. needing to\nmanually clean up my own git.git's config file because some test escaped\nits trash directory.\n"},{"id":"434385","messageId":"20210901045845.GA76263@szeder.dev","threadId":"56393","inReplyTo":"87pmttwuaw.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2] test-lib: set GIT_CEILING_DIRECTORIES to protect the surrounding repository","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2021-09-01T04:58:45Z","receivedAt":"2021-09-01T04:58:54Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Aug 31, 2021 at 04:40:39PM +0200, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Sun, Aug 29 2021, SZEDER Gábor wrote:\n> \n> > Every once in a while a test somehow manages to escape from its trash\n> > directory and modifies the surrounding repository, whether because of\n> > a bug in git itself, a bug in a test [1], or e.g. when trying to run\n> > tests with a shell that is, in general, unable to run our tests [2].\n> >\n> > Set GIT_CEILING_DIRECTORIES=\"$TRASH_DIRECTORY/..\" as an additional\n> > safety measure to protect the surrounding repository at least from\n> > modifications by git commands executed in the tests (assuming that\n> > handling of ceiling directories during repository discovery is not\n> > broken, and, of course, it won't save us from regular shell commands,\n> > e.g. 'cd .. && rm -f ...').\n\n> For what it's worth I'm very happy with this, and have been running this\n> in my own daily build of git, I've occasionally ran into e.g. needing to\n> manually clean up my own git.git's config file because some test escaped\n> its trash directory.\n\nThanks, that's a good point.\n\nAfter a test escapes from its trash directory I routinely check the\ncontent of the work tree and look for stray refs, but it never occured\nto me that I should look at the config, too.  And indeed, at the\nbottom of .git/config there are two config variables that I don't\nremember setting (actually don't even know what they do).\n\n"}]}