3 test_description='merge simplification'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
15 git name-rev --tags --stdin | sed -e "s|$OID_REGEX (tags/\([^)]*\)) |\1 |g"
19 # Create a test repo with interesting commit graph:
21 # A--B----------G--H--I--K--L
27 # The commits are laid out from left-to-right starting with
28 # the root commit A and terminating at the tip commit L.
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.
34 test_expect_success setup '
35 echo "Hi there" >file &&
36 echo "initial" >lost &&
38 test_tick && git commit -m "Initial file and lost" &&
41 git branch other-branch &&
43 git symbolic-ref HEAD refs/heads/unrelated &&
45 echo "Unrelated branch" >side &&
47 test_tick && git commit -m "Side root" &&
52 echo "second" >lost &&
54 test_tick && GIT_AUTHOR_DATE=$(($test_tick + 120)) git commit -m "Modified file and lost" &&
57 git checkout other-branch &&
62 test_tick && git commit -m "Modified the file identically" &&
65 echo "This is a stupid example" >another-file &&
66 git add another-file &&
67 test_tick && git commit -m "Add another file" &&
71 test_must_fail git merge -m "merge" main &&
72 >lost && git commit -a -m "merge" &&
75 echo "Yet another" >elif &&
77 test_tick && git commit -m "Irrelevant change" &&
81 echo "Yet another" >elif &&
83 test_tick && git commit -m "Another irrelevant change" &&
86 test_tick && git merge -m "merge" other-branch &&
89 echo "Final change" >file &&
90 test_tick && git commit -a -m "Final change" &&
94 test_tick && git merge --allow-unrelated-histories -m "Coolest" unrelated &&
97 echo "Immaterial" >elif &&
99 test_tick && git commit -m "Last" &&
103 FMT='tformat:%P %H | %s'
114 test_expect_$outcome "log $param" '
115 git log --pretty="$FMT" --parents $param |
117 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
118 test_cmp expect check
123 check_outcome success "$@"
126 check_result 'L K J I H F E D C G B A' --full-history --topo-order
127 check_result 'L K I H G F E D C B J A' --full-history
128 check_result 'L K I H G F E D C B J A' --full-history --date-order
129 check_result 'L K I H G F E D B C J A' --full-history --author-date-order
130 check_result 'K I H E C B A' --full-history -- file
131 check_result 'K I H E C B A' --full-history --topo-order -- file
132 check_result 'K I H E C B A' --full-history --date-order -- file
133 check_result 'K I H E B C A' --full-history --author-date-order -- file
134 check_result 'I E C B A' --simplify-merges -- file
135 check_result 'I E C B A' --simplify-merges --topo-order -- file
136 check_result 'I E C B A' --simplify-merges --date-order -- file
137 check_result 'I E B C A' --simplify-merges --author-date-order -- file
138 check_result 'I B A' -- file
139 check_result 'I B A' --topo-order -- file
140 check_result 'I B A' --date-order -- file
141 check_result 'I B A' --author-date-order -- file
142 check_result 'H' --first-parent -- another-file
143 check_result 'H' --first-parent --topo-order -- another-file
145 check_result 'E C B A' --full-history E -- lost
146 test_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 |
150 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
151 test_cmp expect check
154 test_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
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.
165 # .-A---M-----C--N---O---P
172 # This example is explained in Documentation/rev-list-options.txt
174 test_expect_success 'setup rebuild repo' '
177 git switch -c topic &&
187 git switch -c branchB I &&
193 test_must_fail git merge -m "M" B &&
197 git merge --continue &&
204 git switch -c branchX I &&
209 git switch -c branchR M &&
210 git merge -m R -Xtheirs X &&
217 git switch -c branchY M &&
222 git switch -c branchZ C &&
235 check_result 'X I' -- file
236 check_result 'N R X I' --show-pulls -- file
238 check_result 'P O N R X M B A I' --full-history --topo-order -- file
239 check_result 'N R X M B A I' --simplify-merges --topo-order --show-pulls -- file
240 check_result 'R X M B A I' --simplify-merges --topo-order -- file
241 check_result 'N M A I' --first-parent -- file
242 check_result 'N M A I' --first-parent --show-pulls -- file
244 # --ancestry-path implies --full-history
245 check_result 'P O N R M' --topo-order \
246 --ancestry-path A..HEAD -- file
247 check_result 'P O N R M' --topo-order \
249 --ancestry-path A..HEAD -- file
250 check_result 'P O N R M' --topo-order \
252 --ancestry-path A..HEAD -- file
253 check_result 'R M' --topo-order \
255 --ancestry-path A..HEAD -- file
256 check_result 'N R M' --topo-order \
257 --simplify-merges --show-pulls \
258 --ancestry-path A..HEAD -- file
260 test_expect_success 'log --graph --simplify-merges --show-pulls' '
261 cat >expect <<-\EOF &&
274 git log --graph --pretty="%s" \
275 --simplify-merges --show-pulls \
277 test_cmp expect actual