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