Raw
1 #!/bin/sh
2
3 # There's more than one "correct" way to represent the history graphically.
4 # These tests depend on the current behavior of the graphing code. If the
5 # graphing code is ever changed to draw the output differently, these tests
6 # cases will need to be updated to know about the new layout.
7
8 test_description='--graph and simplified history'
9
10 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
11 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12
13 . ./test-lib.sh
14 . "$TEST_DIRECTORY"/lib-log-graph.sh
15
16 test_expect_success 'set up rev-list --graph test' '
17 # 3 commits on branch A
18 test_commit A1 foo.txt &&
19 test_commit A2 bar.txt &&
20 test_commit A3 bar.txt &&
21 git branch -m main A &&
22
23 # 2 commits on branch B, started from A1
24 git checkout -b B A1 &&
25 test_commit B1 foo.txt &&
26 test_commit B2 abc.txt &&
27
28 # 2 commits on branch C, started from A2
29 git checkout -b C A2 &&
30 test_commit C1 xyz.txt &&
31 test_commit C2 xyz.txt &&
32
33 # Octopus merge B and C into branch A
34 git checkout A &&
35 git merge B C -m A4 &&
36 git tag A4 &&
37
38 test_commit A5 bar.txt &&
39
40 # More commits on C, then merge C into A
41 git checkout C &&
42 test_commit C3 foo.txt &&
43 test_commit C4 bar.txt &&
44 git checkout A &&
45 git merge -s ours C -m A6 &&
46 git tag A6 &&
47
48 test_commit A7 bar.txt
49 '
50
51 test_expect_success '--graph --all' '
52 lib_test_check_graph --all <<-\EOF
53 * A7
54 * A6
55 |\
56 | * C4
57 | * C3
58 * | A5
59 | |
60 | \
61 *-. | A4
62 |\ \|
63 | | * C2
64 | | * C1
65 | * | B2
66 | * | B1
67 * | | A3
68 | |/
69 |/|
70 * | A2
71 |/
72 * A1
73 EOF
74 '
75
76 # Make sure the graph_is_interesting() code still realizes
77 # that undecorated merges are interesting, even with --simplify-by-decoration
78 test_expect_success '--graph --simplify-by-decoration' '
79 git tag -d A4 &&
80 lib_test_check_graph --all --simplify-by-decoration <<-\EOF
81 * A7
82 * A6
83 |\
84 | * C4
85 | * C3
86 * | A5
87 | |
88 | \
89 *-. | A4
90 |\ \|
91 | | * C2
92 | | * C1
93 | * | B2
94 | * | B1
95 * | | A3
96 | |/
97 |/|
98 * | A2
99 |/
100 * A1
101 EOF
102 '
103
104 test_expect_success 'setup: get rid of decorations on B' '
105 git tag -d B2 &&
106 git tag -d B1 &&
107 git branch -d B
108 '
109
110 # Graph with branch B simplified away
111 test_expect_success '--graph --simplify-by-decoration prune branch B' '
112 lib_test_check_graph --simplify-by-decoration --all <<-\EOF
113 * A7
114 * A6
115 |\
116 | * C4
117 | * C3
118 * | A5
119 * | A4
120 |\|
121 | * C2
122 | * C1
123 * | A3
124 |/
125 * A2
126 * A1
127 EOF
128 '
129
130 test_expect_success '--graph --full-history -- bar.txt' '
131 lib_test_check_graph --full-history --all -- bar.txt <<-\EOF
132 * A7
133 * A6
134 |\
135 | * C4
136 * | A5
137 * | A4
138 |\|
139 * | A3
140 |/
141 * A2
142 EOF
143 '
144
145 test_expect_success '--graph --full-history --simplify-merges -- bar.txt' '
146 lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF
147 * A7
148 * A6
149 |\
150 | * C4
151 * | A5
152 * | A3
153 |/
154 * A2
155 EOF
156 '
157
158 test_expect_success '--graph -- bar.txt' '
159 lib_test_check_graph --all -- bar.txt <<-\EOF
160 * A7
161 * A5
162 * A3
163 | * C4
164 |/
165 * A2
166 EOF
167 '
168
169 test_expect_success '--graph --sparse -- bar.txt' '
170 lib_test_check_graph --sparse --all -- bar.txt <<-\EOF
171 * A7
172 * A6
173 * A5
174 * A4
175 * A3
176 | * C4
177 | * C3
178 | * C2
179 | * C1
180 |/
181 * A2
182 * A1
183 EOF
184 '
185
186 test_expect_success '--graph ^C4' '
187 lib_test_check_graph --all ^C4 <<-\EOF
188 * A7
189 * A6
190 * A5
191 * A4
192 |\
193 | * B2
194 | * B1
195 * A3
196 EOF
197 '
198
199 test_expect_success '--graph ^C3' '
200 lib_test_check_graph --all ^C3 <<-\EOF
201 * A7
202 * A6
203 |\
204 | * C4
205 * A5
206 * A4
207 |\
208 | * B2
209 | * B1
210 * A3
211 EOF
212 '
213
214 # I don't think the ordering of the boundary commits is really
215 # that important, but this test depends on it. If the ordering ever changes
216 # in the code, we'll need to update this test.
217 test_expect_success '--graph --boundary ^C3' '
218 lib_test_check_graph --boundary --all ^C3 <<-\EOF
219 * A7
220 * A6
221 |\
222 | * C4
223 * | A5
224 | |
225 | \
226 *-. \ A4
227 |\ \ \
228 | * | | B2
229 | * | | B1
230 * | | | A3
231 o | | | A2
232 |/ / /
233 o / / A1
234 / /
235 | o C3
236 |/
237 o C2
238 EOF
239 '
240
241 test_done