Windows ANSI - hook write()
[git/mingw/4msysgit/peterh.git] / t / t6030-bisect-porcelain.sh
blob0626544823d6ff9d37ea86c752285d093788df3e
1 #!/bin/sh
3 # Copyright (c) 2007 Christian Couder
5 test_description='Tests git-bisect functionality'
7 exec </dev/null
9 . ./test-lib.sh
11 add_line_into_file()
13 _line=$1
14 _file=$2
16 if [ -f "$_file" ]; then
17 echo "$_line" >> $_file || return $?
18 MSG="Add <$_line> into <$_file>."
19 else
20 echo "$_line" > $_file || return $?
21 git add $_file || return $?
22 MSG="Create file <$_file> with <$_line> inside."
25 test_tick
26 git-commit --quiet -m "$MSG" $_file
29 HASH1=
30 HASH2=
31 HASH3=
32 HASH4=
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' '
46 git bisect reset &&
47 git bisect start &&
48 git bisect bad $HASH4 &&
49 git bisect next
52 test_expect_success 'bisect does not start with only one good' '
53 git bisect reset &&
54 git bisect start &&
55 git bisect good $HASH1 || return 1
57 if git bisect next
58 then
59 echo Oops, should have failed.
60 false
61 else
66 test_expect_success 'bisect start with one bad and good' '
67 git bisect reset &&
68 git bisect start &&
69 git bisect good $HASH1 &&
70 git bisect bad $HASH4 &&
71 git bisect next
74 test_expect_success 'bisect fails if given any junk instead of revs' '
75 git bisect reset &&
76 test_must_fail git bisect start foo $HASH1 -- &&
77 test_must_fail git bisect start $HASH4 $HASH1 bar -- &&
78 test -z "$(git for-each-ref "refs/bisect/*")" &&
79 test_must_fail ls .git/BISECT_* &&
80 git bisect start &&
81 test_must_fail git bisect good foo $HASH1 &&
82 test_must_fail git bisect good $HASH1 bar &&
83 test_must_fail git bisect bad frotz &&
84 test_must_fail git bisect bad $HASH3 $HASH4 &&
85 test_must_fail git bisect skip bar $HASH3 &&
86 test_must_fail git bisect skip $HASH1 foo &&
87 test -z "$(git for-each-ref "refs/bisect/*")" &&
88 git bisect good $HASH1 &&
89 git bisect bad $HASH4
92 test_expect_success 'bisect reset: back in the master branch' '
93 git bisect reset &&
94 echo "* master" > branch.expect &&
95 git branch > branch.output &&
96 cmp branch.expect branch.output
99 test_expect_success 'bisect reset: back in another branch' '
100 git checkout -b other &&
101 git bisect start &&
102 git bisect good $HASH1 &&
103 git bisect bad $HASH3 &&
104 git bisect reset &&
105 echo " master" > branch.expect &&
106 echo "* other" >> branch.expect &&
107 git branch > branch.output &&
108 cmp branch.expect branch.output
111 test_expect_success 'bisect reset when not bisecting' '
112 git bisect reset &&
113 git branch > branch.output &&
114 cmp branch.expect branch.output
117 test_expect_success 'bisect reset removes packed refs' '
118 git bisect reset &&
119 git bisect start &&
120 git bisect good $HASH1 &&
121 git bisect bad $HASH3 &&
122 git pack-refs --all --prune &&
123 git bisect next &&
124 git bisect reset &&
125 test -z "$(git for-each-ref "refs/bisect/*")" &&
126 test -z "$(git for-each-ref "refs/heads/bisect")"
129 test_expect_success 'bisect start: back in good branch' '
130 git branch > branch.output &&
131 grep "* other" branch.output > /dev/null &&
132 git bisect start $HASH4 $HASH1 -- &&
133 git bisect good &&
134 git bisect start $HASH4 $HASH1 -- &&
135 git bisect bad &&
136 git bisect reset &&
137 git branch > branch.output &&
138 grep "* other" branch.output > /dev/null
141 test_expect_success 'bisect start: no ".git/BISECT_START" if junk rev' '
142 git bisect start $HASH4 $HASH1 -- &&
143 git bisect good &&
144 test_must_fail git bisect start $HASH4 foo -- &&
145 git branch > branch.output &&
146 grep "* other" branch.output > /dev/null &&
147 test_must_fail test -e .git/BISECT_START
150 test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
151 git bisect start $HASH4 $HASH1 -- &&
152 git bisect good &&
153 test_must_fail git bisect start $HASH1 $HASH4 -- &&
154 git branch > branch.output &&
155 grep "* other" branch.output > /dev/null &&
156 test_must_fail test -e .git/BISECT_START
159 test_expect_success 'bisect start: no ".git/BISECT_START" if checkout error' '
160 echo "temp stuff" > hello &&
161 test_must_fail git bisect start $HASH4 $HASH1 -- &&
162 git branch &&
163 git branch > branch.output &&
164 grep "* other" branch.output > /dev/null &&
165 test_must_fail test -e .git/BISECT_START &&
166 test -z "$(git for-each-ref "refs/bisect/*")" &&
167 git checkout HEAD hello
170 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
171 # but $HASH2 is bad,
172 # so we should find $HASH2 as the first bad commit
173 test_expect_success 'bisect skip: successfull result' '
174 git bisect reset &&
175 git bisect start $HASH4 $HASH1 &&
176 git bisect skip &&
177 git bisect bad > my_bisect_log.txt &&
178 grep "$HASH2 is first bad commit" my_bisect_log.txt &&
179 git bisect reset
182 # $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
183 # so we should not be able to tell the first bad commit
184 # among $HASH2, $HASH3 and $HASH4
185 test_expect_success 'bisect skip: cannot tell between 3 commits' '
186 git bisect start $HASH4 $HASH1 &&
187 git bisect skip || return 1
189 if git bisect skip > my_bisect_log.txt
190 then
191 echo Oops, should have failed.
192 false
193 else
194 test $? -eq 2 &&
195 grep "first bad commit could be any of" my_bisect_log.txt &&
196 ! grep $HASH1 my_bisect_log.txt &&
197 grep $HASH2 my_bisect_log.txt &&
198 grep $HASH3 my_bisect_log.txt &&
199 grep $HASH4 my_bisect_log.txt &&
200 git bisect reset
204 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
205 # but $HASH2 is good,
206 # so we should not be able to tell the first bad commit
207 # among $HASH3 and $HASH4
208 test_expect_success 'bisect skip: cannot tell between 2 commits' '
209 git bisect start $HASH4 $HASH1 &&
210 git bisect skip || return 1
212 if git bisect good > my_bisect_log.txt
213 then
214 echo Oops, should have failed.
215 false
216 else
217 test $? -eq 2 &&
218 grep "first bad commit could be any of" my_bisect_log.txt &&
219 ! grep $HASH1 my_bisect_log.txt &&
220 ! grep $HASH2 my_bisect_log.txt &&
221 grep $HASH3 my_bisect_log.txt &&
222 grep $HASH4 my_bisect_log.txt &&
223 git bisect reset
227 # We want to automatically find the commit that
228 # introduced "Another" into hello.
229 test_expect_success \
230 '"git bisect run" simple case' \
231 'echo "#"\!"/bin/sh" > test_script.sh &&
232 echo "grep Another hello > /dev/null" >> test_script.sh &&
233 echo "test \$? -ne 0" >> test_script.sh &&
234 chmod +x test_script.sh &&
235 git bisect start &&
236 git bisect good $HASH1 &&
237 git bisect bad $HASH4 &&
238 git bisect run ./test_script.sh > my_bisect_log.txt &&
239 grep "$HASH3 is first bad commit" my_bisect_log.txt &&
240 git bisect reset'
242 # We want to automatically find the commit that
243 # introduced "Ciao" into hello.
244 test_expect_success \
245 '"git bisect run" with more complex "git bisect start"' \
246 'echo "#"\!"/bin/sh" > test_script.sh &&
247 echo "grep Ciao hello > /dev/null" >> test_script.sh &&
248 echo "test \$? -ne 0" >> test_script.sh &&
249 chmod +x test_script.sh &&
250 git bisect start $HASH4 $HASH1 &&
251 git bisect run ./test_script.sh > my_bisect_log.txt &&
252 grep "$HASH4 is first bad commit" my_bisect_log.txt &&
253 git bisect reset'
255 # $HASH1 is good, $HASH5 is bad, we skip $HASH3
256 # but $HASH4 is good,
257 # so we should find $HASH5 as the first bad commit
258 HASH5=
259 test_expect_success 'bisect skip: add line and then a new test' '
260 add_line_into_file "5: Another new line." hello &&
261 HASH5=$(git rev-parse --verify HEAD) &&
262 git bisect start $HASH5 $HASH1 &&
263 git bisect skip &&
264 git bisect good > my_bisect_log.txt &&
265 grep "$HASH5 is first bad commit" my_bisect_log.txt &&
266 git bisect log > log_to_replay.txt &&
267 git bisect reset
270 test_expect_success 'bisect skip and bisect replay' '
271 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
272 grep "$HASH5 is first bad commit" my_bisect_log.txt &&
273 git bisect reset
276 HASH6=
277 test_expect_success 'bisect run & skip: cannot tell between 2' '
278 add_line_into_file "6: Yet a line." hello &&
279 HASH6=$(git rev-parse --verify HEAD) &&
280 echo "#"\!"/bin/sh" > test_script.sh &&
281 echo "sed -ne \\\$p hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
282 echo "grep line hello > /dev/null" >> test_script.sh &&
283 echo "test \$? -ne 0" >> test_script.sh &&
284 chmod +x test_script.sh &&
285 git bisect start $HASH6 $HASH1 &&
286 if git bisect run ./test_script.sh > my_bisect_log.txt
287 then
288 echo Oops, should have failed.
289 false
290 else
291 test $? -eq 2 &&
292 grep "first bad commit could be any of" my_bisect_log.txt &&
293 ! grep $HASH3 my_bisect_log.txt &&
294 ! grep $HASH6 my_bisect_log.txt &&
295 grep $HASH4 my_bisect_log.txt &&
296 grep $HASH5 my_bisect_log.txt
300 HASH7=
301 test_expect_success 'bisect run & skip: find first bad' '
302 git bisect reset &&
303 add_line_into_file "7: Should be the last line." hello &&
304 HASH7=$(git rev-parse --verify HEAD) &&
305 echo "#"\!"/bin/sh" > test_script.sh &&
306 echo "sed -ne \\\$p hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
307 echo "sed -ne \\\$p hello | grep day > /dev/null && exit 125" >> test_script.sh &&
308 echo "grep Yet hello > /dev/null" >> test_script.sh &&
309 echo "test \$? -ne 0" >> test_script.sh &&
310 chmod +x test_script.sh &&
311 git bisect start $HASH7 $HASH1 &&
312 git bisect run ./test_script.sh > my_bisect_log.txt &&
313 grep "$HASH6 is first bad commit" my_bisect_log.txt
316 test_expect_success 'bisect starting with a detached HEAD' '
318 git bisect reset &&
319 git checkout master^ &&
320 HEAD=$(git rev-parse --verify HEAD) &&
321 git bisect start &&
322 test $HEAD = $(cat .git/BISECT_START) &&
323 git bisect reset &&
324 test $HEAD = $(git rev-parse --verify HEAD)
327 test_expect_success 'bisect errors out if bad and good are mistaken' '
328 git bisect reset &&
329 test_must_fail git bisect start $HASH2 $HASH4 2> rev_list_error &&
330 grep "mistake good and bad" rev_list_error &&
331 git bisect reset
334 test_expect_success 'bisect does not create a "bisect" branch' '
335 git bisect reset &&
336 git bisect start $HASH7 $HASH1 &&
337 git branch bisect &&
338 rev_hash4=$(git rev-parse --verify HEAD) &&
339 test "$rev_hash4" = "$HASH4" &&
340 git branch -D bisect &&
341 git bisect good &&
342 git branch bisect &&
343 rev_hash6=$(git rev-parse --verify HEAD) &&
344 test "$rev_hash6" = "$HASH6" &&
345 git bisect good > my_bisect_log.txt &&
346 grep "$HASH7 is first bad commit" my_bisect_log.txt &&
347 git bisect reset &&
348 rev_hash6=$(git rev-parse --verify bisect) &&
349 test "$rev_hash6" = "$HASH6" &&
350 git branch -D bisect
355 test_done