3 # Copyright (c) 2007 Christian Couder
5 test_description
='Tests git-bisect functionality'
16 if [ -f "$_file" ]; then
17 echo "$_line" >> $_file ||
return $?
18 MSG
="Add <$_line> into <$_file>."
20 echo "$_line" > $_file ||
return $?
21 git add
$_file ||
return $?
22 MSG
="Create file <$_file> with <$_line> inside."
26 git-commit
--quiet -m "$MSG" $_file
34 test_expect_success
'set up basic repo with 1 file (hello) and 4 commits' '
35 add_line_into_file "1: Hello World" hello &&
36 HASH1=$(git rev-parse --verify HEAD) &&
37 add_line_into_file "2: A new day for git" hello &&
38 HASH2=$(git rev-parse --verify HEAD) &&
39 add_line_into_file "3: Another new day for git" hello &&
40 HASH3=$(git rev-parse --verify HEAD) &&
41 add_line_into_file "4: Ciao for now" hello &&
42 HASH4=$(git rev-parse --verify HEAD)
45 test_expect_success
'bisect starts with only one bad' '
48 git bisect bad $HASH4 &&
52 test_expect_success
'bisect does not start with only one good' '
55 git bisect good $HASH1 || return 1
59 echo Oops, should have failed.
66 test_expect_success
'bisect start with one bad and good' '
69 git bisect good $HASH1 &&
70 git bisect bad $HASH4 &&
74 test_expect_success
'bisect reset: back in the master branch' '
76 echo "* master" > branch.expect &&
77 git branch > branch.output &&
78 cmp branch.expect branch.output
81 test_expect_success
'bisect reset: back in another branch' '
82 git checkout -b other &&
84 git bisect good $HASH1 &&
85 git bisect bad $HASH3 &&
87 echo " master" > branch.expect &&
88 echo "* other" >> branch.expect &&
89 git branch > branch.output &&
90 cmp branch.expect branch.output
93 test_expect_success
'bisect reset when not bisecting' '
95 git branch > branch.output &&
96 cmp branch.expect branch.output
99 test_expect_success
'bisect reset removes packed refs' '
102 git bisect good $HASH1 &&
103 git bisect bad $HASH3 &&
104 git pack-refs --all --prune &&
107 test -z "$(git for-each-ref "refs/bisect/*")" &&
108 test -z "$(git for-each-ref "refs/heads/bisect")"
111 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
113 # so we should find $HASH2 as the first bad commit
114 test_expect_success
'bisect skip: successfull result' '
116 git bisect start $HASH4 $HASH1 &&
118 git bisect bad > my_bisect_log.txt &&
119 grep "$HASH2 is first bad commit" my_bisect_log.txt &&
123 # $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
124 # so we should not be able to tell the first bad commit
125 # among $HASH2, $HASH3 and $HASH4
126 test_expect_success
'bisect skip: cannot tell between 3 commits' '
127 git bisect start $HASH4 $HASH1 &&
128 git bisect skip || return 1
130 if git bisect skip > my_bisect_log.txt
132 echo Oops, should have failed.
136 grep "first bad commit could be any of" my_bisect_log.txt &&
137 ! grep $HASH1 my_bisect_log.txt &&
138 grep $HASH2 my_bisect_log.txt &&
139 grep $HASH3 my_bisect_log.txt &&
140 grep $HASH4 my_bisect_log.txt &&
145 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
146 # but $HASH2 is good,
147 # so we should not be able to tell the first bad commit
148 # among $HASH3 and $HASH4
149 test_expect_success
'bisect skip: cannot tell between 2 commits' '
150 git bisect start $HASH4 $HASH1 &&
151 git bisect skip || return 1
153 if git bisect good > my_bisect_log.txt
155 echo Oops, should have failed.
159 grep "first bad commit could be any of" my_bisect_log.txt &&
160 ! grep $HASH1 my_bisect_log.txt &&
161 ! grep $HASH2 my_bisect_log.txt &&
162 grep $HASH3 my_bisect_log.txt &&
163 grep $HASH4 my_bisect_log.txt &&
168 # We want to automatically find the commit that
169 # introduced "Another" into hello.
170 test_expect_success \
171 '"git bisect run" simple case' \
172 'echo "#"\!"/bin/sh" > test_script.sh &&
173 echo "grep Another hello > /dev/null" >> test_script.sh &&
174 echo "test \$? -ne 0" >> test_script.sh &&
175 chmod +x test_script.sh &&
177 git bisect good $HASH1 &&
178 git bisect bad $HASH4 &&
179 git bisect run ./test_script.sh > my_bisect_log.txt &&
180 grep "$HASH3 is first bad commit" my_bisect_log.txt &&
183 # We want to automatically find the commit that
184 # introduced "Ciao" into hello.
185 test_expect_success \
186 '"git bisect run" with more complex "git bisect start"' \
187 'echo "#"\!"/bin/sh" > test_script.sh &&
188 echo "grep Ciao hello > /dev/null" >> test_script.sh &&
189 echo "test \$? -ne 0" >> test_script.sh &&
190 chmod +x test_script.sh &&
191 git bisect start $HASH4 $HASH1 &&
192 git bisect run ./test_script.sh > my_bisect_log.txt &&
193 grep "$HASH4 is first bad commit" my_bisect_log.txt &&
196 # $HASH1 is good, $HASH5 is bad, we skip $HASH3
197 # but $HASH4 is good,
198 # so we should find $HASH5 as the first bad commit
200 test_expect_success
'bisect skip: add line and then a new test' '
201 add_line_into_file "5: Another new line." hello &&
202 HASH5=$(git rev-parse --verify HEAD) &&
203 git bisect start $HASH5 $HASH1 &&
205 git bisect good > my_bisect_log.txt &&
206 grep "$HASH5 is first bad commit" my_bisect_log.txt &&
207 git bisect log > log_to_replay.txt &&
211 test_expect_success
'bisect skip and bisect replay' '
212 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
213 grep "$HASH5 is first bad commit" my_bisect_log.txt &&
218 test_expect_success
'bisect run & skip: cannot tell between 2' '
219 add_line_into_file "6: Yet a line." hello &&
220 HASH6=$(git rev-parse --verify HEAD) &&
221 echo "#"\!"/bin/sh" > test_script.sh &&
222 echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
223 echo "grep line hello > /dev/null" >> test_script.sh &&
224 echo "test \$? -ne 0" >> test_script.sh &&
225 chmod +x test_script.sh &&
226 git bisect start $HASH6 $HASH1 &&
227 if git bisect run ./test_script.sh > my_bisect_log.txt
229 echo Oops, should have failed.
233 grep "first bad commit could be any of" my_bisect_log.txt &&
234 ! grep $HASH3 my_bisect_log.txt &&
235 ! grep $HASH6 my_bisect_log.txt &&
236 grep $HASH4 my_bisect_log.txt &&
237 grep $HASH5 my_bisect_log.txt
242 test_expect_success
'bisect run & skip: find first bad' '
244 add_line_into_file "7: Should be the last line." hello &&
245 HASH7=$(git rev-parse --verify HEAD) &&
246 echo "#"\!"/bin/sh" > test_script.sh &&
247 echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
248 echo "tail -1 hello | grep day > /dev/null && exit 125" >> test_script.sh &&
249 echo "grep Yet hello > /dev/null" >> test_script.sh &&
250 echo "test \$? -ne 0" >> test_script.sh &&
251 chmod +x test_script.sh &&
252 git bisect start $HASH7 $HASH1 &&
253 git bisect run ./test_script.sh > my_bisect_log.txt &&
254 grep "$HASH6 is first bad commit" my_bisect_log.txt
257 test_expect_success
'bisect starting with a detached HEAD' '
260 git checkout master^ &&
261 HEAD=$(git rev-parse --verify HEAD) &&
263 test $HEAD = $(cat .git/head-name) &&
265 test $HEAD = $(git rev-parse --verify HEAD)