Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Jon Seymour |
| 4 | # |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 5 | test_description='Tests git rev-list --bisect functionality' |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 6 | |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 7 | . ./test-lib.sh |
Ævar Arnfjörð Bjarmason | 9d488eb | 2010-05-07 19:37:01 +0000 | [diff] [blame] | 8 | . "$TEST_DIRECTORY"/lib-t6000.sh # t6xxx specific functions |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 9 | |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 10 | # usage: test_bisection max-diff bisect-option head ^prune... |
| 11 | # |
| 12 | # e.g. test_bisection 1 --bisect l1 ^l0 |
| 13 | # |
| 14 | test_bisection_diff() |
| 15 | { |
| 16 | _max_diff=$1 |
| 17 | _bisect_option=$2 |
| 18 | shift 2 |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 19 | _bisection=$(git rev-list $_bisect_option "$@") |
| 20 | _list_size=$(git rev-list "$@" | wc -l) |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 21 | _head=$1 |
| 22 | shift 1 |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 23 | _bisection_size=$(git rev-list $_bisection "$@" | wc -l) |
Junio C Hamano | 455a7f3 | 2005-09-30 13:31:16 -0700 | [diff] [blame] | 24 | [ -n "$_list_size" -a -n "$_bisection_size" ] || |
| 25 | error "test_bisection_diff failed" |
| 26 | |
| 27 | # Test if bisection size is close to half of list size within |
| 28 | # tolerance. |
Junio C Hamano | a6080a0 | 2007-06-07 00:04:01 -0700 | [diff] [blame] | 29 | # |
Elia Pinto | 3a9992b | 2016-01-07 14:51:43 +0100 | [diff] [blame] | 30 | _bisect_err=$(expr $_list_size - $_bisection_size \* 2) |
| 31 | test "$_bisect_err" -lt 0 && _bisect_err=$(expr 0 - $_bisect_err) |
| 32 | _bisect_err=$(expr $_bisect_err / 2) ; # floor |
Junio C Hamano | 455a7f3 | 2005-09-30 13:31:16 -0700 | [diff] [blame] | 33 | |
| 34 | test_expect_success \ |
| 35 | "bisection diff $_bisect_option $_head $* <= $_max_diff" \ |
| 36 | 'test $_bisect_err -le $_max_diff' |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | date >path0 |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 40 | git update-index --add path0 |
| 41 | save_tag tree git write-tree |
Junio C Hamano | 841dc69 | 2013-06-21 10:29:59 -0700 | [diff] [blame] | 42 | on_committer_date "00:00" hide_error save_tag root unique_commit root tree |
| 43 | on_committer_date "00:01" save_tag l0 unique_commit l0 tree -p root |
| 44 | on_committer_date "00:02" save_tag l1 unique_commit l1 tree -p l0 |
| 45 | on_committer_date "00:03" save_tag l2 unique_commit l2 tree -p l1 |
| 46 | on_committer_date "00:04" save_tag a0 unique_commit a0 tree -p l2 |
| 47 | on_committer_date "00:05" save_tag a1 unique_commit a1 tree -p a0 |
| 48 | on_committer_date "00:06" save_tag b1 unique_commit b1 tree -p a0 |
| 49 | on_committer_date "00:07" save_tag c1 unique_commit c1 tree -p b1 |
| 50 | on_committer_date "00:08" save_tag b2 unique_commit b2 tree -p b1 |
| 51 | on_committer_date "00:09" save_tag b3 unique_commit b2 tree -p b2 |
| 52 | on_committer_date "00:10" save_tag c2 unique_commit c2 tree -p c1 -p b2 |
| 53 | on_committer_date "00:11" save_tag c3 unique_commit c3 tree -p c2 |
| 54 | on_committer_date "00:12" save_tag a2 unique_commit a2 tree -p a1 |
| 55 | on_committer_date "00:13" save_tag a3 unique_commit a3 tree -p a2 |
| 56 | on_committer_date "00:14" save_tag b4 unique_commit b4 tree -p b3 -p a3 |
| 57 | on_committer_date "00:15" save_tag a4 unique_commit a4 tree -p a3 -p b4 -p c3 |
| 58 | on_committer_date "00:16" save_tag l3 unique_commit l3 tree -p a4 |
| 59 | on_committer_date "00:17" save_tag l4 unique_commit l4 tree -p l3 |
| 60 | on_committer_date "00:18" save_tag l5 unique_commit l5 tree -p l4 |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 61 | git update-ref HEAD $(tag l5) |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 62 | |
| 63 | |
| 64 | # E |
| 65 | # / \ |
| 66 | # e1 | |
| 67 | # | | |
| 68 | # e2 | |
| 69 | # | | |
| 70 | # e3 | |
| 71 | # | | |
| 72 | # e4 | |
| 73 | # | | |
| 74 | # | f1 |
| 75 | # | | |
| 76 | # | f2 |
| 77 | # | | |
| 78 | # | f3 |
| 79 | # | | |
| 80 | # | f4 |
| 81 | # | | |
| 82 | # e5 | |
| 83 | # | | |
| 84 | # e6 | |
| 85 | # | | |
| 86 | # e7 | |
| 87 | # | | |
| 88 | # e8 | |
| 89 | # \ / |
| 90 | # F |
| 91 | |
| 92 | |
Junio C Hamano | 841dc69 | 2013-06-21 10:29:59 -0700 | [diff] [blame] | 93 | on_committer_date "00:00" hide_error save_tag F unique_commit F tree |
| 94 | on_committer_date "00:01" save_tag e8 unique_commit e8 tree -p F |
| 95 | on_committer_date "00:02" save_tag e7 unique_commit e7 tree -p e8 |
| 96 | on_committer_date "00:03" save_tag e6 unique_commit e6 tree -p e7 |
| 97 | on_committer_date "00:04" save_tag e5 unique_commit e5 tree -p e6 |
| 98 | on_committer_date "00:05" save_tag f4 unique_commit f4 tree -p F |
| 99 | on_committer_date "00:06" save_tag f3 unique_commit f3 tree -p f4 |
| 100 | on_committer_date "00:07" save_tag f2 unique_commit f2 tree -p f3 |
| 101 | on_committer_date "00:08" save_tag f1 unique_commit f1 tree -p f2 |
| 102 | on_committer_date "00:09" save_tag e4 unique_commit e4 tree -p e5 |
| 103 | on_committer_date "00:10" save_tag e3 unique_commit e3 tree -p e4 |
| 104 | on_committer_date "00:11" save_tag e2 unique_commit e2 tree -p e3 |
| 105 | on_committer_date "00:12" save_tag e1 unique_commit e1 tree -p e2 |
| 106 | on_committer_date "00:13" save_tag E unique_commit E tree -p e1 -p f1 |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 107 | |
Junio C Hamano | 841dc69 | 2013-06-21 10:29:59 -0700 | [diff] [blame] | 108 | on_committer_date "00:00" hide_error save_tag U unique_commit U tree |
| 109 | on_committer_date "00:01" save_tag u0 unique_commit u0 tree -p U |
| 110 | on_committer_date "00:01" save_tag u1 unique_commit u1 tree -p u0 |
| 111 | on_committer_date "00:02" save_tag u2 unique_commit u2 tree -p u0 |
| 112 | on_committer_date "00:03" save_tag u3 unique_commit u3 tree -p u0 |
| 113 | on_committer_date "00:04" save_tag u4 unique_commit u4 tree -p u0 |
| 114 | on_committer_date "00:05" save_tag u5 unique_commit u5 tree -p u0 |
| 115 | on_committer_date "00:06" save_tag V unique_commit V tree -p u1 -p u2 -p u3 -p u4 -p u5 |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 116 | |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 117 | test_sequence() |
| 118 | { |
Junio C Hamano | a6080a0 | 2007-06-07 00:04:01 -0700 | [diff] [blame] | 119 | _bisect_option=$1 |
| 120 | |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 121 | test_bisection_diff 0 $_bisect_option l0 ^root |
| 122 | test_bisection_diff 0 $_bisect_option l1 ^root |
| 123 | test_bisection_diff 0 $_bisect_option l2 ^root |
| 124 | test_bisection_diff 0 $_bisect_option a0 ^root |
| 125 | test_bisection_diff 0 $_bisect_option a1 ^root |
| 126 | test_bisection_diff 0 $_bisect_option a2 ^root |
| 127 | test_bisection_diff 0 $_bisect_option a3 ^root |
| 128 | test_bisection_diff 0 $_bisect_option b1 ^root |
| 129 | test_bisection_diff 0 $_bisect_option b2 ^root |
| 130 | test_bisection_diff 0 $_bisect_option b3 ^root |
| 131 | test_bisection_diff 0 $_bisect_option c1 ^root |
| 132 | test_bisection_diff 0 $_bisect_option c2 ^root |
| 133 | test_bisection_diff 0 $_bisect_option c3 ^root |
| 134 | test_bisection_diff 0 $_bisect_option E ^F |
| 135 | test_bisection_diff 0 $_bisect_option e1 ^F |
| 136 | test_bisection_diff 0 $_bisect_option e2 ^F |
| 137 | test_bisection_diff 0 $_bisect_option e3 ^F |
| 138 | test_bisection_diff 0 $_bisect_option e4 ^F |
| 139 | test_bisection_diff 0 $_bisect_option e5 ^F |
| 140 | test_bisection_diff 0 $_bisect_option e6 ^F |
| 141 | test_bisection_diff 0 $_bisect_option e7 ^F |
| 142 | test_bisection_diff 0 $_bisect_option f1 ^F |
| 143 | test_bisection_diff 0 $_bisect_option f2 ^F |
| 144 | test_bisection_diff 0 $_bisect_option f3 ^F |
| 145 | test_bisection_diff 0 $_bisect_option f4 ^F |
| 146 | test_bisection_diff 0 $_bisect_option E ^F |
| 147 | |
| 148 | test_bisection_diff 1 $_bisect_option V ^U |
| 149 | test_bisection_diff 0 $_bisect_option V ^U ^u1 ^u2 ^u3 |
| 150 | test_bisection_diff 0 $_bisect_option u1 ^U |
| 151 | test_bisection_diff 0 $_bisect_option u2 ^U |
| 152 | test_bisection_diff 0 $_bisect_option u3 ^U |
| 153 | test_bisection_diff 0 $_bisect_option u4 ^U |
| 154 | test_bisection_diff 0 $_bisect_option u5 ^U |
Junio C Hamano | a6080a0 | 2007-06-07 00:04:01 -0700 | [diff] [blame] | 155 | |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 156 | # |
Pavel Roskin | 82e5a82 | 2006-07-10 01:50:18 -0400 | [diff] [blame] | 157 | # the following illustrates Linus' binary bug blatt idea. |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 158 | # |
| 159 | # assume the bug is actually at l3, but you don't know that - all you know is that l3 is broken |
| 160 | # and it wasn't broken before |
| 161 | # |
| 162 | # keep bisecting the list, advancing the "bad" head and accumulating "good" heads until |
| 163 | # the bisection point is the head - this is the bad point. |
| 164 | # |
| 165 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 166 | test_output_expect_success "$_bisect_option l5 ^root" 'git rev-list $_bisect_option l5 ^root' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 167 | c3 |
| 168 | EOF |
| 169 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 170 | test_output_expect_success "$_bisect_option l5 ^root ^c3" 'git rev-list $_bisect_option l5 ^root ^c3' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 171 | b4 |
| 172 | EOF |
| 173 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 174 | test_output_expect_success "$_bisect_option l5 ^root ^c3 ^b4" 'git rev-list $_bisect_option l5 ^c3 ^b4' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 175 | l3 |
| 176 | EOF |
| 177 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 178 | test_output_expect_success "$_bisect_option l3 ^root ^c3 ^b4" 'git rev-list $_bisect_option l3 ^root ^c3 ^b4' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 179 | a4 |
| 180 | EOF |
| 181 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 182 | test_output_expect_success "$_bisect_option l5 ^b3 ^a3 ^b4 ^a4" 'git rev-list $_bisect_option l3 ^b3 ^a3 ^a4' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 183 | l3 |
| 184 | EOF |
| 185 | |
| 186 | # |
| 187 | # if l3 is bad, then l4 is bad too - so advance the bad pointer by making b4 the known bad head |
| 188 | # |
| 189 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 190 | test_output_expect_success "$_bisect_option l4 ^a2 ^a3 ^b ^a4" 'git rev-list $_bisect_option l4 ^a2 ^a3 ^a4' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 191 | l3 |
| 192 | EOF |
| 193 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 194 | test_output_expect_success "$_bisect_option l3 ^a2 ^a3 ^b ^a4" 'git rev-list $_bisect_option l3 ^a2 ^a3 ^a4' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 195 | l3 |
| 196 | EOF |
| 197 | |
| 198 | # found! |
| 199 | |
| 200 | # |
| 201 | # as another example, let's consider a4 to be the bad head, in which case |
| 202 | # |
| 203 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 204 | test_output_expect_success "$_bisect_option a4 ^a2 ^a3 ^b4" 'git rev-list $_bisect_option a4 ^a2 ^a3 ^b4' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 205 | c2 |
| 206 | EOF |
| 207 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 208 | test_output_expect_success "$_bisect_option a4 ^a2 ^a3 ^b4 ^c2" 'git rev-list $_bisect_option a4 ^a2 ^a3 ^b4 ^c2' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 209 | c3 |
| 210 | EOF |
| 211 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 212 | test_output_expect_success "$_bisect_option a4 ^a2 ^a3 ^b4 ^c2 ^c3" 'git rev-list $_bisect_option a4 ^a2 ^a3 ^b4 ^c2 ^c3' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 213 | a4 |
| 214 | EOF |
| 215 | |
| 216 | # found! |
| 217 | |
| 218 | # |
| 219 | # or consider c3 to be the bad head |
| 220 | # |
| 221 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 222 | test_output_expect_success "$_bisect_option a4 ^a2 ^a3 ^b4" 'git rev-list $_bisect_option a4 ^a2 ^a3 ^b4' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 223 | c2 |
| 224 | EOF |
| 225 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 226 | test_output_expect_success "$_bisect_option c3 ^a2 ^a3 ^b4 ^c2" 'git rev-list $_bisect_option c3 ^a2 ^a3 ^b4 ^c2' <<EOF |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 227 | c3 |
| 228 | EOF |
| 229 | |
| 230 | # found! |
| 231 | |
| 232 | } |
| 233 | |
| 234 | test_sequence "--bisect" |
| 235 | |
| 236 | # |
| 237 | # |
Michael Haggerty | 03df567 | 2017-06-18 15:39:41 +0200 | [diff] [blame] | 238 | |
Jeff King | 1d0538e | 2017-09-06 07:53:10 -0400 | [diff] [blame] | 239 | test_expect_success 'set up fake --bisect refs' ' |
Michael Haggerty | 03df567 | 2017-06-18 15:39:41 +0200 | [diff] [blame] | 240 | git update-ref refs/bisect/bad c3 && |
| 241 | good=$(git rev-parse b1) && |
| 242 | git update-ref refs/bisect/good-$good $good && |
| 243 | good=$(git rev-parse c1) && |
Jeff King | 1d0538e | 2017-09-06 07:53:10 -0400 | [diff] [blame] | 244 | git update-ref refs/bisect/good-$good $good |
| 245 | ' |
Michael Haggerty | 03df567 | 2017-06-18 15:39:41 +0200 | [diff] [blame] | 246 | |
Jeff King | 1d0538e | 2017-09-06 07:53:10 -0400 | [diff] [blame] | 247 | test_expect_success 'rev-list --bisect can default to good/bad refs' ' |
Michael Haggerty | 03df567 | 2017-06-18 15:39:41 +0200 | [diff] [blame] | 248 | # the only thing between c3 and c1 is c2 |
| 249 | git rev-parse c2 >expect && |
| 250 | git rev-list --bisect >actual && |
| 251 | test_cmp expect actual |
| 252 | ' |
| 253 | |
Jeff King | 1d0538e | 2017-09-06 07:53:10 -0400 | [diff] [blame] | 254 | test_expect_success 'rev-parse --bisect can default to good/bad refs' ' |
| 255 | git rev-parse c3 ^b1 ^c1 >expect && |
| 256 | git rev-parse --bisect >actual && |
| 257 | |
| 258 | # output order depends on the refnames, which in turn depends on |
| 259 | # the exact sha1s. We just want to make sure we have the same set |
| 260 | # of lines in any order. |
| 261 | sort <expect >expect.sorted && |
| 262 | sort <actual >actual.sorted && |
| 263 | test_cmp expect.sorted actual.sorted |
| 264 | ' |
| 265 | |
Aaron Lipman | 0fe305a | 2020-08-07 17:58:35 -0400 | [diff] [blame] | 266 | test_output_expect_success '--bisect --first-parent' 'git rev-list --bisect --first-parent E ^F' <<EOF |
| 267 | e4 |
| 268 | EOF |
| 269 | |
| 270 | test_output_expect_success '--first-parent' 'git rev-list --first-parent E ^F' <<EOF |
| 271 | E |
| 272 | e1 |
| 273 | e2 |
| 274 | e3 |
| 275 | e4 |
| 276 | e5 |
| 277 | e6 |
| 278 | e7 |
| 279 | e8 |
| 280 | EOF |
| 281 | |
| 282 | test_output_expect_success '--bisect-vars --first-parent' 'git rev-list --bisect-vars --first-parent E ^F' <<EOF |
| 283 | bisect_rev='e5' |
| 284 | bisect_nr=4 |
| 285 | bisect_good=4 |
| 286 | bisect_bad=3 |
| 287 | bisect_all=9 |
| 288 | bisect_steps=2 |
| 289 | EOF |
| 290 | |
| 291 | test_expect_success '--bisect-all --first-parent' ' |
| 292 | cat >expect.unsorted <<-EOF && |
| 293 | $(git rev-parse E) (tag: E, dist=0) |
| 294 | $(git rev-parse e1) (tag: e1, dist=1) |
| 295 | $(git rev-parse e2) (tag: e2, dist=2) |
| 296 | $(git rev-parse e3) (tag: e3, dist=3) |
| 297 | $(git rev-parse e4) (tag: e4, dist=4) |
| 298 | $(git rev-parse e5) (tag: e5, dist=4) |
| 299 | $(git rev-parse e6) (tag: e6, dist=3) |
| 300 | $(git rev-parse e7) (tag: e7, dist=2) |
| 301 | $(git rev-parse e8) (tag: e8, dist=1) |
| 302 | EOF |
| 303 | |
| 304 | # expect results to be ordered by distance (descending), |
| 305 | # commit hash (ascending) |
| 306 | sort -k4,4r -k1,1 expect.unsorted >expect && |
| 307 | git rev-list --bisect-all --first-parent E ^F >actual && |
| 308 | test_cmp expect actual |
| 309 | ' |
| 310 | |
Patrick Steinhardt | 5f9f7fa | 2024-11-25 16:56:25 +0100 | [diff] [blame] | 311 | test_expect_success '--bisect without any revisions' ' |
| 312 | git rev-list --bisect HEAD..HEAD >out && |
| 313 | test_must_be_empty out |
| 314 | ' |
| 315 | |
Jon Seymour | 8904591 | 2005-07-06 20:11:27 +1000 | [diff] [blame] | 316 | test_done |