Skip to content

Instantly share code, notes, and snippets.

@cheeming
Created June 23, 2012 03:29
Show Gist options
  • Select an option

  • Save cheeming/2976658 to your computer and use it in GitHub Desktop.

Select an option

Save cheeming/2976658 to your computer and use it in GitHub Desktop.

Revisions

  1. cheeming revised this gist Jun 23, 2012. 1 changed file with 5 additions and 22 deletions.
    27 changes: 5 additions & 22 deletions find_bad_revisions
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@ function print_usage () {
    echo usage: $0 LAST_KNOWN_GOOD_REVISION '"TEST_COMMAND"'
    echo LAST_KNOWN_GOOD_REVISION = you can specify this as sha1 hash
    echo TEST_COMMAND = the script to run, it should return 0 if success
    echo NOTE: Ensure that the current revision is the bad \(broken\)
    exit 1;
    }

    @@ -28,25 +29,7 @@ read _tmp
    git bisect start
    git bisect bad
    git bisect good $LAST_KNOWN_GOOD_REVISION

    while true; do
    echo running test command... \( ${TEST_COMMAND} \)
    eval "( ${TEST_COMMAND} )"

    if [ $? -ne 0 ]; then
    PREV_COMMIT=`git log --pretty=format:"%H" -1`
    git bisect bad
    CURR_COMMIT=`git log --pretty=format:"%H" -1`
    echo PREV_COMMIT=${PREV_COMMIT} CURR_COMMIT=${CURR_COMMIT}
    if [ "${PREV_COMMIT}" == "${CURR_COMMIT}" ]; then
    echo no more revisions to test
    git bisect log
    echo run the following to reset git bisect
    echo git bisect reset
    break
    fi
    else
    echo revision is good, continue bisecting ...
    git bisect good
    fi
    done;
    git bisect run bash -c "${TEST_COMMAND}"
    git bisect log
    echo run the following to reset git bisect
    echo git bisect reset
  2. cheeming revised this gist Jun 23, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion find_bad_revisions
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ git bisect bad
    git bisect good $LAST_KNOWN_GOOD_REVISION

    while true; do
    echo 'running test command... "( ${TEST_COMMAND} )" '
    echo running test command... \( ${TEST_COMMAND} \)
    eval "( ${TEST_COMMAND} )"

    if [ $? -ne 0 ]; then
  3. cheeming revised this gist Jun 23, 2012. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion find_bad_revisions
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    function print_usage () {
    echo usage: $0 LAST_KNOWN_GOOD_REVISION '"TEST_COMMAND"'
    echo LAST_KNOWN_GOOD_REVISION = you can specify this as branch, tag or sha1 hash
    echo LAST_KNOWN_GOOD_REVISION = you can specify this as sha1 hash
    echo TEST_COMMAND = the script to run, it should return 0 if success
    exit 1;
    }
    @@ -21,6 +21,10 @@ if [ -z "${TEST_COMMAND}" ]; then
    print_usage
    fi

    # TODO: should have a flag to skip this, so that it can be automated
    echo "ensure HEAD is bad (broken), press enter to continue or ctrl-c to leave to setup..."
    read _tmp

    git bisect start
    git bisect bad
    git bisect good $LAST_KNOWN_GOOD_REVISION
  4. cheeming created this gist Jun 23, 2012.
    48 changes: 48 additions & 0 deletions find_bad_revisions
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    #!/bin/bash

    function print_usage () {
    echo usage: $0 LAST_KNOWN_GOOD_REVISION '"TEST_COMMAND"'
    echo LAST_KNOWN_GOOD_REVISION = you can specify this as branch, tag or sha1 hash
    echo TEST_COMMAND = the script to run, it should return 0 if success
    exit 1;
    }

    LAST_KNOWN_GOOD_REVISION=$1

    if [ -z "${LAST_KNOWN_GOOD_REVISION}" ]; then
    echo please enter last known revision that was good >> /dev/stderr
    print_usage
    fi

    TEST_COMMAND=$2

    if [ -z "${TEST_COMMAND}" ]; then
    echo "please enter a test command (script/program/whatever)" >> /dev/stderr
    print_usage
    fi

    git bisect start
    git bisect bad
    git bisect good $LAST_KNOWN_GOOD_REVISION

    while true; do
    echo 'running test command... "( ${TEST_COMMAND} )" '
    eval "( ${TEST_COMMAND} )"

    if [ $? -ne 0 ]; then
    PREV_COMMIT=`git log --pretty=format:"%H" -1`
    git bisect bad
    CURR_COMMIT=`git log --pretty=format:"%H" -1`
    echo PREV_COMMIT=${PREV_COMMIT} CURR_COMMIT=${CURR_COMMIT}
    if [ "${PREV_COMMIT}" == "${CURR_COMMIT}" ]; then
    echo no more revisions to test
    git bisect log
    echo run the following to reset git bisect
    echo git bisect reset
    break
    fi
    else
    echo revision is good, continue bisecting ...
    git bisect good
    fi
    done;