The eleventh batch
[git/gitster.git] / t / t6012-rev-list-simplify.sh
blob8ed1a215da68ffa042ca44dfd4a4521bee153e47
1 #!/bin/sh
3 test_description='merge simplification'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 note () {
12 git tag "$1"
15 unnote () {
16 test_when_finished "rm -f tmp" &&
17 git name-rev --tags --annotate-stdin >tmp &&
18 sed -e "s|$OID_REGEX (tags/\([^)]*\)) |\1 |g" <tmp
22 # Create a test repo with an interesting commit graph:
24 # A-----B-----G--H--I--K--L
25 # \ \ / /
26 # \ \ / /
27 # C--D--E--F J
29 # The commits are laid out from left-to-right starting with
30 # the root commit A and terminating at the tip commit L.
32 # There are a few places where we adjust the commit date or
33 # author date to make the --topo-order, --date-order, and
34 # --author-date-order flags produce different output.
36 test_expect_success setup '
37 echo "Hi there" >file &&
38 echo "initial" >lost &&
39 git add file lost &&
40 test_tick && git commit -m "Initial file and lost" &&
41 note A &&
43 git branch other-branch &&
45 git symbolic-ref HEAD refs/heads/unrelated &&
46 git rm -f "*" &&
47 echo "Unrelated branch" >side &&
48 git add side &&
49 test_tick && git commit -m "Side root" &&
50 note J &&
51 git checkout main &&
53 echo "Hello" >file &&
54 echo "second" >lost &&
55 git add file lost &&
56 test_tick && GIT_AUTHOR_DATE=$(($test_tick + 120)) git commit -m "Modified file and lost" &&
57 note B &&
59 git checkout other-branch &&
61 echo "Hello" >file &&
62 >lost &&
63 git add file lost &&
64 test_tick && git commit -m "Modified the file identically" &&
65 note C &&
67 echo "This is a stupid example" >another-file &&
68 git add another-file &&
69 test_tick && git commit -m "Add another file" &&
70 note D &&
72 test_tick &&
73 test_must_fail git merge -m "merge" main &&
74 >lost && git commit -a -m "merge" &&
75 note E &&
77 echo "Yet another" >elif &&
78 git add elif &&
79 test_tick && git commit -m "Irrelevant change" &&
80 note F &&
82 git checkout main &&
83 echo "Yet another" >elif &&
84 git add elif &&
85 test_tick && git commit -m "Another irrelevant change" &&
86 note G &&
88 test_tick && git merge -m "merge" other-branch &&
89 note H &&
91 echo "Final change" >file &&
92 test_tick && git commit -a -m "Final change" &&
93 note I &&
95 git checkout main &&
96 test_tick && git merge --allow-unrelated-histories -m "Coolest" unrelated &&
97 note K &&
99 echo "Immaterial" >elif &&
100 git add elif &&
101 test_tick && git commit -m "Last" &&
102 note L
105 FMT='tformat:%P %H | %s'
107 check_outcome () {
108 outcome=$1
109 shift
110 for c in $1
112 echo "$c"
113 done >expect &&
114 shift &&
115 param="$*" &&
116 test_expect_$outcome "log $param" '
117 git log --pretty="$FMT" --parents $param >out &&
118 unnote >actual <out &&
119 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
120 test_cmp expect check
124 check_result () {
125 check_outcome success "$@"
128 check_result 'L K J I H F E D C G B A' --full-history --topo-order
129 check_result 'L K I H G F E D C B J A' --full-history
130 check_result 'L K I H G F E D C B J A' --full-history --date-order
131 check_result 'L K I H G F E D B C J A' --full-history --author-date-order
132 check_result 'K I H E C B A' --full-history -- file
133 check_result 'K I H E C B A' --full-history --topo-order -- file
134 check_result 'K I H E C B A' --full-history --date-order -- file
135 check_result 'K I H E B C A' --full-history --author-date-order -- file
136 check_result 'I E C B A' --simplify-merges -- file
137 check_result 'I E C B A' --simplify-merges --topo-order -- file
138 check_result 'I E C B A' --simplify-merges --date-order -- file
139 check_result 'I E B C A' --simplify-merges --author-date-order -- file
140 check_result 'I B A' -- file
141 check_result 'I B A' --topo-order -- file
142 check_result 'I B A' --date-order -- file
143 check_result 'I B A' --author-date-order -- file
144 check_result 'H' --first-parent -- another-file
145 check_result 'H' --first-parent --topo-order -- another-file
147 check_result 'L K I H G B A' --first-parent L
148 check_result 'F E D C' --exclude-first-parent-only F ^L
149 check_result '' F ^L
150 check_result 'L K I H G J' L ^F
151 check_result 'L K I H G B J' --exclude-first-parent-only L ^F
152 check_result 'L K I H G B' --exclude-first-parent-only --first-parent L ^F
154 check_result 'E C B A' --full-history E -- lost
155 test_expect_success 'full history simplification without parent' '
156 printf "%s\n" E C B A >expect &&
157 git log --pretty="$FMT" --full-history E -- lost >out &&
158 unnote >actual <out &&
159 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
160 test_cmp expect check
163 test_expect_success '--full-diff is not affected by --parents' '
164 git log -p --pretty="%H" --full-diff -- file >expected &&
165 git log -p --pretty="%H" --full-diff --parents -- file >actual &&
166 test_cmp expected actual
170 # Create a new history to demonstrate the value of --show-pulls
171 # with respect to the subtleties of simplified history, --full-history,
172 # and --simplify-merges.
174 # .-A---M-----C--N---O---P
175 # / / \ \ \/ / /
176 # I B \ R-'`-Z' /
177 # \ / \/ /
178 # \ / /\ /
179 # `---X--' `---Y--'
181 # This example is explained in Documentation/rev-list-options.txt
183 test_expect_success 'setup rebuild repo' '
184 rm -rf .git * &&
185 git init &&
186 git switch -c topic &&
188 echo base >file &&
189 git add file &&
190 test_commit I &&
192 echo A >file &&
193 git add file &&
194 test_commit A &&
196 git switch -c branchB I &&
197 echo B >file &&
198 git add file &&
199 test_commit B &&
201 git switch topic &&
202 test_must_fail git merge -m "M" B &&
203 echo A >file &&
204 echo B >>file &&
205 git add file &&
206 git merge --continue &&
207 note M &&
209 echo C >other &&
210 git add other &&
211 test_commit C &&
213 git switch -c branchX I &&
214 echo X >file &&
215 git add file &&
216 test_commit X &&
218 git switch -c branchR M &&
219 git merge -m R -Xtheirs X &&
220 note R &&
222 git switch topic &&
223 git merge -m N R &&
224 note N &&
226 git switch -c branchY M &&
227 echo Y >y &&
228 git add y &&
229 test_commit Y &&
231 git switch -c branchZ C &&
232 echo Z >z &&
233 git add z &&
234 test_commit Z &&
236 git switch topic &&
237 git merge -m O Z &&
238 note O &&
240 git merge -m P Y &&
241 note P
244 check_result 'X I' -- file
245 check_result 'N R X I' --show-pulls -- file
247 check_result 'P O N R X M B A I' --full-history --topo-order -- file
248 check_result 'N R X M B A I' --simplify-merges --topo-order --show-pulls -- file
249 check_result 'R X M B A I' --simplify-merges --topo-order -- file
250 check_result 'N M A I' --first-parent -- file
251 check_result 'N M A I' --first-parent --show-pulls -- file
253 # --ancestry-path implies --full-history
254 check_result 'P O N R M' --topo-order \
255 --ancestry-path A..HEAD -- file
256 check_result 'P O N R M' --topo-order \
257 --show-pulls \
258 --ancestry-path A..HEAD -- file
259 check_result 'P O N R M' --topo-order \
260 --full-history \
261 --ancestry-path A..HEAD -- file
262 check_result 'R M' --topo-order \
263 --simplify-merges \
264 --ancestry-path A..HEAD -- file
265 check_result 'N R M' --topo-order \
266 --simplify-merges --show-pulls \
267 --ancestry-path A..HEAD -- file
269 test_expect_success 'log --graph --simplify-merges --show-pulls' '
270 cat >expect <<-\EOF &&
274 | * X
275 * | M
276 |\ \
277 | * | B
278 | |/
279 * / A
283 git log --graph --pretty="%s" \
284 --simplify-merges --show-pulls \
285 -- file >actual &&
286 test_cmp expect actual
289 test_done