Re: [PATCH] t7900: use pwd -P in macOS maintenance test
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 23, 2025, 20:42 UTC
- Message-ID
- <xmqqsekvvz1t.fsf@gitster.g>
- In-Reply-To
- <CAPig+cRpS=t-wNLxdV_WoKF0Wzy-S1oLUEyS18S9r-4OBQ87VQ@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 28 quoted lines
>> - pfx=$(cd "$HOME" && pwd) &&
>> + pfx=$(cd "$HOME" && pwd -P) &&
>
> Okay, this seems like the minimum fix[*], and -P is POSIX.
>
> However, have you tested this on Windows? I ask because, despite the
> test's name, this and most of the tests in this script, are actually
> run on all platforms, and because `pwd` is overridden by a shell
> function for MinGW on Windows:
>
> # t/test-lib.sh
> ...
> # git sees Windows-style pwd
> pwd () {
> builtin pwd -W
> }
>
> My quick testing suggests that this patch's change might be problematic:
>
> # on Windows
> $ pwd
> /home/me
> $ pwd -W
> C:/msys64/home/me
> $ pwd -P
> /home/me
> $ pwd -W -P
> /home/meBecause pwd emulation we use on Windows ignores -P the updated caller, pfx with this change would not change the existing behaviour.
How would one test this situation on Windows, I wonder? Create a directory that is pointed at by a symbolic link, and use it as the test directory (either have the checkout there, or use --root to have the trash directory there)?
Show 10 quoted lines
> FOOTNOTES > > [*]: In the long run, a better fix would probably be for the tests to > sanitize the output of the Git command, replacing (via `sed`) the > actual emitted path with some placeholder, such as "%HOME%" or > something, and then have the tests look for (`grep` or whatnot) > needles using that literal placeholder rather than trying to perfectly > match the path emitted by Git. This approach makes sense since these > tests are about overall functionality of git-maintenance, not about > the specific path in which the person happens to be running the tests.
Another approach may be to do a form of chdir that forces the shell to figure out where it really is upfront at the beginning of a test script, perhaps inside test-lib.sh which happend before anything meaningful happens in the test (i.e. "cd -P ." or something).