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 good and bad fails if not given only revs' '
77 test_must_fail git bisect good foo $HASH1 &&
78 test_must_fail git bisect good $HASH1 bar &&
79 test_must_fail git bisect bad frotz &&
80 test_must_fail git bisect bad $HASH3 $HASH4 &&
81 test_must_fail git bisect skip bar $HASH3 &&
82 test_must_fail git bisect skip $HASH1 foo &&
83 git bisect good $HASH1 &&
87 test_expect_success
'bisect reset: back in the master branch' '
89 echo "* master" > branch.expect &&
90 git branch > branch.output &&
91 cmp branch.expect branch.output
94 test_expect_success
'bisect reset: back in another branch' '
95 git checkout -b other &&
97 git bisect good $HASH1 &&
98 git bisect bad $HASH3 &&
100 echo " master" > branch.expect &&
101 echo "* other" >> branch.expect &&
102 git branch > branch.output &&
103 cmp branch.expect branch.output
106 test_expect_success
'bisect reset when not bisecting' '
108 git branch > branch.output &&
109 cmp branch.expect branch.output
112 test_expect_success
'bisect reset removes packed refs' '
115 git bisect good $HASH1 &&
116 git bisect bad $HASH3 &&
117 git pack-refs --all --prune &&
120 test -z "$(git for-each-ref "refs/bisect/*")" &&
121 test -z "$(git for-each-ref "refs/heads/bisect")"
124 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
126 # so we should find $HASH2 as the first bad commit
127 test_expect_success
'bisect skip: successfull result' '
129 git bisect start $HASH4 $HASH1 &&
131 git bisect bad > my_bisect_log.txt &&
132 grep "$HASH2 is first bad commit" my_bisect_log.txt &&
136 # $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
137 # so we should not be able to tell the first bad commit
138 # among $HASH2, $HASH3 and $HASH4
139 test_expect_success
'bisect skip: cannot tell between 3 commits' '
140 git bisect start $HASH4 $HASH1 &&
141 git bisect skip || return 1
143 if git bisect skip > my_bisect_log.txt
145 echo Oops, should have failed.
149 grep "first bad commit could be any of" my_bisect_log.txt &&
150 ! grep $HASH1 my_bisect_log.txt &&
151 grep $HASH2 my_bisect_log.txt &&
152 grep $HASH3 my_bisect_log.txt &&
153 grep $HASH4 my_bisect_log.txt &&
158 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
159 # but $HASH2 is good,
160 # so we should not be able to tell the first bad commit
161 # among $HASH3 and $HASH4
162 test_expect_success
'bisect skip: cannot tell between 2 commits' '
163 git bisect start $HASH4 $HASH1 &&
164 git bisect skip || return 1
166 if git bisect good > my_bisect_log.txt
168 echo Oops, should have failed.
172 grep "first bad commit could be any of" my_bisect_log.txt &&
173 ! grep $HASH1 my_bisect_log.txt &&
174 ! grep $HASH2 my_bisect_log.txt &&
175 grep $HASH3 my_bisect_log.txt &&
176 grep $HASH4 my_bisect_log.txt &&
181 # We want to automatically find the commit that
182 # introduced "Another" into hello.
183 test_expect_success \
184 '"git bisect run" simple case' \
185 'echo "#"\!"/bin/sh" > test_script.sh &&
186 echo "grep Another hello > /dev/null" >> test_script.sh &&
187 echo "test \$? -ne 0" >> test_script.sh &&
188 chmod +x test_script.sh &&
190 git bisect good $HASH1 &&
191 git bisect bad $HASH4 &&
192 git bisect run ./test_script.sh > my_bisect_log.txt &&
193 grep "$HASH3 is first bad commit" my_bisect_log.txt &&
196 # We want to automatically find the commit that
197 # introduced "Ciao" into hello.
198 test_expect_success \
199 '"git bisect run" with more complex "git bisect start"' \
200 'echo "#"\!"/bin/sh" > test_script.sh &&
201 echo "grep Ciao hello > /dev/null" >> test_script.sh &&
202 echo "test \$? -ne 0" >> test_script.sh &&
203 chmod +x test_script.sh &&
204 git bisect start $HASH4 $HASH1 &&
205 git bisect run ./test_script.sh > my_bisect_log.txt &&
206 grep "$HASH4 is first bad commit" my_bisect_log.txt &&
209 # $HASH1 is good, $HASH5 is bad, we skip $HASH3
210 # but $HASH4 is good,
211 # so we should find $HASH5 as the first bad commit
213 test_expect_success
'bisect skip: add line and then a new test' '
214 add_line_into_file "5: Another new line." hello &&
215 HASH5=$(git rev-parse --verify HEAD) &&
216 git bisect start $HASH5 $HASH1 &&
218 git bisect good > my_bisect_log.txt &&
219 grep "$HASH5 is first bad commit" my_bisect_log.txt &&
220 git bisect log > log_to_replay.txt &&
224 test_expect_success
'bisect skip and bisect replay' '
225 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
226 grep "$HASH5 is first bad commit" my_bisect_log.txt &&
231 test_expect_success
'bisect run & skip: cannot tell between 2' '
232 add_line_into_file "6: Yet a line." hello &&
233 HASH6=$(git rev-parse --verify HEAD) &&
234 echo "#"\!"/bin/sh" > test_script.sh &&
235 echo "sed -ne \\\$p hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
236 echo "grep line hello > /dev/null" >> test_script.sh &&
237 echo "test \$? -ne 0" >> test_script.sh &&
238 chmod +x test_script.sh &&
239 git bisect start $HASH6 $HASH1 &&
240 if git bisect run ./test_script.sh > my_bisect_log.txt
242 echo Oops, should have failed.
246 grep "first bad commit could be any of" my_bisect_log.txt &&
247 ! grep $HASH3 my_bisect_log.txt &&
248 ! grep $HASH6 my_bisect_log.txt &&
249 grep $HASH4 my_bisect_log.txt &&
250 grep $HASH5 my_bisect_log.txt
255 test_expect_success
'bisect run & skip: find first bad' '
257 add_line_into_file "7: Should be the last line." hello &&
258 HASH7=$(git rev-parse --verify HEAD) &&
259 echo "#"\!"/bin/sh" > test_script.sh &&
260 echo "sed -ne \\\$p hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
261 echo "sed -ne \\\$p hello | grep day > /dev/null && exit 125" >> test_script.sh &&
262 echo "grep Yet hello > /dev/null" >> test_script.sh &&
263 echo "test \$? -ne 0" >> test_script.sh &&
264 chmod +x test_script.sh &&
265 git bisect start $HASH7 $HASH1 &&
266 git bisect run ./test_script.sh > my_bisect_log.txt &&
267 grep "$HASH6 is first bad commit" my_bisect_log.txt
270 test_expect_success
'bisect starting with a detached HEAD' '
273 git checkout master^ &&
274 HEAD=$(git rev-parse --verify HEAD) &&
276 test $HEAD = $(cat .git/BISECT_START) &&
278 test $HEAD = $(git rev-parse --verify HEAD)