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