config: unify code paths to get global config paths
[git] / t / t6415-merge-dir-to-symlink.sh
1 #!/bin/sh
2
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
6
7 . ./test-lib.sh
8
9 test_expect_success 'create a commit where dir a/b changed to symlink' '
10         mkdir -p a/b/c a/b-2/c &&
11         > a/b/c/d &&
12         > a/b-2/c/d &&
13         > a/x &&
14         git add -A &&
15         git commit -m base &&
16         git tag start &&
17         rm -rf a/b &&
18         git add -A &&
19         test_ln_s_add b-2 a/b &&
20         git commit -m "dir to symlink"
21 '
22
23 test_expect_success 'checkout does not clobber untracked symlink' '
24         git checkout HEAD^0 &&
25         git reset --hard main &&
26         git rm --cached a/b &&
27         git commit -m "untracked symlink remains" &&
28         test_must_fail git checkout start^0
29 '
30
31 test_expect_success 'a/b-2/c/d is kept when clobbering symlink b' '
32         git checkout HEAD^0 &&
33         git reset --hard main &&
34         git rm --cached a/b &&
35         git commit -m "untracked symlink remains" &&
36         git checkout -f start^0 &&
37         test_path_is_file a/b-2/c/d
38 '
39
40 test_expect_success 'checkout should not have deleted a/b-2/c/d' '
41         git checkout HEAD^0 &&
42         git reset --hard main &&
43          git checkout start^0 &&
44          test_path_is_file a/b-2/c/d
45 '
46
47 test_expect_success 'setup for merge test' '
48         git reset --hard &&
49         test_path_is_file a/b-2/c/d &&
50         echo x > a/x &&
51         git add a/x &&
52         git commit -m x &&
53         git tag baseline
54 '
55
56 test_expect_success 'Handle D/F conflict, do not lose a/b-2/c/d in merge (resolve)' '
57         git reset --hard &&
58         git checkout baseline^0 &&
59         git merge -s resolve main &&
60         test_path_is_file a/b-2/c/d
61 '
62
63 test_expect_success SYMLINKS 'a/b was resolved as symlink' '
64         test -h a/b
65 '
66
67 test_expect_success 'Handle D/F conflict, do not lose a/b-2/c/d in merge (recursive)' '
68         git reset --hard &&
69         git checkout baseline^0 &&
70         git merge -s recursive main &&
71         test_path_is_file a/b-2/c/d
72 '
73
74 test_expect_success SYMLINKS 'a/b was resolved as symlink' '
75         test -h a/b
76 '
77
78 test_expect_success 'Handle F/D conflict, do not lose a/b-2/c/d in merge (resolve)' '
79         git reset --hard &&
80         git checkout main^0 &&
81         git merge -s resolve baseline^0 &&
82         test_path_is_file a/b-2/c/d
83 '
84
85 test_expect_success SYMLINKS 'a/b was resolved as symlink' '
86         test -h a/b
87 '
88
89 test_expect_success 'Handle F/D conflict, do not lose a/b-2/c/d in merge (recursive)' '
90         git reset --hard &&
91         git checkout main^0 &&
92         git merge -s recursive baseline^0 &&
93         test_path_is_file a/b-2/c/d
94 '
95
96 test_expect_success SYMLINKS 'a/b was resolved as symlink' '
97         test -h a/b
98 '
99
100 test_expect_failure 'do not lose untracked in merge (resolve)' '
101         git reset --hard &&
102         git checkout baseline^0 &&
103         >a/b/c/e &&
104         test_must_fail git merge -s resolve main &&
105         test_path_is_file a/b/c/e &&
106         test_path_is_file a/b-2/c/d
107 '
108
109 test_expect_success 'do not lose untracked in merge (recursive)' '
110         git reset --hard &&
111         git checkout baseline^0 &&
112         >a/b/c/e &&
113         test_must_fail git merge -s recursive main &&
114         test_path_is_file a/b/c/e &&
115         test_path_is_file a/b-2/c/d
116 '
117
118 test_expect_success 'do not lose modifications in merge (resolve)' '
119         git reset --hard &&
120         git checkout baseline^0 &&
121         echo more content >>a/b/c/d &&
122         test_must_fail git merge -s resolve main
123 '
124
125 test_expect_success 'do not lose modifications in merge (recursive)' '
126         git reset --hard &&
127         git checkout baseline^0 &&
128         echo more content >>a/b/c/d &&
129         test_must_fail git merge -s recursive main
130 '
131
132 test_expect_success 'setup a merge where dir a/b-2 changed to symlink' '
133         git reset --hard &&
134         git checkout start^0 &&
135         rm -rf a/b-2 &&
136         git add -A &&
137         test_ln_s_add b a/b-2 &&
138         git commit -m "dir a/b-2 to symlink" &&
139         git tag test2
140 '
141
142 test_expect_success 'merge should not have D/F conflicts (resolve)' '
143         git reset --hard &&
144         git checkout baseline^0 &&
145         git merge -s resolve test2 &&
146         test_path_is_file a/b/c/d
147 '
148
149 test_expect_success SYMLINKS 'a/b-2 was resolved as symlink' '
150         test -h a/b-2
151 '
152
153 test_expect_success 'merge should not have D/F conflicts (recursive)' '
154         git reset --hard &&
155         git checkout baseline^0 &&
156         git merge -s recursive test2 &&
157         test_path_is_file a/b/c/d
158 '
159
160 test_expect_success SYMLINKS 'a/b-2 was resolved as symlink' '
161         test -h a/b-2
162 '
163
164 test_expect_success 'merge should not have F/D conflicts (recursive)' '
165         git reset --hard &&
166         git checkout -b foo test2 &&
167         git merge -s recursive baseline^0 &&
168         test_path_is_file a/b/c/d
169 '
170
171 test_expect_success SYMLINKS 'a/b-2 was resolved as symlink' '
172         test -h a/b-2
173 '
174
175 test_done