Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-bisect(1) |
| 2 | ============= |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 6 | git-bisect - Find by binary search the change that introduced a bug |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
Junio C Hamano | 15567bc | 2011-07-23 00:51:59 | [diff] [blame] | 11 | [verse] |
Junio C Hamano | a77a513 | 2007-06-08 16:13:44 | [diff] [blame] | 12 | 'git bisect' <subcommand> <options> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 13 | |
| 14 | DESCRIPTION |
| 15 | ----------- |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 16 | The command takes various subcommands, and different options depending |
| 17 | on the subcommand: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 18 | |
Junio C Hamano | e79159d | 2008-04-12 08:23:17 | [diff] [blame] | 19 | git bisect help |
Junio C Hamano | 12a3a23 | 2007-04-07 10:18:10 | [diff] [blame] | 20 | git bisect start [<bad> [<good>...]] [--] [<paths>...] |
Junio C Hamano | 1974bf2 | 2007-10-31 05:57:20 | [diff] [blame] | 21 | git bisect bad [<rev>] |
| 22 | git bisect good [<rev>...] |
Junio C Hamano | d796cea | 2008-12-03 03:51:10 | [diff] [blame] | 23 | git bisect skip [(<rev>|<range>)...] |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 24 | git bisect reset [<commit>] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 25 | git bisect visualize |
| 26 | git bisect replay <logfile> |
| 27 | git bisect log |
Junio C Hamano | f440a23 | 2007-03-23 10:46:17 | [diff] [blame] | 28 | git bisect run <cmd>... |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 29 | |
Junio C Hamano | 175a1bd | 2008-11-10 00:08:57 | [diff] [blame] | 30 | This command uses 'git rev-list --bisect' to help drive the |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 31 | binary search process to find which change introduced a bug, given an |
| 32 | old "good" commit object name and a later "bad" commit object name. |
| 33 | |
Junio C Hamano | e79159d | 2008-04-12 08:23:17 | [diff] [blame] | 34 | Getting help |
| 35 | ~~~~~~~~~~~~ |
| 36 | |
| 37 | Use "git bisect" to get a short usage description, and "git bisect |
| 38 | help" or "git bisect -h" to get a long usage description. |
| 39 | |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 40 | Basic bisect commands: start, bad, good |
| 41 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 42 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 43 | Using the Linux kernel tree as an example, basic use of the bisect |
| 44 | command is as follows: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 45 | |
| 46 | ------------------------------------------------ |
| 47 | $ git bisect start |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 48 | $ git bisect bad # Current version is bad |
| 49 | $ git bisect good v2.6.13-rc2 # v2.6.13-rc2 was the last version |
| 50 | # tested that was good |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 51 | ------------------------------------------------ |
| 52 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 53 | When you have specified at least one bad and one good version, the |
| 54 | command bisects the revision tree and outputs something similar to |
| 55 | the following: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 56 | |
| 57 | ------------------------------------------------ |
| 58 | Bisecting: 675 revisions left to test after this |
| 59 | ------------------------------------------------ |
| 60 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 61 | The state in the middle of the set of revisions is then checked out. |
| 62 | You would now compile that kernel and boot it. If the booted kernel |
| 63 | works correctly, you would then issue the following command: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 64 | |
| 65 | ------------------------------------------------ |
| 66 | $ git bisect good # this one is good |
| 67 | ------------------------------------------------ |
| 68 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 69 | The output of this command would be something similar to the following: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 70 | |
| 71 | ------------------------------------------------ |
| 72 | Bisecting: 337 revisions left to test after this |
| 73 | ------------------------------------------------ |
| 74 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 75 | You keep repeating this process, compiling the tree, testing it, and |
| 76 | depending on whether it is good or bad issuing the command "git bisect good" |
| 77 | or "git bisect bad" to ask for the next bisection. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 78 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 79 | Eventually there will be no more revisions left to bisect, and you |
| 80 | will have been left with the first bad kernel revision in "refs/bisect/bad". |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 81 | |
| 82 | Bisect reset |
| 83 | ~~~~~~~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 84 | |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 85 | After a bisect session, to clean up the bisection state and return to |
| 86 | the original HEAD, issue the following command: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 87 | |
| 88 | ------------------------------------------------ |
| 89 | $ git bisect reset |
| 90 | ------------------------------------------------ |
| 91 | |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 92 | By default, this will return your tree to the commit that was checked |
| 93 | out before `git bisect start`. (A new `git bisect start` will also do |
| 94 | that, as it cleans up the old bisection state.) |
| 95 | |
| 96 | With an optional argument, you can return to a different commit |
| 97 | instead: |
| 98 | |
| 99 | ------------------------------------------------ |
| 100 | $ git bisect reset <commit> |
| 101 | ------------------------------------------------ |
| 102 | |
| 103 | For example, `git bisect reset HEAD` will leave you on the current |
| 104 | bisection commit and avoid switching commits at all, while `git bisect |
| 105 | reset bisect/bad` will check out the first bad revision. |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 106 | |
| 107 | Bisect visualize |
| 108 | ~~~~~~~~~~~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 109 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 110 | To see the currently remaining suspects in 'gitk', issue the following |
| 111 | command during the bisection process: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 112 | |
| 113 | ------------ |
| 114 | $ git bisect visualize |
| 115 | ------------ |
| 116 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 117 | `view` may also be used as a synonym for `visualize`. |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 118 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 119 | If the 'DISPLAY' environment variable is not set, 'git log' is used |
| 120 | instead. You can also give command line options such as `-p` and |
Junio C Hamano | 942b35e | 2007-12-09 10:19:33 | [diff] [blame] | 121 | `--stat`. |
| 122 | |
| 123 | ------------ |
| 124 | $ git bisect view --stat |
| 125 | ------------ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 126 | |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 127 | Bisect log and bisect replay |
| 128 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 129 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 130 | After having marked revisions as good or bad, issue the following |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 131 | command to show what has been done so far: |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 132 | |
| 133 | ------------ |
| 134 | $ git bisect log |
| 135 | ------------ |
| 136 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 137 | If you discover that you made a mistake in specifying the status of a |
| 138 | revision, you can save the output of this command to a file, edit it to |
| 139 | remove the incorrect entries, and then issue the following commands to |
| 140 | return to a corrected state: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 141 | |
| 142 | ------------ |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 143 | $ git bisect reset |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 144 | $ git bisect replay that-file |
| 145 | ------------ |
| 146 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 147 | Avoiding testing a commit |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 148 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 149 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 150 | If, in the middle of a bisect session, you know that the next suggested |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 151 | revision is not a good one to test (e.g. the change the commit |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 152 | introduces is known not to work in your environment and you know it |
| 153 | does not have anything to do with the bug you are chasing), you may |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 154 | want to find a nearby commit and try that instead. |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 155 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 156 | For example: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 157 | |
| 158 | ------------ |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 159 | $ git bisect good/bad # previous round was good or bad. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 160 | Bisecting: 337 revisions left to test after this |
| 161 | $ git bisect visualize # oops, that is uninteresting. |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 162 | $ git reset --hard HEAD~3 # try 3 revisions before what |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 163 | # was suggested |
| 164 | ------------ |
| 165 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 166 | Then compile and test the chosen revision, and afterwards mark |
| 167 | the revision as good or bad in the usual manner. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 168 | |
Junio C Hamano | 1974bf2 | 2007-10-31 05:57:20 | [diff] [blame] | 169 | Bisect skip |
| 170 | ~~~~~~~~~~~~ |
| 171 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 172 | Instead of choosing by yourself a nearby commit, you can ask git |
| 173 | to do it for you by issuing the command: |
Junio C Hamano | 1974bf2 | 2007-10-31 05:57:20 | [diff] [blame] | 174 | |
| 175 | ------------ |
| 176 | $ git bisect skip # Current version cannot be tested |
| 177 | ------------ |
| 178 | |
Junio C Hamano | 2c14c8d | 2009-07-02 03:17:00 | [diff] [blame] | 179 | But git may eventually be unable to tell the first bad commit among |
| 180 | a bad commit and one or more skipped commits. |
Junio C Hamano | 1974bf2 | 2007-10-31 05:57:20 | [diff] [blame] | 181 | |
Junio C Hamano | d796cea | 2008-12-03 03:51:10 | [diff] [blame] | 182 | You can even skip a range of commits, instead of just one commit, |
| 183 | using the "'<commit1>'..'<commit2>'" notation. For example: |
| 184 | |
| 185 | ------------ |
| 186 | $ git bisect skip v2.5..v2.6 |
| 187 | ------------ |
| 188 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 189 | This tells the bisect process that no commit after `v2.5`, up to and |
| 190 | including `v2.6`, should be tested. |
Junio C Hamano | d796cea | 2008-12-03 03:51:10 | [diff] [blame] | 191 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 192 | Note that if you also want to skip the first commit of the range you |
| 193 | would issue the command: |
Junio C Hamano | d796cea | 2008-12-03 03:51:10 | [diff] [blame] | 194 | |
| 195 | ------------ |
| 196 | $ git bisect skip v2.5 v2.5..v2.6 |
| 197 | ------------ |
| 198 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 199 | This tells the bisect process that the commits between `v2.5` included |
| 200 | and `v2.6` included should be skipped. |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 201 | |
Junio C Hamano | d796cea | 2008-12-03 03:51:10 | [diff] [blame] | 202 | |
Junio C Hamano | 12a3a23 | 2007-04-07 10:18:10 | [diff] [blame] | 203 | Cutting down bisection by giving more parameters to bisect start |
| 204 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 205 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 206 | You can further cut down the number of trials, if you know what part of |
| 207 | the tree is involved in the problem you are tracking down, by specifying |
| 208 | path parameters when issuing the `bisect start` command: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 209 | |
| 210 | ------------ |
Junio C Hamano | 12a3a23 | 2007-04-07 10:18:10 | [diff] [blame] | 211 | $ git bisect start -- arch/i386 include/asm-i386 |
| 212 | ------------ |
| 213 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 214 | If you know beforehand more than one good commit, you can narrow the |
| 215 | bisect space down by specifying all of the good commits immediately after |
| 216 | the bad commit when issuing the `bisect start` command: |
Junio C Hamano | 12a3a23 | 2007-04-07 10:18:10 | [diff] [blame] | 217 | |
| 218 | ------------ |
| 219 | $ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 -- |
| 220 | # v2.6.20-rc6 is bad |
| 221 | # v2.6.20-rc4 and v2.6.20-rc1 are good |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 222 | ------------ |
| 223 | |
Junio C Hamano | b60308a | 2007-03-24 07:16:42 | [diff] [blame] | 224 | Bisect run |
| 225 | ~~~~~~~~~~ |
| 226 | |
| 227 | If you have a script that can tell if the current source code is good |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 228 | or bad, you can bisect by issuing the command: |
Junio C Hamano | f440a23 | 2007-03-23 10:46:17 | [diff] [blame] | 229 | |
| 230 | ------------ |
Junio C Hamano | 0a23522 | 2009-03-06 08:21:09 | [diff] [blame] | 231 | $ git bisect run my_script arguments |
Junio C Hamano | f440a23 | 2007-03-23 10:46:17 | [diff] [blame] | 232 | ------------ |
| 233 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 234 | Note that the script (`my_script` in the above example) should |
| 235 | exit with code 0 if the current source code is good, and exit with a |
Junio C Hamano | 1974bf2 | 2007-10-31 05:57:20 | [diff] [blame] | 236 | code between 1 and 127 (inclusive), except 125, if the current |
| 237 | source code is bad. |
Junio C Hamano | f440a23 | 2007-03-23 10:46:17 | [diff] [blame] | 238 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 239 | Any other exit code will abort the bisect process. It should be noted |
| 240 | that a program that terminates via "exit(-1)" leaves $? = 255, (see the |
| 241 | exit(3) manual page), as the value is chopped with "& 0377". |
Junio C Hamano | f440a23 | 2007-03-23 10:46:17 | [diff] [blame] | 242 | |
Junio C Hamano | 1974bf2 | 2007-10-31 05:57:20 | [diff] [blame] | 243 | The special exit code 125 should be used when the current source code |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 244 | cannot be tested. If the script exits with this code, the current |
Junio C Hamano | d2c978f | 2011-03-20 19:42:22 | [diff] [blame] | 245 | revision will be skipped (see `git bisect skip` above). 125 was chosen |
| 246 | as the highest sensible value to use for this purpose, because 126 and 127 |
| 247 | are used by POSIX shells to signal specific error status (127 is for |
| 248 | command not found, 126 is for command found but not executable---these |
| 249 | details do not matter, as they are normal errors in the script, as far as |
| 250 | "bisect run" is concerned). |
Junio C Hamano | 1974bf2 | 2007-10-31 05:57:20 | [diff] [blame] | 251 | |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 252 | You may often find that during a bisect session you want to have |
| 253 | temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a |
| 254 | header file, or "revision that does not have this commit needs this |
| 255 | patch applied to work around another problem this bisection is not |
| 256 | interested in") applied to the revision being tested. |
Junio C Hamano | f440a23 | 2007-03-23 10:46:17 | [diff] [blame] | 257 | |
Junio C Hamano | 175a1bd | 2008-11-10 00:08:57 | [diff] [blame] | 258 | To cope with such a situation, after the inner 'git bisect' finds the |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 259 | next revision to test, the script can apply the patch |
| 260 | before compiling, run the real test, and afterwards decide if the |
| 261 | revision (possibly with the needed patch) passed the test and then |
| 262 | rewind the tree to the pristine state. Finally the script should exit |
| 263 | with the status of the real test to let the "git bisect run" command loop |
| 264 | determine the eventual outcome of the bisect session. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 265 | |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 266 | EXAMPLES |
| 267 | -------- |
| 268 | |
| 269 | * Automatically bisect a broken build between v1.2 and HEAD: |
| 270 | + |
| 271 | ------------ |
| 272 | $ git bisect start HEAD v1.2 -- # HEAD is bad, v1.2 is good |
| 273 | $ git bisect run make # "make" builds the app |
| 274 | ------------ |
| 275 | |
Junio C Hamano | 0a23522 | 2009-03-06 08:21:09 | [diff] [blame] | 276 | * Automatically bisect a test failure between origin and HEAD: |
| 277 | + |
| 278 | ------------ |
| 279 | $ git bisect start HEAD origin -- # HEAD is bad, origin is good |
| 280 | $ git bisect run make test # "make test" builds and tests |
| 281 | ------------ |
| 282 | |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 283 | * Automatically bisect a broken test case: |
| 284 | + |
| 285 | ------------ |
| 286 | $ cat ~/test.sh |
| 287 | #!/bin/sh |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 288 | make || exit 125 # this skips broken builds |
Junio C Hamano | 9a2fb2d | 2011-03-23 05:40:15 | [diff] [blame] | 289 | ~/check_test_case.sh # does the test case pass? |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 290 | $ git bisect start HEAD HEAD~10 -- # culprit is among the last 10 |
| 291 | $ git bisect run ~/test.sh |
| 292 | ------------ |
| 293 | + |
Junio C Hamano | 9a2fb2d | 2011-03-23 05:40:15 | [diff] [blame] | 294 | Here we use a "test.sh" custom script. In this script, if "make" |
| 295 | fails, we skip the current commit. |
| 296 | "check_test_case.sh" should "exit 0" if the test case passes, |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 297 | and "exit 1" otherwise. |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 298 | + |
Junio C Hamano | 9a2fb2d | 2011-03-23 05:40:15 | [diff] [blame] | 299 | It is safer if both "test.sh" and "check_test_case.sh" are |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 300 | outside the repository to prevent interactions between the bisect, |
| 301 | make and test processes and the scripts. |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 302 | |
Junio C Hamano | 9a2fb2d | 2011-03-23 05:40:15 | [diff] [blame] | 303 | * Automatically bisect with temporary modifications (hot-fix): |
| 304 | + |
| 305 | ------------ |
| 306 | $ cat ~/test.sh |
| 307 | #!/bin/sh |
| 308 | |
| 309 | # tweak the working tree by merging the hot-fix branch |
| 310 | # and then attempt a build |
| 311 | if git merge --no-commit hot-fix && |
| 312 | make |
| 313 | then |
| 314 | # run project specific test and report its status |
| 315 | ~/check_test_case.sh |
| 316 | status=$? |
| 317 | else |
| 318 | # tell the caller this is untestable |
| 319 | status=125 |
| 320 | fi |
| 321 | |
| 322 | # undo the tweak to allow clean flipping to the next commit |
| 323 | git reset --hard |
| 324 | |
| 325 | # return control |
| 326 | exit $status |
| 327 | ------------ |
| 328 | + |
| 329 | This applies modifications from a hot-fix branch before each test run, |
| 330 | e.g. in case your build or test environment changed so that older |
| 331 | revisions may need a fix which newer ones have already. (Make sure the |
| 332 | hot-fix branch is based off a commit which is contained in all revisions |
| 333 | which you are bisecting, so that the merge does not pull in too much, or |
| 334 | use `git cherry-pick` instead of `git merge`.) |
| 335 | |
| 336 | * Automatically bisect a broken test case: |
Junio C Hamano | 0a23522 | 2009-03-06 08:21:09 | [diff] [blame] | 337 | + |
| 338 | ------------ |
| 339 | $ git bisect start HEAD HEAD~10 -- # culprit is among the last 10 |
| 340 | $ git bisect run sh -c "make || exit 125; ~/check_test_case.sh" |
| 341 | ------------ |
| 342 | + |
Junio C Hamano | 9a2fb2d | 2011-03-23 05:40:15 | [diff] [blame] | 343 | This shows that you can do without a run script if you write the test |
| 344 | on a single line. |
Junio C Hamano | 0a23522 | 2009-03-06 08:21:09 | [diff] [blame] | 345 | |
Junio C Hamano | 2bd8a74 | 2009-12-01 21:16:59 | [diff] [blame] | 346 | SEE ALSO |
| 347 | -------- |
| 348 | link:git-bisect-lk2009.html[Fighting regressions with git bisect], |
| 349 | linkgit:git-blame[1]. |
| 350 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 351 | GIT |
| 352 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 353 | Part of the linkgit:git[1] suite |