Re: [PATCH 04/10] t0001: handle `diff --no-index` gracefully
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 30, 2025, 05:59 UTC
- Message-ID
- <xmqqms44cb7p.fsf@gitster.g>
- In-Reply-To
- <3be9594e80c37b2b393f5883a173694ab6793813.1764440906.git.gitgitgadget@gmail.com>
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 8 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de> > > The test case 're-init to move gitdir symlink' wants to compare the > contents of `newdir/.git`, which is a symbolic link pointing to a file. > However, `git diff --no-index`, which is used by `test_cmp` on Windows, > does not resolve symlinks; It shows the symlink _target_ instead (with a > file mode of 120000). That is totally unexpected by the test case, which > as a consequence fails, meaning that it's a bug in the test case itself.
It is dubious if it is a bug in this particular test case, or test_cmp implementation that uses "git diff --no-index", though.
Either way, when test_cmp here does not do "diff", the test would fail, so you are correct to notice that this piece of code needs to be patched in some way. I do not think not comparing is the right solution, though. Would there be a better option than completely punting on the comparison? Something silly like:
Show 5 quoted lines
> + case "$GIT_TEST_CMP" in > + # git diff --no-index does not resolve symlinks > + *--no-index*) cmp expected newdir/.git ;; > + *) test_cmp expected newdir/.git ;; > + esac &&
perhaps?
Show 21 quoted lines
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> > --- > t/t0001-init.sh | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/t/t0001-init.sh b/t/t0001-init.sh > index 618da080dc..2f38e09b58 100755 > --- a/t/t0001-init.sh > +++ b/t/t0001-init.sh > @@ -425,7 +425,10 @@ test_expect_success SYMLINKS 're-init to move gitdir symlink' ' > git init --separate-git-dir ../realgitdir > ) && > echo "gitdir: $(pwd)/realgitdir" >expected && > - test_cmp expected newdir/.git && > + case "$GIT_TEST_CMP" in > + *--no-index*) ;; # git diff --no-index does not resolve symlinks > + *) test_cmp expected newdir/.git;; > + esac && > test_cmp expected newdir/here && > test_path_is_dir realgitdir/refs > '