]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6009-rev-list-parent.sh
The third batch
[thirdparty/git.git] / t / t6009-rev-list-parent.sh
CommitLineData
991c3dc7
JH
1#!/bin/sh
2
6a6ebded 3test_description='ancestor culling and limiting by parent number'
991c3dc7 4
1550bb6e 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
716a6b2c 8TEST_PASSES_SANITIZE_LEAK=true
991c3dc7
JH
9. ./test-lib.sh
10
6a6ebded
MG
11check_revlist () {
12 rev_list_args="$1" &&
13 shift &&
14 git rev-parse "$@" >expect &&
15 git rev-list $rev_list_args --all >actual &&
16 test_cmp expect actual
17}
18
991c3dc7
JH
19test_expect_success setup '
20
21 touch file &&
22 git add file &&
23
8ee50594 24 test_commit one &&
991c3dc7 25
a48fcd83 26 test_tick=$(($test_tick - 2400)) &&
991c3dc7 27
8ee50594
MG
28 test_commit two &&
29 test_commit three &&
30 test_commit four &&
991c3dc7
JH
31
32 git log --pretty=oneline --abbrev-commit
33'
34
7d004199 35test_expect_success 'one is ancestor of others and should not be shown' '
991c3dc7
JH
36
37 git rev-list one --not four >result &&
d3c6751b 38 test_must_be_empty result
991c3dc7
JH
39
40'
41
6a6ebded
MG
42test_expect_success 'setup roots, merges and octopuses' '
43
44 git checkout --orphan newroot &&
45 test_commit five &&
46 git checkout -b sidebranch two &&
47 test_commit six &&
48 git checkout -b anotherbranch three &&
49 test_commit seven &&
50 git checkout -b yetanotherbranch four &&
51 test_commit eight &&
1550bb6e 52 git checkout main &&
e379fdf3
JH
53 test_tick &&
54 git merge --allow-unrelated-histories -m normalmerge newroot &&
55 git tag normalmerge &&
6a6ebded
MG
56 test_tick &&
57 git merge -m tripus sidebranch anotherbranch &&
58 git tag tripus &&
59 git checkout -b tetrabranch normalmerge &&
60 test_tick &&
61 git merge -m tetrapus sidebranch anotherbranch yetanotherbranch &&
62 git tag tetrapus &&
1550bb6e 63 git checkout main
6a6ebded
MG
64'
65
71a1e948
JH
66test_expect_success 'parse --max-parents & --min-parents' '
67 test_must_fail git rev-list --max-parents=1q HEAD 2>error &&
68 grep "not an integer" error &&
69
70 test_must_fail git rev-list --min-parents=1q HEAD 2>error &&
71 grep "not an integer" error &&
72
73 git rev-list --max-parents=1 --min-parents=1 HEAD &&
74 git rev-list --max-parents=-1 --min-parents=-1 HEAD
75'
76
6a6ebded
MG
77test_expect_success 'rev-list roots' '
78
79 check_revlist "--max-parents=0" one five
80'
81
82test_expect_success 'rev-list no merges' '
83
84 check_revlist "--max-parents=1" one eight seven six five four three two &&
85 check_revlist "--no-merges" one eight seven six five four three two
86'
87
88test_expect_success 'rev-list no octopuses' '
89
90 check_revlist "--max-parents=2" one normalmerge eight seven six five four three two
91'
92
93test_expect_success 'rev-list no roots' '
94
95 check_revlist "--min-parents=1" tetrapus tripus normalmerge eight seven six four three two
96'
97
98test_expect_success 'rev-list merges' '
99
100 check_revlist "--min-parents=2" tetrapus tripus normalmerge &&
101 check_revlist "--merges" tetrapus tripus normalmerge
102'
103
104test_expect_success 'rev-list octopus' '
105
106 check_revlist "--min-parents=3" tetrapus tripus
107'
108
109test_expect_success 'rev-list ordinary commits' '
110
111 check_revlist "--min-parents=1 --max-parents=1" eight seven six four three two
112'
113
114test_expect_success 'rev-list --merges --no-merges yields empty set' '
115
116 check_revlist "--min-parents=2 --no-merges" &&
117 check_revlist "--merges --no-merges" &&
118 check_revlist "--no-merges --merges"
119'
120
121test_expect_success 'rev-list override and infinities' '
122
123 check_revlist "--min-parents=2 --max-parents=1 --max-parents=3" tripus normalmerge &&
124 check_revlist "--min-parents=1 --min-parents=2 --max-parents=7" tetrapus tripus normalmerge &&
125 check_revlist "--min-parents=2 --max-parents=8" tetrapus tripus normalmerge &&
126 check_revlist "--min-parents=2 --max-parents=-1" tetrapus tripus normalmerge &&
127 check_revlist "--min-parents=2 --no-max-parents" tetrapus tripus normalmerge &&
128 check_revlist "--max-parents=0 --min-parents=1 --no-min-parents" one five
129'
130
482ce70e 131test_expect_success 'dodecapus' '
6a6ebded 132
482ce70e 133 roots= &&
6a6ebded
MG
134 for i in 1 2 3 4 5 6 7 8 9 10 11
135 do
482ce70e
JN
136 git checkout -b root$i five &&
137 test_commit $i &&
138 roots="$roots root$i" ||
0c51d6b4 139 return 1
6a6ebded 140 done &&
1550bb6e 141 git checkout main &&
6a6ebded 142 test_tick &&
482ce70e
JN
143 git merge -m dodecapus $roots &&
144 git tag dodecapus &&
6a6ebded
MG
145
146 check_revlist "--min-parents=4" dodecapus tetrapus &&
147 check_revlist "--min-parents=8" dodecapus &&
148 check_revlist "--min-parents=12" dodecapus &&
149 check_revlist "--min-parents=13" &&
150 check_revlist "--min-parents=4 --max-parents=11" tetrapus
151'
c19d1b4e
KK
152
153test_expect_success 'ancestors with the same commit time' '
154
155 test_tick_keep=$test_tick &&
156 for i in 1 2 3 4 5 6 7 8; do
74d2f569 157 test_tick=$test_tick_keep &&
0c51d6b4 158 test_commit t$i || return 1
c19d1b4e
KK
159 done &&
160 git rev-list t1^! --not t$i >result &&
d3c6751b 161 test_must_be_empty result
c19d1b4e
KK
162'
163
991c3dc7 164test_done