Git 2.32
[git] / t / t6016-rev-list-graph-simplify-history.sh
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 check_graph () {
17         cat >expect &&
18         lib_test_cmp_graph --format=%s "$@"
19 }
20
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 &&
27
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 &&
32
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 &&
37
38         # Octopus merge B and C into branch A
39         git checkout A &&
40         git merge B C -m A4 &&
41         git tag A4 &&
42
43         test_commit A5 bar.txt &&
44
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 &&
52
53         test_commit A7 bar.txt
54 '
55
56 test_expect_success '--graph --all' '
57         check_graph --all <<-\EOF
58         * A7
59         *   A6
60         |\
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
76         |/
77         * A1
78         EOF
79 '
80
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
88         |\
89         | * C4
90         | * C3
91         * | A5
92         | |
93         |  \
94         *-. | A4
95         |\ \|
96         | | * C2
97         | | * C1
98         | * | B2
99         | * | B1
100         * | | A3
101         | |/
102         |/|
103         * | A2
104         |/
105         * A1
106         EOF
107 '
108
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
113 '
114
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
120         |\
121         | * C4
122         | * C3
123         * | A5
124         * | A4
125         |\|
126         | * C2
127         | * C1
128         * | A3
129         |/
130         * A2
131         * A1
132         EOF
133 '
134
135 test_expect_success '--graph --full-history -- bar.txt' '
136         check_graph --full-history --all -- bar.txt <<-\EOF
137         * A7
138         *   A6
139         |\
140         | * C4
141         * | A5
142         * | A4
143         |\|
144         * | A3
145         |/
146         * A2
147         EOF
148 '
149
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
154         |\
155         | * C4
156         * | A5
157         * | A3
158         |/
159         * A2
160         EOF
161 '
162
163 test_expect_success '--graph -- bar.txt' '
164         check_graph --all -- bar.txt <<-\EOF
165         * A7
166         * A5
167         * A3
168         | * C4
169         |/
170         * A2
171         EOF
172 '
173
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
185         |/
186         * A2
187         * A1
188         EOF
189 '
190
191 test_expect_success '--graph ^C4' '
192         check_graph --all ^C4 <<-\EOF
193         * A7
194         * A6
195         * A5
196         *   A4
197         |\
198         | * B2
199         | * B1
200         * A3
201         EOF
202 '
203
204 test_expect_success '--graph ^C3' '
205         check_graph --all ^C3 <<-\EOF
206         * A7
207         *   A6
208         |\
209         | * C4
210         * A5
211         *   A4
212         |\
213         | * B2
214         | * B1
215         * A3
216         EOF
217 '
218
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
226         |\
227         | * C4
228         * | A5
229         | |
230         |  \
231         *-. \   A4
232         |\ \ \
233         | * | | B2
234         | * | | B1
235         * | | | A3
236         o | | | A2
237         |/ / /
238         o / / A1
239          / /
240         | o C3
241         |/
242         o C2
243         EOF
244 '
245
246 test_done