3 test_description='merging with submodules'
17 test_expect_success setup '
22 echo original > file &&
25 git commit -m sub-root) &&
30 git checkout -b a master &&
35 git commit -m sub-a) &&
40 git checkout -b b master &&
45 git commit -m sub-b) &&
50 git checkout -b c a &&
51 git merge -s ours b &&
53 git checkout -b d b &&
65 # a in the main repository records to sub-a in the submodule and
66 # analogous b and c. d should be automatically found by merging c into
67 # b in the main repository.
68 test_expect_success 'setup for merge search' '
75 echo "file-a" > file-a &&
77 git commit -m "sub-a" &&
79 git commit --allow-empty -m init &&
87 git checkout -b sub-b &&
88 echo "file-b" > file-b &&
90 git commit -m "sub-b") &&
91 git commit -a -m "b" &&
93 git checkout -b c a &&
95 git checkout -b sub-c sub-a &&
96 echo "file-c" > file-c &&
98 git commit -m "sub-c") &&
99 git commit -a -m "c" &&
101 git checkout -b d a &&
103 git checkout -b sub-d sub-b &&
105 git commit -a -m "d" &&
108 git checkout -b g init &&
110 git checkout -b sub-g sub-c) &&
112 git commit -a -m "g")
115 test_expect_success 'merge with one side as a fast-forward of the other' '
117 git checkout -b test-forward b &&
119 git ls-tree test-forward sub | cut -f1 | cut -f3 -d" " > actual &&
121 git rev-parse sub-d > ../expect) &&
122 test_cmp actual expect)
125 test_expect_success 'merging should conflict for non fast-forward' '
127 git checkout -b test-nonforward b &&
129 git rev-parse sub-d > ../expect) &&
130 test_must_fail git merge c 2> actual &&
131 grep $(cat expect) actual > /dev/null &&
135 test_expect_success 'merging should fail for ambiguous common parent' '
137 git checkout -b test-ambiguous b &&
139 git checkout -b ambiguous sub-b &&
141 git rev-parse sub-d > ../expect1 &&
142 git rev-parse ambiguous > ../expect2) &&
143 test_must_fail git merge c 2> actual &&
144 grep $(cat expect1) actual > /dev/null &&
145 grep $(cat expect2) actual > /dev/null &&
149 # in a situation like this
153 # sub-a --- sub-b --- sub-d
163 # A merge between e and f should fail because one of the submodule
164 # commits (sub-a) does not descend from the submodule merge-base (sub-b).
166 test_expect_success 'merging should fail for changes that are backwards' '
168 git checkout -b bb a &&
170 git checkout sub-b) &&
171 git commit -a -m "bb" &&
173 git checkout -b e bb &&
175 git checkout sub-a) &&
176 git commit -a -m "e" &&
178 git checkout -b f bb &&
180 git checkout sub-d) &&
181 git commit -a -m "f" &&
183 git checkout -b test-backward e &&
184 test_must_fail git merge f)
188 # Check that the conflicting submodule is detected when it is
189 # in the common ancestor. status should be 'U00...00"
190 test_expect_success 'git submodule status should display the merge conflict properly with merge base' '
192 cat >.gitmodules <<EOF &&
195 url = $TRASH_DIRECTORY/sub
198 U0000000000000000000000000000000000000000 sub
200 git submodule status > actual &&
201 test_cmp expect actual &&
205 # Check that the conflicting submodule is detected when it is
206 # not in the common ancestor. status should be 'U00...00"
207 test_expect_success 'git submodule status should display the merge conflict properly without merge-base' '
209 git checkout -b test-no-merge-base g &&
210 test_must_fail git merge b &&
211 cat >.gitmodules <<EOF &&
214 url = $TRASH_DIRECTORY/sub
217 U0000000000000000000000000000000000000000 sub
219 git submodule status > actual &&
220 test_cmp expect actual &&
225 test_expect_success 'merging with a modify/modify conflict between merge bases' '
226 git reset --hard HEAD &&
227 git checkout -b test2 c &&