]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7603-merge-reduce-heads.sh
The third batch
[thirdparty/git.git] / t / t7603-merge-reduce-heads.sh
1 #!/bin/sh
2
3 test_description='git merge
4
5 Testing octopus merge when reducing parents to independent branches.'
6
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
10 # 0 - 1
11 # \ 2
12 # \ 3
13 # \ 4 - 5
14 #
15 # So 1, 2, 3 and 5 should be kept, 4 should be avoided.
16
17 test_expect_success 'setup' '
18 echo c0 > c0.c &&
19 git add c0.c &&
20 git commit -m c0 &&
21 git tag c0 &&
22 echo c1 > c1.c &&
23 git add c1.c &&
24 git commit -m c1 &&
25 git tag c1 &&
26 git reset --hard c0 &&
27 echo c2 > c2.c &&
28 git add c2.c &&
29 git commit -m c2 &&
30 git tag c2 &&
31 git reset --hard c0 &&
32 echo c3 > c3.c &&
33 git add c3.c &&
34 git commit -m c3 &&
35 git tag c3 &&
36 git reset --hard c0 &&
37 echo c4 > c4.c &&
38 git add c4.c &&
39 git commit -m c4 &&
40 git tag c4 &&
41 echo c5 > c5.c &&
42 git add c5.c &&
43 git commit -m c5 &&
44 git tag c5
45 '
46
47 test_expect_success 'merge c1 with c2, c3, c4, c5' '
48 git reset --hard c1 &&
49 git merge c2 c3 c4 c5 &&
50 test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
51 test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
52 test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
53 test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" &&
54 test "$(git rev-parse c5)" = "$(git rev-parse HEAD^4)" &&
55 git diff --exit-code &&
56 test -f c0.c &&
57 test -f c1.c &&
58 test -f c2.c &&
59 test -f c3.c &&
60 test -f c4.c &&
61 test -f c5.c &&
62 git show --format=%s -s >actual &&
63 ! grep c1 actual &&
64 grep c2 actual &&
65 grep c3 actual &&
66 ! grep c4 actual &&
67 grep c5 actual
68 '
69
70 test_expect_success 'pull c2, c3, c4, c5 into c1' '
71 git reset --hard c1 &&
72 git pull --no-rebase . c2 c3 c4 c5 &&
73 test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
74 test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
75 test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
76 test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" &&
77 test "$(git rev-parse c5)" = "$(git rev-parse HEAD^4)" &&
78 git diff --exit-code &&
79 test -f c0.c &&
80 test -f c1.c &&
81 test -f c2.c &&
82 test -f c3.c &&
83 test -f c4.c &&
84 test -f c5.c &&
85 git show --format=%s -s >actual &&
86 ! grep c1 actual &&
87 grep c2 actual &&
88 grep c3 actual &&
89 ! grep c4 actual &&
90 grep c5 actual
91 '
92
93 test_expect_success 'setup' '
94 for i in A B C D E
95 do
96 echo $i > $i.c &&
97 git add $i.c &&
98 git commit -m $i &&
99 git tag $i || return 1
100 done &&
101 git reset --hard A &&
102 for i in F G H I
103 do
104 echo $i > $i.c &&
105 git add $i.c &&
106 git commit -m $i &&
107 git tag $i || return 1
108 done
109 '
110
111 test_expect_success 'merge E and I' '
112 git reset --hard A &&
113 git merge E I
114 '
115
116 test_expect_success 'verify merge result' '
117 test $(git rev-parse HEAD^1) = $(git rev-parse E) &&
118 test $(git rev-parse HEAD^2) = $(git rev-parse I)
119 '
120
121 test_expect_success 'add conflicts' '
122 git reset --hard E &&
123 echo foo > file.c &&
124 git add file.c &&
125 git commit -m E2 &&
126 git tag E2 &&
127 git reset --hard I &&
128 echo bar >file.c &&
129 git add file.c &&
130 git commit -m I2 &&
131 git tag I2
132 '
133
134 test_expect_success 'merge E2 and I2, causing a conflict and resolve it' '
135 git reset --hard A &&
136 test_must_fail git merge E2 I2 &&
137 echo baz > file.c &&
138 git add file.c &&
139 git commit -m "resolve conflict"
140 '
141
142 test_expect_success 'verify merge result' '
143 test $(git rev-parse HEAD^1) = $(git rev-parse E2) &&
144 test $(git rev-parse HEAD^2) = $(git rev-parse I2)
145 '
146
147 test_expect_success 'fast-forward to redundant refs' '
148 git reset --hard c0 &&
149 git merge c4 c5
150 '
151
152 test_expect_success 'verify merge result' '
153 test $(git rev-parse HEAD) = $(git rev-parse c5)
154 '
155
156 test_expect_success 'merge up-to-date redundant refs' '
157 git reset --hard c5 &&
158 git merge c0 c4
159 '
160
161 test_expect_success 'verify merge result' '
162 test $(git rev-parse HEAD) = $(git rev-parse c5)
163 '
164
165 test_done