2007-03-23 08:49:59 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Christian Couder
|
|
|
|
#
|
2007-04-06 07:52:37 +02:00
|
|
|
test_description='Tests git-bisect functionality'
|
2007-03-23 08:49:59 +01:00
|
|
|
|
2007-04-06 08:27:44 +02:00
|
|
|
exec </dev/null
|
|
|
|
|
2007-03-23 08:49:59 +01:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
add_line_into_file()
|
|
|
|
{
|
|
|
|
_line=$1
|
|
|
|
_file=$2
|
|
|
|
|
|
|
|
if [ -f "$_file" ]; then
|
|
|
|
echo "$_line" >> $_file || return $?
|
|
|
|
MSG="Add <$_line> into <$_file>."
|
|
|
|
else
|
|
|
|
echo "$_line" > $_file || return $?
|
|
|
|
git add $_file || return $?
|
|
|
|
MSG="Create file <$_file> with <$_line> inside."
|
|
|
|
fi
|
|
|
|
|
|
|
|
git-commit -m "$MSG" $_file
|
|
|
|
}
|
|
|
|
|
|
|
|
HASH1=
|
|
|
|
HASH3=
|
|
|
|
HASH4=
|
|
|
|
|
|
|
|
test_expect_success \
|
|
|
|
'set up basic repo with 1 file (hello) and 4 commits' \
|
|
|
|
'add_line_into_file "1: Hello World" hello &&
|
|
|
|
add_line_into_file "2: A new day for git" hello &&
|
|
|
|
add_line_into_file "3: Another new day for git" hello &&
|
|
|
|
add_line_into_file "4: Ciao for now" hello &&
|
|
|
|
HASH1=$(git rev-list HEAD | tail -1) &&
|
|
|
|
HASH3=$(git rev-list HEAD | head -2 | tail -1) &&
|
|
|
|
HASH4=$(git rev-list HEAD | head -1)'
|
|
|
|
|
2007-04-06 08:27:44 +02:00
|
|
|
test_expect_success 'bisect starts with only one bad' '
|
2007-04-06 07:52:37 +02:00
|
|
|
git bisect reset &&
|
|
|
|
git bisect start &&
|
2007-04-06 08:27:44 +02:00
|
|
|
git bisect bad $HASH4 &&
|
|
|
|
git bisect next
|
2007-04-06 07:52:37 +02:00
|
|
|
'
|
|
|
|
|
2007-04-17 06:51:48 +02:00
|
|
|
test_expect_success 'bisect does not start with only one good' '
|
2007-04-06 07:52:37 +02:00
|
|
|
git bisect reset &&
|
|
|
|
git bisect start &&
|
|
|
|
git bisect good $HASH1 || return 1
|
|
|
|
|
|
|
|
if git bisect next
|
|
|
|
then
|
|
|
|
echo Oops, should have failed.
|
|
|
|
false
|
|
|
|
else
|
|
|
|
:
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'bisect start with one bad and good' '
|
|
|
|
git bisect reset &&
|
|
|
|
git bisect start &&
|
|
|
|
git bisect good $HASH1 &&
|
|
|
|
git bisect bad $HASH4 &&
|
|
|
|
git bisect next
|
|
|
|
'
|
|
|
|
|
2007-03-23 08:49:59 +01:00
|
|
|
# We want to automatically find the commit that
|
|
|
|
# introduced "Another" into hello.
|
|
|
|
test_expect_success \
|
2007-04-04 07:12:02 +02:00
|
|
|
'"git bisect run" simple case' \
|
|
|
|
'echo "#"\!"/bin/sh" > test_script.sh &&
|
2007-03-23 08:49:59 +01:00
|
|
|
echo "grep Another hello > /dev/null" >> test_script.sh &&
|
|
|
|
echo "test \$? -ne 0" >> test_script.sh &&
|
|
|
|
chmod +x test_script.sh &&
|
|
|
|
git bisect start &&
|
|
|
|
git bisect good $HASH1 &&
|
|
|
|
git bisect bad $HASH4 &&
|
|
|
|
git bisect run ./test_script.sh > my_bisect_log.txt &&
|
2007-04-04 07:12:02 +02:00
|
|
|
grep "$HASH3 is first bad commit" my_bisect_log.txt &&
|
|
|
|
git bisect reset'
|
|
|
|
|
|
|
|
# We want to automatically find the commit that
|
|
|
|
# introduced "Ciao" into hello.
|
|
|
|
test_expect_success \
|
|
|
|
'"git bisect run" with more complex "git bisect start"' \
|
|
|
|
'echo "#"\!"/bin/sh" > test_script.sh &&
|
|
|
|
echo "grep Ciao hello > /dev/null" >> test_script.sh &&
|
|
|
|
echo "test \$? -ne 0" >> test_script.sh &&
|
|
|
|
chmod +x test_script.sh &&
|
|
|
|
git bisect start $HASH4 $HASH1 &&
|
|
|
|
git bisect run ./test_script.sh > my_bisect_log.txt &&
|
|
|
|
grep "$HASH4 is first bad commit" my_bisect_log.txt &&
|
|
|
|
git bisect reset'
|
2007-03-23 08:49:59 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
test_done
|
|
|
|
|