Skip to content

Commit b96d406

Browse files
ptarjangitster
authored andcommitted
t7800: fix racy "difftool --dir-diff syncs worktree" test
The "difftool --dir-diff syncs worktree without unstaged change" test fails intermittently, particularly on Windows CI. The test modifies a file in difftool's temp directory via an extcmd script and expects the change to be synced back to the worktree. The sync-back detection relies on git's change detection mechanisms. The root cause is that the original file content and the replacement content have identical sizes: - Original: "main\ntest\na\n" = 12 bytes - New: "new content\n" = 12 bytes When difftool creates the temporary index (wtindex), the cache entries have sd_size = 0 (zero-initialized via make_cache_entry with no refresh). Git's ie_modified() is designed to handle this by calling ce_modified_check_fs() for content hashing when sd_size is 0. However, Windows has known filesystem issues that may cause this to fail intermittently: - UNRELIABLE_FSTAT: Windows fstat() on open files may not return the same information as lstat() after close (config.mak.uname:506) - NTFS timestamp issues: The racy-git documentation notes that NTFS is "still broken" regarding timestamp granularity between in-core and on-disk representations (Documentation/technical/racy-git.adoc) - Attribute caching: Windows GetFileAttributesExW may cache results Fix this by changing the replacement content to "modified content\n" (17 bytes), ensuring the change is detected at the earliest size comparison in match_stat_data(), bypassing any platform-specific edge cases in the more complex code paths. Note: Other tests with same-size file patterns (t0010-racy-git.sh, t2200-add-update.sh, t1701-racy-split-index.sh) are not vulnerable because they use normal Git index operations with proper racy git detection. The difftool case is unique due to its ephemeral wtindex created via make_cache_entry() without full stat refresh. Signed-off-by: Paul Tarjan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 68cb7f9 commit b96d406

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

t/t7800-difftool.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,21 +647,21 @@ test_expect_success SYMLINKS 'difftool --dir-diff --symlinks without unstaged ch
647647
'
648648

649649
write_script modify-right-file <<\EOF
650-
echo "new content" >"$2/file"
650+
echo "modified content" >"$2/file"
651651
EOF
652652

653653
run_dir_diff_test 'difftool --dir-diff syncs worktree with unstaged change' '
654654
test_when_finished git reset --hard &&
655655
echo "orig content" >file &&
656656
git difftool -d $symlinks --extcmd "$PWD/modify-right-file" branch &&
657-
echo "new content" >expect &&
657+
echo "modified content" >expect &&
658658
test_cmp expect file
659659
'
660660

661661
run_dir_diff_test 'difftool --dir-diff syncs worktree without unstaged change' '
662662
test_when_finished git reset --hard &&
663663
git difftool -d $symlinks --extcmd "$PWD/modify-right-file" branch &&
664-
echo "new content" >expect &&
664+
echo "modified content" >expect &&
665665
test_cmp expect file
666666
'
667667

0 commit comments

Comments
 (0)