diff options
Diffstat (limited to 't/t2021-checkout-overwrite.sh')
-rwxr-xr-x | t/t2021-checkout-overwrite.sh | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/t/t2021-checkout-overwrite.sh b/t/t2021-checkout-overwrite.sh new file mode 100755 index 0000000..713c3fa --- /dev/null +++ b/t/t2021-checkout-overwrite.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +test_description='checkout must not overwrite an untracked objects' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh + +test_expect_success 'setup' ' + + mkdir -p a/b/c && + >a/b/c/d && + git add -A && + git commit -m base && + git tag start +' + +test_expect_success 'create a commit where dir a/b changed to file' ' + + git checkout -b file && + rm -rf a/b && + >a/b && + git add -A && + git commit -m "dir to file" +' + +test_expect_success 'checkout commit with dir must not remove untracked a/b' ' + + git rm --cached a/b && + git commit -m "un-track the file" && + test_must_fail git checkout start && + test -f a/b +' + +test_expect_success 'create a commit where dir a/b changed to symlink' ' + + rm -rf a/b && # cleanup if previous test failed + git checkout -f -b symlink start && + rm -rf a/b && + git add -A && + test_ln_s_add foo a/b && + git commit -m "dir to symlink" +' + +test_expect_success 'checkout commit with dir must not remove untracked a/b' ' + + git rm --cached a/b && + git commit -m "un-track the symlink" && + test_must_fail git checkout start +' + +test_expect_success SYMLINKS 'the symlink remained' ' + + test_when_finished "rm a/b" && + test -h a/b +' + +test_expect_success SYMLINKS 'checkout -f must not follow symlinks when removing entries' ' + git checkout -f start && + mkdir dir && + >dir/f && + git add dir/f && + git commit -m "add dir/f" && + mv dir untracked && + ln -s untracked dir && + git checkout -f HEAD~ && + test_path_is_file untracked/f +' + +test_done |