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
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
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 &&
40 test_tick && git commit -m "Initial file and lost" &&
43 git branch other-branch &&
45 git symbolic-ref HEAD refs/heads/unrelated &&
47 echo "Unrelated branch" >side &&
49 test_tick && git commit -m "Side root" &&
54 echo "second" >lost &&
56 test_tick && GIT_AUTHOR_DATE=$(($test_tick + 120)) git commit -m "Modified file and lost" &&
59 git checkout other-branch &&
64 test_tick && git commit -m "Modified the file identically" &&
67 echo "This is a stupid example" >another-file &&
68 git add another-file &&
69 test_tick && git commit -m "Add another file" &&
73 test_must_fail git merge -m "merge" main &&
74 >lost && git commit -a -m "merge" &&
77 echo "Yet another" >elif &&
79 test_tick && git commit -m "Irrelevant change" &&
83 echo "Yet another" >elif &&
85 test_tick && git commit -m "Another irrelevant change" &&
88 test_tick && git merge -m "merge" other-branch &&
91 echo "Final change" >file &&
92 test_tick && git commit -a -m "Final change" &&
96 test_tick && git merge --allow-unrelated-histories -m "Coolest" unrelated &&
99 echo "Immaterial" >elif &&
101 test_tick && git commit -m "Last" &&
105 FMT
='tformat:%P %H | %s'
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
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
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
181 # This example is explained in Documentation/rev-list-options.txt
183 test_expect_success
'setup rebuild repo' '
186 git switch -c topic &&
196 git switch -c branchB I &&
202 test_must_fail git merge -m "M" B &&
206 git merge --continue &&
213 git switch -c branchX I &&
218 git switch -c branchR M &&
219 git merge -m R -Xtheirs X &&
226 git switch -c branchY M &&
231 git switch -c branchZ C &&
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 \
258 --ancestry-path A..HEAD
-- file
259 check_result
'P O N R M' --topo-order \
261 --ancestry-path A..HEAD
-- file
262 check_result
'R M' --topo-order \
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 &&
283 git log --graph --pretty="%s" \
284 --simplify-merges --show-pulls \
286 test_cmp expect actual