]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6012-rev-list-simplify.sh
tests: mark tests relying on the current default for `init.defaultBranch`
[thirdparty/git.git] / t / t6012-rev-list-simplify.sh
CommitLineData
65347030
JH
1#!/bin/sh
2
3test_description='merge simplification'
4
334afbc7
JS
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
65347030
JH
8. ./test-lib.sh
9
10note () {
11 git tag "$1"
12}
13
65347030 14unnote () {
2ece6ad2 15 git name-rev --tags --stdin | sed -e "s|$OID_REGEX (tags/\([^)]*\)) |\1 |g"
65347030
JH
16}
17
561b5837
DS
18#
19# Create a test repo with interesting commit graph:
20#
21# A--B----------G--H--I--K--L
22# \ \ / /
23# \ \ / /
24# C------E---F J
25# \_/
26#
27# The commits are laid out from left-to-right starting with
28# the root commit A and terminating at the tip commit L.
29#
30# There are a few places where we adjust the commit date or
31# author date to make the --topo-order, --date-order, and
32# --author-date-order flags produce different output.
33
65347030
JH
34test_expect_success setup '
35 echo "Hi there" >file &&
d5d2fc8b
JH
36 echo "initial" >lost &&
37 git add file lost &&
38 test_tick && git commit -m "Initial file and lost" &&
65347030
JH
39 note A &&
40
41 git branch other-branch &&
42
561b5837
DS
43 git symbolic-ref HEAD refs/heads/unrelated &&
44 git rm -f "*" &&
45 echo "Unrelated branch" >side &&
46 git add side &&
47 test_tick && git commit -m "Side root" &&
48 note J &&
49 git checkout master &&
50
65347030 51 echo "Hello" >file &&
d5d2fc8b
JH
52 echo "second" >lost &&
53 git add file lost &&
561b5837 54 test_tick && GIT_AUTHOR_DATE=$(($test_tick + 120)) git commit -m "Modified file and lost" &&
65347030
JH
55 note B &&
56
57 git checkout other-branch &&
58
59 echo "Hello" >file &&
d5d2fc8b
JH
60 >lost &&
61 git add file lost &&
65347030
JH
62 test_tick && git commit -m "Modified the file identically" &&
63 note C &&
64
65 echo "This is a stupid example" >another-file &&
66 git add another-file &&
67 test_tick && git commit -m "Add another file" &&
68 note D &&
69
d5d2fc8b
JH
70 test_tick &&
71 test_must_fail git merge -m "merge" master &&
72 >lost && git commit -a -m "merge" &&
65347030
JH
73 note E &&
74
75 echo "Yet another" >elif &&
76 git add elif &&
77 test_tick && git commit -m "Irrelevant change" &&
78 note F &&
79
80 git checkout master &&
81 echo "Yet another" >elif &&
82 git add elif &&
83 test_tick && git commit -m "Another irrelevant change" &&
84 note G &&
85
86 test_tick && git merge -m "merge" other-branch &&
87 note H &&
88
89 echo "Final change" >file &&
90 test_tick && git commit -a -m "Final change" &&
4b7f53da
JH
91 note I &&
92
4b7f53da 93 git checkout master &&
e379fdf3 94 test_tick && git merge --allow-unrelated-histories -m "Coolest" unrelated &&
4b7f53da
JH
95 note K &&
96
97 echo "Immaterial" >elif &&
98 git add elif &&
99 test_tick && git commit -m "Last" &&
100 note L
65347030
JH
101'
102
103FMT='tformat:%P %H | %s'
104
0290bf12
JH
105check_outcome () {
106 outcome=$1
107 shift
65347030
JH
108 for c in $1
109 do
110 echo "$c"
111 done >expect &&
112 shift &&
113 param="$*" &&
0290bf12 114 test_expect_$outcome "log $param" '
65347030
JH
115 git log --pretty="$FMT" --parents $param |
116 unnote >actual &&
117 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
5ca812a1 118 test_cmp expect check
65347030
JH
119 '
120}
121
0290bf12
JH
122check_result () {
123 check_outcome success "$@"
124}
125
561b5837
DS
126check_result 'L K J I H F E D C G B A' --full-history --topo-order
127check_result 'L K I H G F E D C B J A' --full-history
128check_result 'L K I H G F E D C B J A' --full-history --date-order
129check_result 'L K I H G F E D B C J A' --full-history --author-date-order
4b7f53da
JH
130check_result 'K I H E C B A' --full-history -- file
131check_result 'K I H E C B A' --full-history --topo-order -- file
132check_result 'K I H E C B A' --full-history --date-order -- file
561b5837 133check_result 'K I H E B C A' --full-history --author-date-order -- file
143f1eaf 134check_result 'I E C B A' --simplify-merges -- file
561b5837
DS
135check_result 'I E C B A' --simplify-merges --topo-order -- file
136check_result 'I E C B A' --simplify-merges --date-order -- file
137check_result 'I E B C A' --simplify-merges --author-date-order -- file
65347030
JH
138check_result 'I B A' -- file
139check_result 'I B A' --topo-order -- file
561b5837
DS
140check_result 'I B A' --date-order -- file
141check_result 'I B A' --author-date-order -- file
36ed1913 142check_result 'H' --first-parent -- another-file
561b5837 143check_result 'H' --first-parent --topo-order -- another-file
65347030 144
d5d2fc8b
JH
145check_result 'E C B A' --full-history E -- lost
146test_expect_success 'full history simplification without parent' '
147 printf "%s\n" E C B A >expect &&
148 git log --pretty="$FMT" --full-history E -- lost |
149 unnote >actual &&
150 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
5ca812a1 151 test_cmp expect check
d5d2fc8b
JH
152'
153
53d00b39
TR
154test_expect_success '--full-diff is not affected by --parents' '
155 git log -p --pretty="%H" --full-diff -- file >expected &&
156 git log -p --pretty="%H" --full-diff --parents -- file >actual &&
157 test_cmp expected actual
158'
159
8d049e18
DS
160#
161# Create a new history to demonstrate the value of --show-pulls
162# with respect to the subtleties of simplified history, --full-history,
163# and --simplify-merges.
164#
165# .-A---M-----C--N---O---P
166# / / \ \ \/ / /
167# I B \ R-'`-Z' /
168# \ / \/ /
169# \ / /\ /
170# `---X--' `---Y--'
171#
172# This example is explained in Documentation/rev-list-options.txt
173
2ba31ebd 174test_expect_success 'setup rebuild repo' '
8d049e18
DS
175 rm -rf .git * &&
176 git init &&
538228ed 177 git switch -c topic &&
8d049e18
DS
178
179 echo base >file &&
180 git add file &&
181 test_commit I &&
182
183 echo A >file &&
184 git add file &&
185 test_commit A &&
186
187 git switch -c branchB I &&
188 echo B >file &&
189 git add file &&
190 test_commit B &&
191
538228ed 192 git switch topic &&
8d049e18
DS
193 test_must_fail git merge -m "M" B &&
194 echo A >file &&
195 echo B >>file &&
196 git add file &&
197 git merge --continue &&
198 note M &&
199
200 echo C >other &&
201 git add other &&
202 test_commit C &&
203
204 git switch -c branchX I &&
205 echo X >file &&
206 git add file &&
207 test_commit X &&
208
209 git switch -c branchR M &&
210 git merge -m R -Xtheirs X &&
211 note R &&
212
538228ed 213 git switch topic &&
8d049e18
DS
214 git merge -m N R &&
215 note N &&
216
217 git switch -c branchY M &&
218 echo Y >y &&
219 git add y &&
220 test_commit Y &&
221
222 git switch -c branchZ C &&
223 echo Z >z &&
224 git add z &&
225 test_commit Z &&
226
538228ed 227 git switch topic &&
8d049e18
DS
228 git merge -m O Z &&
229 note O &&
230
231 git merge -m P Y &&
232 note P
233'
234
235check_result 'X I' -- file
236check_result 'N R X I' --show-pulls -- file
237
238check_result 'P O N R X M B A I' --full-history --topo-order -- file
239check_result 'N R X M B A I' --simplify-merges --topo-order --show-pulls -- file
240check_result 'R X M B A I' --simplify-merges --topo-order -- file
241check_result 'N M A I' --first-parent -- file
242check_result 'N M A I' --first-parent --show-pulls -- file
243
244# --ancestry-path implies --full-history
245check_result 'P O N R M' --topo-order \
246 --ancestry-path A..HEAD -- file
247check_result 'P O N R M' --topo-order \
248 --show-pulls \
249 --ancestry-path A..HEAD -- file
250check_result 'P O N R M' --topo-order \
251 --full-history \
252 --ancestry-path A..HEAD -- file
253check_result 'R M' --topo-order \
254 --simplify-merges \
255 --ancestry-path A..HEAD -- file
256check_result 'N R M' --topo-order \
257 --simplify-merges --show-pulls \
258 --ancestry-path A..HEAD -- file
259
260test_expect_success 'log --graph --simplify-merges --show-pulls' '
261 cat >expect <<-\EOF &&
262 * N
263 * R
264 |\
265 | * X
266 * | M
267 |\ \
268 | * | B
269 | |/
270 * / A
271 |/
272 * I
273 EOF
274 git log --graph --pretty="%s" \
275 --simplify-merges --show-pulls \
276 -- file >actual &&
277 test_cmp expect actual
278'
279
65347030 280test_done