3 test_description
='merge simplification'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
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
21 # Create a test repo with an interesting commit graph:
23 # A-----B-----G--H--I--K--L
28 # The commits are laid out from left-to-right starting with
29 # the root commit A and terminating at the tip commit L.
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.
35 test_expect_success setup
'
36 echo "Hi there" >file &&
37 echo "initial" >lost &&
39 test_tick && git commit -m "Initial file and lost" &&
42 git branch other-branch &&
44 git symbolic-ref HEAD refs/heads/unrelated &&
46 echo "Unrelated branch" >side &&
48 test_tick && git commit -m "Side root" &&
53 echo "second" >lost &&
55 test_tick && GIT_AUTHOR_DATE=$(($test_tick + 120)) git commit -m "Modified file and lost" &&
58 git checkout other-branch &&
63 test_tick && git commit -m "Modified the file identically" &&
66 echo "This is a stupid example" >another-file &&
67 git add another-file &&
68 test_tick && git commit -m "Add another file" &&
72 test_must_fail git merge -m "merge" main &&
73 >lost && git commit -a -m "merge" &&
76 echo "Yet another" >elif &&
78 test_tick && git commit -m "Irrelevant change" &&
82 echo "Yet another" >elif &&
84 test_tick && git commit -m "Another irrelevant change" &&
87 test_tick && git merge -m "merge" other-branch &&
90 echo "Final change" >file &&
91 test_tick && git commit -a -m "Final change" &&
95 test_tick && git merge --allow-unrelated-histories -m "Coolest" unrelated &&
98 echo "Immaterial" >elif &&
100 test_tick && git commit -m "Last" &&
104 FMT
='tformat:%P %H | %s'
115 test_expect_
$outcome "log $param" '
116 git log --pretty="$FMT" --parents $param >out &&
117 unnote >actual <out &&
118 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
119 test_cmp expect check
124 check_outcome success
"$@"
127 check_result
'L K J I H F E D C G B A' --full-history --topo-order
128 check_result
'L K I H G F E D C B J A' --full-history
129 check_result
'L K I H G F E D C B J A' --full-history --date-order
130 check_result
'L K I H G F E D B C J A' --full-history --author-date-order
131 check_result
'K I H E C B A' --full-history -- file
132 check_result
'K I H E C B A' --full-history --topo-order -- file
133 check_result
'K I H E C B A' --full-history --date-order -- file
134 check_result
'K I H E B C A' --full-history --author-date-order -- file
135 check_result
'I E C B A' --simplify-merges -- file
136 check_result
'I E C B A' --simplify-merges --topo-order -- file
137 check_result
'I E C B A' --simplify-merges --date-order -- file
138 check_result
'I E B C A' --simplify-merges --author-date-order -- file
139 check_result
'I B A' -- file
140 check_result
'I B A' --topo-order -- file
141 check_result
'I B A' --date-order -- file
142 check_result
'I B A' --author-date-order -- file
143 check_result
'H' --first-parent -- another-file
144 check_result
'H' --first-parent --topo-order -- another-file
146 check_result
'L K I H G B A' --first-parent L
147 check_result
'F E D C' --exclude-first-parent-only F ^L
149 check_result
'L K I H G J' L ^F
150 check_result
'L K I H G B J' --exclude-first-parent-only L ^F
151 check_result
'L K I H G B' --exclude-first-parent-only --first-parent L ^F
153 check_result
'E C B A' --full-history E
-- lost
154 test_expect_success
'full history simplification without parent' '
155 printf "%s\n" E C B A >expect &&
156 git log --pretty="$FMT" --full-history E -- lost >out &&
157 unnote >actual <out &&
158 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
159 test_cmp expect check
162 test_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
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.
173 # .-A---M-----C--N---O---P
180 # This example is explained in Documentation/rev-list-options.txt
182 test_expect_success
'setup rebuild repo' '
185 git switch -c topic &&
195 git switch -c branchB I &&
201 test_must_fail git merge -m "M" B &&
205 git merge --continue &&
212 git switch -c branchX I &&
217 git switch -c branchR M &&
218 git merge -m R -Xtheirs X &&
225 git switch -c branchY M &&
230 git switch -c branchZ C &&
243 check_result
'X I' -- file
244 check_result
'N R X I' --show-pulls -- file
246 check_result
'P O N R X M B A I' --full-history --topo-order -- file
247 check_result
'N R X M B A I' --simplify-merges --topo-order --show-pulls -- file
248 check_result
'R X M B A I' --simplify-merges --topo-order -- file
249 check_result
'N M A I' --first-parent -- file
250 check_result
'N M A I' --first-parent --show-pulls -- file
252 # --ancestry-path implies --full-history
253 check_result
'P O N R M' --topo-order \
254 --ancestry-path A..HEAD
-- file
255 check_result
'P O N R M' --topo-order \
257 --ancestry-path A..HEAD
-- file
258 check_result
'P O N R M' --topo-order \
260 --ancestry-path A..HEAD
-- file
261 check_result
'R M' --topo-order \
263 --ancestry-path A..HEAD
-- file
264 check_result
'N R M' --topo-order \
265 --simplify-merges --show-pulls \
266 --ancestry-path A..HEAD
-- file
268 test_expect_success
'log --graph --simplify-merges --show-pulls' '
269 cat >expect <<-\EOF &&
282 git log --graph --pretty="%s" \
283 --simplify-merges --show-pulls \
285 test_cmp expect actual