]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2021-checkout-overwrite.sh
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / t / t2021-checkout-overwrite.sh
1 #!/bin/sh
2
3 test_description='checkout must not overwrite an untracked objects'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '
9
10 mkdir -p a/b/c &&
11 >a/b/c/d &&
12 git add -A &&
13 git commit -m base &&
14 git tag start
15 '
16
17 test_expect_success 'create a commit where dir a/b changed to file' '
18
19 git checkout -b file &&
20 rm -rf a/b &&
21 >a/b &&
22 git add -A &&
23 git commit -m "dir to file"
24 '
25
26 test_expect_success 'checkout commit with dir must not remove untracked a/b' '
27
28 git rm --cached a/b &&
29 git commit -m "un-track the file" &&
30 test_must_fail git checkout start &&
31 test -f a/b
32 '
33
34 test_expect_success 'create a commit where dir a/b changed to symlink' '
35
36 rm -rf a/b && # cleanup if previous test failed
37 git checkout -f -b symlink start &&
38 rm -rf a/b &&
39 git add -A &&
40 test_ln_s_add foo a/b &&
41 git commit -m "dir to symlink"
42 '
43
44 test_expect_success 'checkout commit with dir must not remove untracked a/b' '
45
46 git rm --cached a/b &&
47 git commit -m "un-track the symlink" &&
48 test_must_fail git checkout start
49 '
50
51 test_expect_success SYMLINKS 'the symlink remained' '
52
53 test_when_finished "rm a/b" &&
54 test -h a/b
55 '
56
57 test_expect_success SYMLINKS 'checkout -f must not follow symlinks when removing entries' '
58 git checkout -f start &&
59 mkdir dir &&
60 >dir/f &&
61 git add dir/f &&
62 git commit -m "add dir/f" &&
63 mv dir untracked &&
64 ln -s untracked dir &&
65 git checkout -f HEAD~ &&
66 test_path_is_file untracked/f
67 '
68
69 test_done