On Thu, Aug 15, 2024 at 07:52:47AM -0700, Junio C Hamano wrote: > Jeff King <peff@xxxxxxxx> writes: > > > +test_expect_success POSIXPERM 'patch mode for deleted file is canonicalized' ' > > This test seems to fail under "--stress" and I need to borrow a > brain better clued than mine. It appears to be fooled by mtime that > is not updated immediately and failing match_stat check, but since > the index file is written on the other side of the second resolution > boundary, racy-git double-checking code does not trigger, or > something like that. Ah, thanks. I saw this fail once in CI, and then later succeed. But for some reason I wrote it off as CI flakiness rather than trying --stress locally. It's easy to reproduce the issue. I didn't puzzle out the exact condition that causes the race, but I think the fix is pretty clearly this: -- >8 -- Subject: [PATCH] t4129: fix racy index when calling chmod after git-add This patch fixes a racy test failure in t4129. The deletion test added by e95d515141 (apply: canonicalize modes read from patches, 2024-08-05) wants to make sure that git-apply does not complain about a non-canonical mode in the patch, even if that mode does not match the working tree file. So it does this: echo content >non-canon && git add non-canon && chmod 666 non-canon && This is wrong, because running chmod will update the ctime on the file, making it stat-dirty and causing git-apply to refuse to apply the patch. But this only happens sometimes, since it depends on the timestamps crossing a second boundary (but it triggers pretty quickly when run with --stress). We can fix this by doing the chmod before updating the index. The order isn't important here, as the mode will be canonicalized to 100644 in the index anyway (in fact, the chmod is not even that important in the first place, since git-apply will only look at the index; I only added it as an extra confirmation that git-apply would not be confused by it). Signed-off-by: Jeff King <peff@xxxxxxxx> --- t/t4129-apply-samemode.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh index d9a1084b5e..87ffd2b8e1 100755 --- a/t/t4129-apply-samemode.sh +++ b/t/t4129-apply-samemode.sh @@ -153,8 +153,8 @@ test_expect_success POSIXPERM 'patch mode for new file is canonicalized' ' test_expect_success POSIXPERM 'patch mode for deleted file is canonicalized' ' test_when_finished "git reset --hard" && echo content >non-canon && - git add non-canon && chmod 666 non-canon && + git add non-canon && cat >patch <<-\EOF && diff --git a/non-canon b/non-canon -- 2.46.0.476.g32f0e7348d