| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='checkout must not overwrite an untracked objects' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'setup' ' |
| 8 | |
| 9 | mkdir -p a/b/c && |
| 10 | >a/b/c/d && |
| 11 | git add -A && |
| 12 | git commit -m base && |
| 13 | git tag start |
| 14 | ' |
| 15 | |
| 16 | test_expect_success 'create a commit where dir a/b changed to file' ' |
| 17 | |
| 18 | git checkout -b file && |
| 19 | rm -rf a/b && |
| 20 | >a/b && |
| 21 | git add -A && |
| 22 | git commit -m "dir to file" |
| 23 | ' |
| 24 | |
| 25 | test_expect_success 'checkout commit with dir must not remove untracked a/b' ' |
| 26 | |
| 27 | git rm --cached a/b && |
| 28 | git commit -m "un-track the file" && |
| 29 | test_must_fail git checkout start && |
| 30 | test_path_is_file a/b |
| 31 | ' |
| 32 | |
| 33 | test_expect_success 'create a commit where dir a/b changed to symlink' ' |
| 34 | |
| 35 | rm -rf a/b && # cleanup if previous test failed |
| 36 | git checkout -f -b symlink start && |
| 37 | rm -rf a/b && |
| 38 | git add -A && |
| 39 | test_ln_s_add foo a/b && |
| 40 | git commit -m "dir to symlink" |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'checkout commit with dir must not remove untracked a/b' ' |
| 44 | |
| 45 | git rm --cached a/b && |
| 46 | git commit -m "un-track the symlink" && |
| 47 | test_must_fail git checkout start |
| 48 | ' |
| 49 | |
| 50 | test_expect_success SYMLINKS 'the symlink remained' ' |
| 51 | |
| 52 | test_path_is_symlink a/b |
| 53 | ' |
| 54 | |
| 55 | test_expect_success 'cleanup after previous symlink tests' ' |
| 56 | rm a/b |
| 57 | ' |
| 58 | |
| 59 | test_expect_success SYMLINKS 'checkout -f must not follow symlinks when removing entries' ' |
| 60 | git checkout -f start && |
| 61 | mkdir dir && |
| 62 | >dir/f && |
| 63 | git add dir/f && |
| 64 | git commit -m "add dir/f" && |
| 65 | mv dir untracked && |
| 66 | ln -s untracked dir && |
| 67 | git checkout -f HEAD~ && |
| 68 | test_path_is_file untracked/f |
| 69 | ' |
| 70 | |
| 71 | test_expect_success 'checkout --overwrite-ignore should succeed if only ignored files in the way' ' |
| 72 | git checkout -b df_conflict && |
| 73 | test_commit contents some_dir && |
| 74 | git checkout start && |
| 75 | mkdir some_dir && |
| 76 | echo autogenerated information >some_dir/ignore && |
| 77 | echo ignore >.git/info/exclude && |
| 78 | git checkout --overwrite-ignore df_conflict && |
| 79 | test_path_is_file some_dir |
| 80 | ' |
| 81 | |
| 82 | test_done |