git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* t7900 failures when $HOME is symlinked
@ 2021-12-03 14:56 Philippe Blain
  2021-12-03 17:10 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Philippe Blain @ 2021-12-03 14:56 UTC (permalink / raw)
  To: Git mailing list, Derrick Stolee

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.

Cheers,

Philippe.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: t7900 failures when $HOME is symlinked
  2021-12-03 14:56 t7900 failures when $HOME is symlinked Philippe Blain
@ 2021-12-03 17:10 ` Junio C Hamano
  2021-12-03 17:42   ` Jeff King
  2021-12-03 22:40   ` Philippe Blain
  0 siblings, 2 replies; 5+ messages in thread
From: Junio C Hamano @ 2021-12-03 17:10 UTC (permalink / raw)
  To: Philippe Blain; +Cc: Git mailing list, Derrick Stolee

Philippe Blain <levraiphilippeblain@gmail.com> writes:

> 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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: t7900 failures when $HOME is symlinked
  2021-12-03 17:10 ` Junio C Hamano
@ 2021-12-03 17:42   ` Jeff King
  2021-12-05 10:02     ` Junio C Hamano
  2021-12-03 22:40   ` Philippe Blain
  1 sibling, 1 reply; 5+ messages in thread
From: Jeff King @ 2021-12-03 17:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Philippe Blain, Git mailing list, Derrick Stolee

On Fri, Dec 03, 2021 at 09:10:16AM -0800, Junio C Hamano wrote:

>  * 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.

I don't think it's lost. It becomes part of $TRASH_DIRECTORY in the
first line, so the final line which prepends $TEST_OUTPUT_DIRECTORY
makes it relative to that. E.g.:

  $ cd t
  $ ./t0000-basic.sh --root=foo --debug
  [...]
  $ ls foo
  trash directory.t0000-basic/

I don't recall planning that in particular (there is not much point in
using it unless you are pointing outside the repo, though I guess you
could use ../../../foo or similar). But I think it has always worked
that way, since f423ef5f2b (tests: allow user to specify trash directory
location, 2009-08-09). It was perhaps a little easier to see back then
when the intermediate "$test" variable was not the final one.

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: t7900 failures when $HOME is symlinked
  2021-12-03 17:10 ` Junio C Hamano
  2021-12-03 17:42   ` Jeff King
@ 2021-12-03 22:40   ` Philippe Blain
  1 sibling, 0 replies; 5+ messages in thread
From: Philippe Blain @ 2021-12-03 22:40 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git mailing list, Derrick Stolee

Hi Junio,

Le 2021-12-03 à 12:10, Junio C Hamano a écrit :
> Philippe Blain <levraiphilippeblain@gmail.com> writes:
> 
>> 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.

Indeed, the source code was cloned somewhere in my HOME.

> 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)?

Indeed, that works and it looks like a more robust fix.

Thanks,

Philippe.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: t7900 failures when $HOME is symlinked
  2021-12-03 17:42   ` Jeff King
@ 2021-12-05 10:02     ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2021-12-05 10:02 UTC (permalink / raw)
  To: Jeff King; +Cc: Philippe Blain, Git mailing list, Derrick Stolee

Jeff King <peff@peff.net> writes:

> I don't think it's lost. It becomes part of $TRASH_DIRECTORY in the
> first line, so the final line which prepends $TEST_OUTPUT_DIRECTORY
> makes it relative to that. E.g.:
>
>   $ cd t
>   $ ./t0000-basic.sh --root=foo --debug
>   [...]
>   $ ls foo
>   trash directory.t0000-basic/

Ah, OK.  Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-05 10:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03 14:56 t7900 failures when $HOME is symlinked Philippe Blain
2021-12-03 17:10 ` Junio C Hamano
2021-12-03 17:42   ` Jeff King
2021-12-05 10:02     ` Junio C Hamano
2021-12-03 22:40   ` Philippe Blain

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).