Git 2.45
[git/gitster.git] / t / t6016-rev-list-graph-simplify-history.sh
blob54b0a6f5f8a4b2996bd49ab3251837967f8fd57a
1 #!/bin/sh
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.
8 test_description='--graph and simplified history'
10 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
11 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13 . ./test-lib.sh
14 . "$TEST_DIRECTORY"/lib-log-graph.sh
16 check_graph () {
17 cat >expect &&
18 lib_test_cmp_graph --format=%s "$@"
21 test_expect_success 'set up rev-list --graph test' '
22 # 3 commits on branch A
23 test_commit A1 foo.txt &&
24 test_commit A2 bar.txt &&
25 test_commit A3 bar.txt &&
26 git branch -m main A &&
28 # 2 commits on branch B, started from A1
29 git checkout -b B A1 &&
30 test_commit B1 foo.txt &&
31 test_commit B2 abc.txt &&
33 # 2 commits on branch C, started from A2
34 git checkout -b C A2 &&
35 test_commit C1 xyz.txt &&
36 test_commit C2 xyz.txt &&
38 # Octopus merge B and C into branch A
39 git checkout A &&
40 git merge B C -m A4 &&
41 git tag A4 &&
43 test_commit A5 bar.txt &&
45 # More commits on C, then merge C into A
46 git checkout C &&
47 test_commit C3 foo.txt &&
48 test_commit C4 bar.txt &&
49 git checkout A &&
50 git merge -s ours C -m A6 &&
51 git tag A6 &&
53 test_commit A7 bar.txt
56 test_expect_success '--graph --all' '
57 check_graph --all <<-\EOF
58 * A7
59 * A6
61 | * C4
62 | * C3
63 * | A5
64 | |
65 | \
66 *-. | A4
67 |\ \|
68 | | * C2
69 | | * C1
70 | * | B2
71 | * | B1
72 * | | A3
73 | |/
74 |/|
75 * | A2
77 * A1
78 EOF
81 # Make sure the graph_is_interesting() code still realizes
82 # that undecorated merges are interesting, even with --simplify-by-decoration
83 test_expect_success '--graph --simplify-by-decoration' '
84 git tag -d A4 &&
85 check_graph --all --simplify-by-decoration <<-\EOF
86 * A7
87 * A6
89 | * C4
90 | * C3
91 * | A5
92 | |
93 | \
94 *-. | A4
95 |\ \|
96 | | * C2
97 | | * C1
98 | * | B2
99 | * | B1
100 * | | A3
101 | |/
103 * | A2
105 * A1
109 test_expect_success 'setup: get rid of decorations on B' '
110 git tag -d B2 &&
111 git tag -d B1 &&
112 git branch -d B
115 # Graph with branch B simplified away
116 test_expect_success '--graph --simplify-by-decoration prune branch B' '
117 check_graph --simplify-by-decoration --all <<-\EOF
118 * A7
119 * A6
121 | * C4
122 | * C3
123 * | A5
124 * | A4
126 | * C2
127 | * C1
128 * | A3
130 * A2
131 * A1
135 test_expect_success '--graph --full-history -- bar.txt' '
136 check_graph --full-history --all -- bar.txt <<-\EOF
137 * A7
138 * A6
140 | * C4
141 * | A5
142 * | A4
144 * | A3
146 * A2
150 test_expect_success '--graph --full-history --simplify-merges -- bar.txt' '
151 check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF
152 * A7
153 * A6
155 | * C4
156 * | A5
157 * | A3
159 * A2
163 test_expect_success '--graph -- bar.txt' '
164 check_graph --all -- bar.txt <<-\EOF
165 * A7
166 * A5
167 * A3
168 | * C4
170 * A2
174 test_expect_success '--graph --sparse -- bar.txt' '
175 check_graph --sparse --all -- bar.txt <<-\EOF
176 * A7
177 * A6
178 * A5
179 * A4
180 * A3
181 | * C4
182 | * C3
183 | * C2
184 | * C1
186 * A2
187 * A1
191 test_expect_success '--graph ^C4' '
192 check_graph --all ^C4 <<-\EOF
193 * A7
194 * A6
195 * A5
196 * A4
198 | * B2
199 | * B1
200 * A3
204 test_expect_success '--graph ^C3' '
205 check_graph --all ^C3 <<-\EOF
206 * A7
207 * A6
209 | * C4
210 * A5
211 * A4
213 | * B2
214 | * B1
215 * A3
219 # I don't think the ordering of the boundary commits is really
220 # that important, but this test depends on it. If the ordering ever changes
221 # in the code, we'll need to update this test.
222 test_expect_success '--graph --boundary ^C3' '
223 check_graph --boundary --all ^C3 <<-\EOF
224 * A7
225 * A6
227 | * C4
228 * | A5
231 *-. \ A4
232 |\ \ \
233 | * | | B2
234 | * | | B1
235 * | | | A3
236 o | | | A2
237 |/ / /
238 o / / A1
240 | o C3
242 o C2
246 test_done