]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t4129: fix racy index when calling chmod after git-add
authorJeff King <peff@peff.net>
Thu, 15 Aug 2024 15:30:07 +0000 (11:30 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Aug 2024 16:41:11 +0000 (09:41 -0700)
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@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4129-apply-samemode.sh

index d9a1084b5e6f2a531beaf329f88cbc86ad7ff1d2..87ffd2b8e1a3d3b3f69c8849e8a153362f77ad1a 100755 (executable)
@@ -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