Last active
November 23, 2017 21:08
-
-
Save RedRoosterKey/bf54795506bc7b8cf278 to your computer and use it in GitHub Desktop.
An example of how to use git bisect with tests to automatically find a bad commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| # author RedRoosterKey | |
| set -e | |
| # set -v | |
| # Example - exit code 125 tells git bisect to skip this commt | |
| # git_bisect.sh --back 10 "cd Release || exit 125; make clean || exit 125; make || exit 125; make test" | |
| back=1 | |
| case "${1}" in | |
| '--back') | |
| if [ -z "${2}" ] | |
| then | |
| >&2 echo "Incorrect Usage!" | |
| >&2 echo "${0} --back n \"some shell command\"" | |
| exit 1 | |
| else | |
| back=${2} | |
| fi | |
| ;; | |
| *) | |
| >&2 echo "Incorrect Usage!" | |
| >&2 echo "${0} --back n \"some shell command\"" | |
| exit 2 | |
| esac | |
| if [ -z "${3}" ] | |
| then | |
| >&2 echo "Incorrect Usage!" | |
| >&2 echo "${0} --back n \"some shell command\"" | |
| exit 3 | |
| else | |
| echo running commands "\"${3}\"" to determine commit status | |
| fi | |
| git bisect start HEAD "HEAD~${back}" -- # culprit is among the last ${back} commits | |
| git bisect run sh -c "${3}" | |
| git bisect reset # quit the bisect session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment