git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: t7900 failures when $HOME is symlinked

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 3, 2021, 17:10 UTC
Message-ID
<xmqq1r2tty13.fsf@gitster.g>
In-Reply-To
<4cf14040-c8e1-0f75-0ec4-fd8cf6bed0a5@gmail.com>
Philippe Blain <levraiphilippeblain@gmail.com> writes:
Show 14 quoted lines
> Hi Stolee,
>
> I noticed two failures, t7900.32 and t7900.36, on a system where
> $HOME is symlinked, i.e.
>
>     $ cd $HOME && pwd
>     /home/me
>     $ pwd -P
>     /some/other/path/me
>
> These two tests use 'pfx = $(cd $HOME && pwd)', so $pfx is '/home/me',
> but the actual path that gets written by Git is canonicalized, i.e.
> '/some/other/path/me'. I think a simple fix would be to use 'pwd -P'
> instead, which fixes it for me.

Curious. Your personal HOME shouldn't have much to do with the tests, but obviously it can indirectly affect the outcome because it affects where you place your repository.

HOME during tests is set in t/test-lib.sh, based on where TRASH_DIRECTORY is, and the latter is often derived from TEST_OUTPUT_DIRECTORY (unless --root is given), which comes from TEST_DIRECTORY and it is set like so:

    # Test the binaries we have just built.  The tests are kept in
    # t/ subdirectory and are run in 'trash directory' subdirectory.
    if test -z "$TEST_DIRECTORY"
    then
            # We allow tests to override this, in case they want to run tests
            # outside of t/, e.g. for running tests on the test library
            # itself.
            TEST_DIRECTORY=$(pwd)
    else
            # ensure that TEST_DIRECTORY is an absolute path so that it
            # is valid even if the current working directory is changed
            TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1
    fi
    if test -z "$TEST_OUTPUT_DIRECTORY"
    then
            # Similarly, override this to store the test-results subdir
            # elsewhere
            TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY
    fi
    GIT_BUILD_DIR="$TEST_DIRECTORY"/..

If you want to do $(pwd -P) somewhere, isn't it that one you want to change to avoid similar problems in any code, including the ones that are not yet written, that uses $(pwd)?

This is a tangent, but I think I found a small bug while spelunking for the origin of HOME during tests.

 * We parse out --root=* option like this:
	--root=*)
		root=${opt#--*=} ;;
   Notice that we do not require it to be absolute path.
 * TRASH_DIRECTORY is originally set to "trash directory." with a
   suffix to make it unique across test scripts, but it immediately
   gets turned into an absolute path by doing this:
        test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
        case "$TRASH_DIRECTORY" in
        /*) ;; # absolute path is good
         *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
        esac
   I notice that a root that is not absolute is silently lost during
   this process.
   TEST_OUTPUT_DIRECTORY is set to TEST_DIRECTORY that comes from
   $(pwd) we saw earlier, or TEST_OUTPUT_DIRECTORY_OVERRIDE, which
   is also set to $(pwd) elsewhere, so the case statement does make
   it absolute in the end.  It just loses --root=* without complaint
   which is what I found iffy.
Previous: Philippe BlainNext: Jeff King
Message 2 of 5 in “t7900 failures when $HOME is symlinked”
  1. Philippe BlainDec 3, 2021
  2. Junio C HamanoDec 3, 2021
  3. Jeff KingDec 3, 2021
  4. Junio C HamanoDec 5, 2021
  5. Philippe BlainDec 3, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.