mailmap.c: fix a memory leak in free_mailap_{info,entry}()
[alt-git.git] / t / t6012-rev-list-simplify.sh
blob4f7fa8b6c037bd45b2b4a6836609e35b820cbce6
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-lib.sh
10 note () {
11 git tag "$1"
14 unnote () {
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
22 # \ \ / /
23 # \ \ / /
24 # C------E---F J
25 # \_/
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 &&
37 git add file lost &&
38 test_tick && git commit -m "Initial file and lost" &&
39 note A &&
41 git branch other-branch &&
43 git symbolic-ref HEAD refs/heads/unrelated &&
44 git rm -f "*" &&
45 echo "Unrelated branch" >side &&
46 git add side &&
47 test_tick && git commit -m "Side root" &&
48 note J &&
49 git checkout main &&
51 echo "Hello" >file &&
52 echo "second" >lost &&
53 git add file lost &&
54 test_tick && GIT_AUTHOR_DATE=$(($test_tick + 120)) git commit -m "Modified file and lost" &&
55 note B &&
57 git checkout other-branch &&
59 echo "Hello" >file &&
60 >lost &&
61 git add file lost &&
62 test_tick && git commit -m "Modified the file identically" &&
63 note C &&
65 echo "This is a stupid example" >another-file &&
66 git add another-file &&
67 test_tick && git commit -m "Add another file" &&
68 note D &&
70 test_tick &&
71 test_must_fail git merge -m "merge" main &&
72 >lost && git commit -a -m "merge" &&
73 note E &&
75 echo "Yet another" >elif &&
76 git add elif &&
77 test_tick && git commit -m "Irrelevant change" &&
78 note F &&
80 git checkout main &&
81 echo "Yet another" >elif &&
82 git add elif &&
83 test_tick && git commit -m "Another irrelevant change" &&
84 note G &&
86 test_tick && git merge -m "merge" other-branch &&
87 note H &&
89 echo "Final change" >file &&
90 test_tick && git commit -a -m "Final change" &&
91 note I &&
93 git checkout main &&
94 test_tick && git merge --allow-unrelated-histories -m "Coolest" unrelated &&
95 note K &&
97 echo "Immaterial" >elif &&
98 git add elif &&
99 test_tick && git commit -m "Last" &&
100 note L
103 FMT='tformat:%P %H | %s'
105 check_outcome () {
106 outcome=$1
107 shift
108 for c in $1
110 echo "$c"
111 done >expect &&
112 shift &&
113 param="$*" &&
114 test_expect_$outcome "log $param" '
115 git log --pretty="$FMT" --parents $param |
116 unnote >actual &&
117 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
118 test_cmp expect check
122 check_result () {
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 |
149 unnote >actual &&
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
166 # / / \ \ \/ / /
167 # I B \ R-'`-Z' /
168 # \ / \/ /
169 # \ / /\ /
170 # `---X--' `---Y--'
172 # This example is explained in Documentation/rev-list-options.txt
174 test_expect_success 'setup rebuild repo' '
175 rm -rf .git * &&
176 git init &&
177 git switch -c topic &&
179 echo base >file &&
180 git add file &&
181 test_commit I &&
183 echo A >file &&
184 git add file &&
185 test_commit A &&
187 git switch -c branchB I &&
188 echo B >file &&
189 git add file &&
190 test_commit B &&
192 git switch topic &&
193 test_must_fail git merge -m "M" B &&
194 echo A >file &&
195 echo B >>file &&
196 git add file &&
197 git merge --continue &&
198 note M &&
200 echo C >other &&
201 git add other &&
202 test_commit C &&
204 git switch -c branchX I &&
205 echo X >file &&
206 git add file &&
207 test_commit X &&
209 git switch -c branchR M &&
210 git merge -m R -Xtheirs X &&
211 note R &&
213 git switch topic &&
214 git merge -m N R &&
215 note N &&
217 git switch -c branchY M &&
218 echo Y >y &&
219 git add y &&
220 test_commit Y &&
222 git switch -c branchZ C &&
223 echo Z >z &&
224 git add z &&
225 test_commit Z &&
227 git switch topic &&
228 git merge -m O Z &&
229 note O &&
231 git merge -m P Y &&
232 note P
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 \
248 --show-pulls \
249 --ancestry-path A..HEAD -- file
250 check_result 'P O N R M' --topo-order \
251 --full-history \
252 --ancestry-path A..HEAD -- file
253 check_result 'R M' --topo-order \
254 --simplify-merges \
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 &&
265 | * X
266 * | M
267 |\ \
268 | * | B
269 | |/
270 * / A
274 git log --graph --pretty="%s" \
275 --simplify-merges --show-pulls \
276 -- file >actual &&
277 test_cmp expect actual
280 test_done