Merge branch 'cp/git-flush-is-an-env-bool'
[alt-git.git] / t / t6415-merge-dir-to-symlink.sh
blobae00492c768217a46d73fde7cfbc330dcc502616
1 #!/bin/sh
3 test_description='merging when a directory was replaced with a symlink'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 test_expect_success 'create a commit where dir a/b changed to symlink' '
11 mkdir -p a/b/c a/b-2/c &&
12 > a/b/c/d &&
13 > a/b-2/c/d &&
14 > a/x &&
15 git add -A &&
16 git commit -m base &&
17 git tag start &&
18 rm -rf a/b &&
19 git add -A &&
20 test_ln_s_add b-2 a/b &&
21 git commit -m "dir to symlink"
24 test_expect_success 'checkout does not clobber untracked symlink' '
25 git checkout HEAD^0 &&
26 git reset --hard main &&
27 git rm --cached a/b &&
28 git commit -m "untracked symlink remains" &&
29 test_must_fail git checkout start^0 &&
30 git clean -fd # Do not leave the untracked symlink in the way
33 test_expect_success 'a/b-2/c/d is kept when clobbering symlink b' '
34 git checkout HEAD^0 &&
35 git reset --hard main &&
36 git rm --cached a/b &&
37 git commit -m "untracked symlink remains" &&
38 git checkout -f start^0 &&
39 test_path_is_file a/b-2/c/d &&
40 git clean -fd # Do not leave the untracked symlink in the way
43 test_expect_success 'checkout should not have deleted a/b-2/c/d' '
44 git checkout HEAD^0 &&
45 git reset --hard main &&
46 git checkout start^0 &&
47 test_path_is_file a/b-2/c/d
50 test_expect_success 'setup for merge test' '
51 git reset --hard &&
52 test_path_is_file a/b-2/c/d &&
53 echo x > a/x &&
54 git add a/x &&
55 git commit -m x &&
56 git tag baseline
59 test_expect_success 'Handle D/F conflict, do not lose a/b-2/c/d in merge (resolve)' '
60 git reset --hard &&
61 git checkout baseline^0 &&
62 git merge -s resolve main &&
63 test_path_is_file a/b-2/c/d
66 test_expect_success SYMLINKS 'a/b was resolved as symlink' '
67 test -h a/b
70 test_expect_success 'Handle D/F conflict, do not lose a/b-2/c/d in merge (recursive)' '
71 git reset --hard &&
72 git checkout baseline^0 &&
73 git merge -s recursive main &&
74 test_path_is_file a/b-2/c/d
77 test_expect_success SYMLINKS 'a/b was resolved as symlink' '
78 test -h a/b
81 test_expect_success 'Handle F/D conflict, do not lose a/b-2/c/d in merge (resolve)' '
82 git reset --hard &&
83 git checkout main^0 &&
84 git merge -s resolve baseline^0 &&
85 test_path_is_file a/b-2/c/d
88 test_expect_success SYMLINKS 'a/b was resolved as symlink' '
89 test -h a/b
92 test_expect_success 'Handle F/D conflict, do not lose a/b-2/c/d in merge (recursive)' '
93 git reset --hard &&
94 git checkout main^0 &&
95 git merge -s recursive baseline^0 &&
96 test_path_is_file a/b-2/c/d
99 test_expect_success SYMLINKS 'a/b was resolved as symlink' '
100 test -h a/b
103 test_expect_failure 'do not lose untracked in merge (resolve)' '
104 git reset --hard &&
105 git checkout baseline^0 &&
106 >a/b/c/e &&
107 test_must_fail git merge -s resolve main &&
108 test_path_is_file a/b/c/e &&
109 test_path_is_file a/b-2/c/d
112 test_expect_success 'do not lose untracked in merge (recursive)' '
113 git reset --hard &&
114 git checkout baseline^0 &&
115 >a/b/c/e &&
116 test_must_fail git merge -s recursive main &&
117 test_path_is_file a/b/c/e &&
118 test_path_is_file a/b-2/c/d
121 test_expect_success 'do not lose modifications in merge (resolve)' '
122 git reset --hard &&
123 git checkout baseline^0 &&
124 echo more content >>a/b/c/d &&
125 test_must_fail git merge -s resolve main
128 test_expect_success 'do not lose modifications in merge (recursive)' '
129 git reset --hard &&
130 git checkout baseline^0 &&
131 echo more content >>a/b/c/d &&
132 test_must_fail git merge -s recursive main
135 test_expect_success 'setup a merge where dir a/b-2 changed to symlink' '
136 git reset --hard &&
137 git checkout start^0 &&
138 rm -rf a/b-2 &&
139 git add -A &&
140 test_ln_s_add b a/b-2 &&
141 git commit -m "dir a/b-2 to symlink" &&
142 git tag test2
145 test_expect_success 'merge should not have D/F conflicts (resolve)' '
146 git reset --hard &&
147 git checkout baseline^0 &&
148 git merge -s resolve test2 &&
149 test_path_is_file a/b/c/d
152 test_expect_success SYMLINKS 'a/b-2 was resolved as symlink' '
153 test -h a/b-2
156 test_expect_success 'merge should not have D/F conflicts (recursive)' '
157 git reset --hard &&
158 git checkout baseline^0 &&
159 git merge -s recursive test2 &&
160 test_path_is_file a/b/c/d
163 test_expect_success SYMLINKS 'a/b-2 was resolved as symlink' '
164 test -h a/b-2
167 test_expect_success 'merge should not have F/D conflicts (recursive)' '
168 git reset --hard &&
169 git checkout -b foo test2 &&
170 git merge -s recursive baseline^0 &&
171 test_path_is_file a/b/c/d
174 test_expect_success SYMLINKS 'a/b-2 was resolved as symlink' '
175 test -h a/b-2
178 test_done