t/t3415: use && where applicable.
[git/kirr.git] / t / t7405-submodule-merge.sh
blob7e2e258950772c91dfc04aff72ed74e95b5df884
1 #!/bin/sh
3 test_description='merging with submodules'
5 . ./test-lib.sh
8 # history
10 # a --- c
11 # / \ /
12 # root X
13 # \ / \
14 # b --- d
17 test_expect_success setup '
19 mkdir sub &&
20 (cd sub &&
21 git init &&
22 echo original > file &&
23 git add file &&
24 test_tick &&
25 git commit -m sub-root) &&
26 git add sub &&
27 test_tick &&
28 git commit -m root &&
30 git checkout -b a master &&
31 (cd sub &&
32 echo A > file &&
33 git add file &&
34 test_tick &&
35 git commit -m sub-a) &&
36 git add sub &&
37 test_tick &&
38 git commit -m a &&
40 git checkout -b b master &&
41 (cd sub &&
42 echo B > file &&
43 git add file &&
44 test_tick &&
45 git commit -m sub-b) &&
46 git add sub &&
47 test_tick &&
48 git commit -m b &&
50 git checkout -b c a &&
51 git merge -s ours b &&
53 git checkout -b d b &&
54 git merge -s ours a
57 # History setup
59 # b
60 # / \
61 # a d
62 # \ /
63 # c
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' '
69 mkdir merge-search &&
70 (cd merge-search &&
71 git init &&
72 mkdir sub &&
73 (cd sub &&
74 git init &&
75 echo "file-a" > file-a &&
76 git add file-a &&
77 git commit -m "sub-a" &&
78 git branch sub-a) &&
79 git add sub &&
80 git commit -m "a" &&
81 git branch a &&
83 git checkout -b b &&
84 (cd sub &&
85 git checkout -b sub-b &&
86 echo "file-b" > file-b &&
87 git add file-b &&
88 git commit -m "sub-b") &&
89 git commit -a -m "b" &&
91 git checkout -b c a &&
92 (cd sub &&
93 git checkout -b sub-c sub-a &&
94 echo "file-c" > file-c &&
95 git add file-c &&
96 git commit -m "sub-c") &&
97 git commit -a -m "c" &&
99 git checkout -b d a &&
100 (cd sub &&
101 git checkout -b sub-d sub-b &&
102 git merge sub-c) &&
103 git commit -a -m "d" &&
104 git branch test b)
107 test_expect_success 'merge with one side as a fast-forward of the other' '
108 (cd merge-search &&
109 git checkout -b test-forward b &&
110 git merge d &&
111 git ls-tree test-forward sub | cut -f1 | cut -f3 -d" " > actual &&
112 (cd sub &&
113 git rev-parse sub-d > ../expect) &&
114 test_cmp actual expect)
117 test_expect_success 'merging should conflict for non fast-forward' '
118 (cd merge-search &&
119 git checkout -b test-nonforward b &&
120 (cd sub &&
121 git rev-parse sub-d > ../expect) &&
122 test_must_fail git merge c 2> actual &&
123 grep $(cat expect) actual > /dev/null &&
124 git reset --hard)
127 test_expect_success 'merging should fail for ambiguous common parent' '
128 (cd merge-search &&
129 git checkout -b test-ambiguous b &&
130 (cd sub &&
131 git checkout -b ambiguous sub-b &&
132 git merge sub-c &&
133 git rev-parse sub-d > ../expect1 &&
134 git rev-parse ambiguous > ../expect2) &&
135 test_must_fail git merge c 2> actual &&
136 grep $(cat expect1) actual > /dev/null &&
137 grep $(cat expect2) actual > /dev/null &&
138 git reset --hard)
141 # in a situation like this
143 # submodule tree:
145 # sub-a --- sub-b --- sub-d
147 # main tree:
149 # e (sub-a)
151 # bb (sub-b)
153 # f (sub-d)
155 # A merge between e and f should fail because one of the submodule
156 # commits (sub-a) does not descend from the submodule merge-base (sub-b).
158 test_expect_success 'merging should fail for changes that are backwards' '
159 (cd merge-search &&
160 git checkout -b bb a &&
161 (cd sub &&
162 git checkout sub-b) &&
163 git commit -a -m "bb" &&
165 git checkout -b e bb &&
166 (cd sub &&
167 git checkout sub-a) &&
168 git commit -a -m "e" &&
170 git checkout -b f bb &&
171 (cd sub &&
172 git checkout sub-d) &&
173 git commit -a -m "f" &&
175 git checkout -b test-backward e &&
176 test_must_fail git merge f)
179 test_expect_success 'merging with a modify/modify conflict between merge bases' '
180 git reset --hard HEAD &&
181 git checkout -b test2 c &&
182 git merge d
185 test_done