{"thread":{"id":"57023","subject":"t7900 failures when $HOME is symlinked","startedAt":"2021-12-03T14:56:45Z","lastAt":"2021-12-05T10:02:44Z","messageCount":5,"participants":["Philippe Blain","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"443000","messageId":"4cf14040-c8e1-0f75-0ec4-fd8cf6bed0a5@gmail.com","threadId":"57023","inReplyTo":null,"subject":"t7900 failures when $HOME is symlinked","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2021-12-03T14:56:28Z","receivedAt":"2021-12-03T14:56:45Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Stolee,\n\nI noticed two failures, t7900.32 and t7900.36, on a system where\n$HOME is symlinked, i.e.\n\n     $ cd $HOME && pwd\n     /home/me\n     $ pwd -P\n     /some/other/path/me\n\nThese two tests use 'pfx = $(cd $HOME && pwd)', so $pfx is '/home/me',\nbut the actual path that gets written by Git is canonicalized, i.e.\n'/some/other/path/me'. I think a simple fix would be to use 'pwd -P'\ninstead, which fixes it for me.\n\nCheers,\n\nPhilippe.\n"},{"id":"443010","messageId":"xmqq1r2tty13.fsf@gitster.g","threadId":"57023","inReplyTo":"4cf14040-c8e1-0f75-0ec4-fd8cf6bed0a5@gmail.com","subject":"Re: t7900 failures when $HOME is symlinked","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-03T17:10:16Z","receivedAt":"2021-12-03T17:10:33Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philippe Blain <levraiphilippeblain@gmail.com> writes:\n\n> Hi Stolee,\n>\n> I noticed two failures, t7900.32 and t7900.36, on a system where\n> $HOME is symlinked, i.e.\n>\n>     $ cd $HOME && pwd\n>     /home/me\n>     $ pwd -P\n>     /some/other/path/me\n>\n> These two tests use 'pfx = $(cd $HOME && pwd)', so $pfx is '/home/me',\n> but the actual path that gets written by Git is canonicalized, i.e.\n> '/some/other/path/me'. I think a simple fix would be to use 'pwd -P'\n> instead, which fixes it for me.\n\nCurious.  Your personal HOME shouldn't have much to do with the\ntests, but obviously it can indirectly affect the outcome because it\naffects where you place your repository.\n\nHOME during tests is set in t/test-lib.sh, based on where\nTRASH_DIRECTORY is, and the latter is often derived from\nTEST_OUTPUT_DIRECTORY (unless --root is given), which comes from\nTEST_DIRECTORY and it is set like so:\n\n    # Test the binaries we have just built.  The tests are kept in\n    # t/ subdirectory and are run in 'trash directory' subdirectory.\n    if test -z \"$TEST_DIRECTORY\"\n    then\n            # We allow tests to override this, in case they want to run tests\n            # outside of t/, e.g. for running tests on the test library\n            # itself.\n            TEST_DIRECTORY=$(pwd)\n    else\n            # ensure that TEST_DIRECTORY is an absolute path so that it\n            # is valid even if the current working directory is changed\n            TEST_DIRECTORY=$(cd \"$TEST_DIRECTORY\" && pwd) || exit 1\n    fi\n    if test -z \"$TEST_OUTPUT_DIRECTORY\"\n    then\n            # Similarly, override this to store the test-results subdir\n            # elsewhere\n            TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY\n    fi\n    GIT_BUILD_DIR=\"$TEST_DIRECTORY\"/..\n\nIf you want to do $(pwd -P) somewhere, isn't it that one you want to\nchange to avoid similar problems in any code, including the ones\nthat are not yet written, that uses $(pwd)?\n\nThis is a tangent, but I think I found a small bug while spelunking\nfor the origin of HOME during tests.\n\n * We parse out --root=* option like this:\n\n\t--root=*)\n\t\troot=${opt#--*=} ;;\n\n   Notice that we do not require it to be absolute path.\n\n * TRASH_DIRECTORY is originally set to \"trash directory.\" with a\n   suffix to make it unique across test scripts, but it immediately\n   gets turned into an absolute path by doing this:\n\n        test -n \"$root\" && TRASH_DIRECTORY=\"$root/$TRASH_DIRECTORY\"\n        case \"$TRASH_DIRECTORY\" in\n        /*) ;; # absolute path is good\n         *) TRASH_DIRECTORY=\"$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY\" ;;\n        esac\n\n   I notice that a root that is not absolute is silently lost during\n   this process.\n\n   TEST_OUTPUT_DIRECTORY is set to TEST_DIRECTORY that comes from\n   $(pwd) we saw earlier, or TEST_OUTPUT_DIRECTORY_OVERRIDE, which\n   is also set to $(pwd) elsewhere, so the case statement does make\n   it absolute in the end.  It just loses --root=* without complaint\n   which is what I found iffy.\n\n"},{"id":"443013","messageId":"YapW/CfjFiPvsVbj@coredump.intra.peff.net","threadId":"57023","inReplyTo":"xmqq1r2tty13.fsf@gitster.g","subject":"Re: t7900 failures when $HOME is symlinked","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-12-03T17:42:20Z","receivedAt":"2021-12-03T17:42:23Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Dec 03, 2021 at 09:10:16AM -0800, Junio C Hamano wrote:\n\n>  * TRASH_DIRECTORY is originally set to \"trash directory.\" with a\n>    suffix to make it unique across test scripts, but it immediately\n>    gets turned into an absolute path by doing this:\n> \n>         test -n \"$root\" && TRASH_DIRECTORY=\"$root/$TRASH_DIRECTORY\"\n>         case \"$TRASH_DIRECTORY\" in\n>         /*) ;; # absolute path is good\n>          *) TRASH_DIRECTORY=\"$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY\" ;;\n>         esac\n> \n>    I notice that a root that is not absolute is silently lost during\n>    this process.\n> \n>    TEST_OUTPUT_DIRECTORY is set to TEST_DIRECTORY that comes from\n>    $(pwd) we saw earlier, or TEST_OUTPUT_DIRECTORY_OVERRIDE, which\n>    is also set to $(pwd) elsewhere, so the case statement does make\n>    it absolute in the end.  It just loses --root=* without complaint\n>    which is what I found iffy.\n\nI don't think it's lost. It becomes part of $TRASH_DIRECTORY in the\nfirst line, so the final line which prepends $TEST_OUTPUT_DIRECTORY\nmakes it relative to that. E.g.:\n\n  $ cd t\n  $ ./t0000-basic.sh --root=foo --debug\n  [...]\n  $ ls foo\n  trash directory.t0000-basic/\n\nI don't recall planning that in particular (there is not much point in\nusing it unless you are pointing outside the repo, though I guess you\ncould use ../../../foo or similar). But I think it has always worked\nthat way, since f423ef5f2b (tests: allow user to specify trash directory\nlocation, 2009-08-09). It was perhaps a little easier to see back then\nwhen the intermediate \"$test\" variable was not the final one.\n\n-Peff\n"},{"id":"443046","messageId":"837581db-b3d7-2a73-9a61-7c40f77f264b@gmail.com","threadId":"57023","inReplyTo":"xmqq1r2tty13.fsf@gitster.g","subject":"Re: t7900 failures when $HOME is symlinked","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2021-12-03T22:40:37Z","receivedAt":"2021-12-03T22:40:40Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Junio,\n\nLe 2021-12-03 à 12:10, Junio C Hamano a écrit :\n> Philippe Blain <levraiphilippeblain@gmail.com> writes:\n> \n>> Hi Stolee,\n>>\n>> I noticed two failures, t7900.32 and t7900.36, on a system where\n>> $HOME is symlinked, i.e.\n>>\n>>      $ cd $HOME && pwd\n>>      /home/me\n>>      $ pwd -P\n>>      /some/other/path/me\n>>\n>> These two tests use 'pfx = $(cd $HOME && pwd)', so $pfx is '/home/me',\n>> but the actual path that gets written by Git is canonicalized, i.e.\n>> '/some/other/path/me'. I think a simple fix would be to use 'pwd -P'\n>> instead, which fixes it for me.\n> \n> Curious.  Your personal HOME shouldn't have much to do with the\n> tests, but obviously it can indirectly affect the outcome because it\n> affects where you place your repository.\n\nIndeed, the source code was cloned somewhere in my HOME.\n\n> HOME during tests is set in t/test-lib.sh, based on where\n> TRASH_DIRECTORY is, and the latter is often derived from\n> TEST_OUTPUT_DIRECTORY (unless --root is given), which comes from\n> TEST_DIRECTORY and it is set like so:\n> \n>      # Test the binaries we have just built.  The tests are kept in\n>      # t/ subdirectory and are run in 'trash directory' subdirectory.\n>      if test -z \"$TEST_DIRECTORY\"\n>      then\n>              # We allow tests to override this, in case they want to run tests\n>              # outside of t/, e.g. for running tests on the test library\n>              # itself.\n>              TEST_DIRECTORY=$(pwd)\n>      else\n>              # ensure that TEST_DIRECTORY is an absolute path so that it\n>              # is valid even if the current working directory is changed\n>              TEST_DIRECTORY=$(cd \"$TEST_DIRECTORY\" && pwd) || exit 1\n>      fi\n>      if test -z \"$TEST_OUTPUT_DIRECTORY\"\n>      then\n>              # Similarly, override this to store the test-results subdir\n>              # elsewhere\n>              TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY\n>      fi\n>      GIT_BUILD_DIR=\"$TEST_DIRECTORY\"/..\n> \n> If you want to do $(pwd -P) somewhere, isn't it that one you want to\n> change to avoid similar problems in any code, including the ones\n> that are not yet written, that uses $(pwd)?\n\nIndeed, that works and it looks like a more robust fix.\n\nThanks,\n\nPhilippe.\n"},{"id":"443103","messageId":"xmqqy24zl681.fsf@gitster.g","threadId":"57023","inReplyTo":"YapW/CfjFiPvsVbj@coredump.intra.peff.net","subject":"Re: t7900 failures when $HOME is symlinked","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-05T10:02:38Z","receivedAt":"2021-12-05T10:02:44Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> I don't think it's lost. It becomes part of $TRASH_DIRECTORY in the\n> first line, so the final line which prepends $TEST_OUTPUT_DIRECTORY\n> makes it relative to that. E.g.:\n>\n>   $ cd t\n>   $ ./t0000-basic.sh --root=foo --debug\n>   [...]\n>   $ ls foo\n>   trash directory.t0000-basic/\n\nAh, OK.  Thanks.\n"}]}