Created
March 23, 2012 11:44
-
-
Save naholyr/2169898 to your computer and use it in GitHub Desktop.
Git bisect for SVN
This file contains 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
function svn-bisect() { | |
local TEST="$1" | |
local TARGET="${2:-.}" | |
local LEFT=${3:-1} | |
local RIGHT=${4:-$(LANG=LC svn info | grep ^Revision | sed 's/Revision: //')} | |
if ! echo "$LEFT" | grep '^[0-9]\+$' > /dev/null; then | |
echo 'Starting revision must be a valid number' >&2 | |
exit 1 | |
fi | |
if ! echo "$RIGHT" | grep '^[0-9]\+$' > /dev/null; then | |
echo 'Ending revision must be a valid number' >&2 | |
exit 1 | |
fi | |
if [ $RIGHT -le $LEFT ]; then | |
echo 'Ending revision must be greater than starting revision' >&2 | |
exit 2 | |
fi | |
if ! (svn status "$TARGET" --ignore-externals) 2> /dev/null; then | |
echo 'Invalid target' >&2 | |
exit 3 | |
fi | |
if [ "$(svn status "$TARGET" --ignore-externals)" != "" ]; then | |
echo 'Target has local changes: cleanup your working copy before bisect' >&2 | |
exit 4 | |
fi | |
function test_rev() { | |
echo "Testing $1…" >&2 | |
svn up --force --accept=theirs-full -r $1 "$TARGET" > /dev/null | |
if eval "$TEST"; then | |
echo "PASS: $1" | |
return 0 | |
else | |
echo "FAIL: $1" | |
return 1 | |
fi | |
} | |
local MIDDLE= | |
function advance_rev() { | |
MIDDLE=$((($LEFT+$RIGHT)/2)) | |
if [ $MIDDLE = $LEFT ]; then | |
return 1; | |
fi | |
} | |
if (test_rev $RIGHT); then | |
echo "Already working at ending revision" >&2 | |
echo "Hint: You should provide an ending revision that fails." >&2 | |
echo $RIGHT | |
exit 0 | |
fi | |
if ! (test_rev $LEFT); then | |
echo "Not working at starting revision" >&2 | |
echo "You must provide an starting revision that does not fail." >&2 | |
exit 255 | |
fi | |
while advance_rev; do | |
if test_rev $MIDDLE; then | |
LEFT=$MIDDLE | |
else | |
RIGHT=$MIDDLE | |
fi | |
done | |
echo "Latest successful revision found:" >&2 | |
echo "$RIGHT" | |
} |
This file contains 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
A method of a class I knew previously existed suddenly disappeared. Dafuq ? | |
The test to check if method exists will be: "grep 'n myMethod' /path/to/class.php" | |
The target to update is "/path/to/class.php" | |
To revision when I implemented the function (I therefore know it exists there) is 13921 | |
Current HEAD is 14345 | |
$ svn-bisect "grep 'n myMethod' /path/to/class.php > /dev/null" /path/to/class.php 13921 | |
Testing 14345… | |
FAIL: 14345 | |
Testing 13921… | |
PASS: 13921 | |
Testing 14133… | |
FAIL: 14133 | |
Testing 14027… | |
FAIL: 14027 | |
Testing 13974… | |
PASS: 13974 | |
Testing 14000… | |
PASS: 14000 | |
Testing 14013… | |
FAIL: 14013 | |
Testing 14006… | |
FAIL: 14006 | |
Testing 14003… | |
FAIL: 14003 | |
Testing 14001… | |
PASS: 14001 | |
Testing 14002… | |
FAIL: 14002 | |
Latest successful revision found: | |
14002 | |
Time to execute: ~ 10 seconds | |
Time saved: ~ 2 hours :) |
This file contains 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
`svn-bisect $TEST $TARGET [$START [$END]]` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment