From 319a7bc50930c444d0d243fee87a014658ab4927 Mon Sep 17 00:00:00 2001 From: skdas20 Date: Thu, 27 Aug 2026 15:21:42 +0000 Subject: [PATCH] t2021: move directory-to-file checkout test out of t0050 The test 'checkout with no pathspec and a case insensitive fs' was added to t0050 as a minimal reproduction of a segfault. Reviewing it later, its author noted it had ended up in a script it does not belong in: https://lore.kernel.org/git/20191007180409.GD11529@szeder.dev/ Three things were wrong with it: - It carried the CASE_INSENSITIVE_FS prerequisite. The segfault could only be triggered on a case insensitive filesystem, but the sequence of commands itself succeeds anywhere, so the prerequisite only prevented the test from running on most systems. - t0050 collects filesystem capability tests. What this exercises is checkout replacing a tracked directory with a tracked file when switching branches, which is what t2021 already covers. - It asserted nothing beyond 'git checkout main' succeeding, so it would not have noticed checkout leaving the wrong contents behind. Move it to t2021, drop the prerequisite, and check the resulting worktree: Gitweb is restored as a file and the gitweb directory is gone. The repository is created with an explicit initial branch, since t2021 does not set GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME the way t0050 does. Signed-off-by: skdas20 --- t/t0050-filesystem.sh | 20 -------------------- t/t2021-checkout-overwrite.sh | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh index ca8568067d31d6..003329c082fae8 100755 --- a/t/t0050-filesystem.sh +++ b/t/t0050-filesystem.sh @@ -117,24 +117,4 @@ $test_unicode 'merge (silent unicode normalization)' ' git merge topic ' -test_expect_success CASE_INSENSITIVE_FS 'checkout with no pathspec and a case insensitive fs' ' - git init repo && - ( - cd repo && - - >Gitweb && - git add Gitweb && - git commit -m "add Gitweb" && - - git checkout --orphan todo && - git reset --hard && - mkdir -p gitweb/subdir && - >gitweb/subdir/file && - git add gitweb && - git commit -m "add gitweb/subdir/file" && - - git checkout main - ) -' - test_done diff --git a/t/t2021-checkout-overwrite.sh b/t/t2021-checkout-overwrite.sh index 38c41ae37321ce..729a9bece17208 100755 --- a/t/t2021-checkout-overwrite.sh +++ b/t/t2021-checkout-overwrite.sh @@ -79,4 +79,27 @@ test_expect_success 'checkout --overwrite-ignore should succeed if only ignored test_path_is_file some_dir ' +test_expect_success 'checkout switching to a tracked file replaces a tracked directory' ' + git init -b main dir-to-file && + ( + cd dir-to-file && + + >Gitweb && + git add Gitweb && + git commit -m "add Gitweb" && + + git checkout --orphan todo && + git reset --hard && + mkdir -p gitweb/subdir && + >gitweb/subdir/file && + git add gitweb && + git commit -m "add gitweb/subdir/file" && + + git checkout main && + + test_path_is_file Gitweb && + test_path_is_missing gitweb + ) +' + test_done