hooks--update: decline deleting tags or branches by default, add config options
[git/spearce.git] / t / t6030-bisect-porcelain.sh
blob53956c08e2754eb68a2a8311b26e16f5ee891308
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 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
75 # but $HASH2 is bad,
76 # so we should find $HASH2 as the first bad commit
77 test_expect_success 'bisect skip: successfull result' '
78 git bisect reset &&
79 git bisect start $HASH4 $HASH1 &&
80 git bisect skip &&
81 git bisect bad > my_bisect_log.txt &&
82 grep "$HASH2 is first bad commit" my_bisect_log.txt &&
83 git bisect reset
86 # $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
87 # so we should not be able to tell the first bad commit
88 # among $HASH2, $HASH3 and $HASH4
89 test_expect_success 'bisect skip: cannot tell between 3 commits' '
90 git bisect start $HASH4 $HASH1 &&
91 git bisect skip || return 1
93 if git bisect skip > my_bisect_log.txt
94 then
95 echo Oops, should have failed.
96 false
97 else
98 test $? -eq 2 &&
99 grep "first bad commit could be any of" my_bisect_log.txt &&
100 ! grep $HASH1 my_bisect_log.txt &&
101 grep $HASH2 my_bisect_log.txt &&
102 grep $HASH3 my_bisect_log.txt &&
103 grep $HASH4 my_bisect_log.txt &&
104 git bisect reset
108 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
109 # but $HASH2 is good,
110 # so we should not be able to tell the first bad commit
111 # among $HASH3 and $HASH4
112 test_expect_success 'bisect skip: cannot tell between 2 commits' '
113 git bisect start $HASH4 $HASH1 &&
114 git bisect skip || return 1
116 if git bisect good > my_bisect_log.txt
117 then
118 echo Oops, should have failed.
119 false
120 else
121 test $? -eq 2 &&
122 grep "first bad commit could be any of" my_bisect_log.txt &&
123 ! grep $HASH1 my_bisect_log.txt &&
124 ! grep $HASH2 my_bisect_log.txt &&
125 grep $HASH3 my_bisect_log.txt &&
126 grep $HASH4 my_bisect_log.txt &&
127 git bisect reset
131 # We want to automatically find the commit that
132 # introduced "Another" into hello.
133 test_expect_success \
134 '"git bisect run" simple case' \
135 'echo "#"\!"/bin/sh" > test_script.sh &&
136 echo "grep Another hello > /dev/null" >> test_script.sh &&
137 echo "test \$? -ne 0" >> test_script.sh &&
138 chmod +x test_script.sh &&
139 git bisect start &&
140 git bisect good $HASH1 &&
141 git bisect bad $HASH4 &&
142 git bisect run ./test_script.sh > my_bisect_log.txt &&
143 grep "$HASH3 is first bad commit" my_bisect_log.txt &&
144 git bisect reset'
146 # We want to automatically find the commit that
147 # introduced "Ciao" into hello.
148 test_expect_success \
149 '"git bisect run" with more complex "git bisect start"' \
150 'echo "#"\!"/bin/sh" > test_script.sh &&
151 echo "grep Ciao hello > /dev/null" >> test_script.sh &&
152 echo "test \$? -ne 0" >> test_script.sh &&
153 chmod +x test_script.sh &&
154 git bisect start $HASH4 $HASH1 &&
155 git bisect run ./test_script.sh > my_bisect_log.txt &&
156 grep "$HASH4 is first bad commit" my_bisect_log.txt &&
157 git bisect reset'
159 # $HASH1 is good, $HASH5 is bad, we skip $HASH3
160 # but $HASH4 is good,
161 # so we should find $HASH5 as the first bad commit
162 HASH5=
163 test_expect_success 'bisect skip: add line and then a new test' '
164 add_line_into_file "5: Another new line." hello &&
165 HASH5=$(git rev-parse --verify HEAD) &&
166 git bisect start $HASH5 $HASH1 &&
167 git bisect skip &&
168 git bisect good > my_bisect_log.txt &&
169 grep "$HASH5 is first bad commit" my_bisect_log.txt &&
170 git bisect log > log_to_replay.txt
171 git bisect reset
174 test_expect_success 'bisect skip and bisect replay' '
175 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
176 grep "$HASH5 is first bad commit" my_bisect_log.txt &&
177 git bisect reset
180 HASH6=
181 test_expect_success 'bisect run & skip: cannot tell between 2' '
182 add_line_into_file "6: Yet a line." hello &&
183 HASH6=$(git rev-parse --verify HEAD) &&
184 echo "#"\!"/bin/sh" > test_script.sh &&
185 echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
186 echo "grep line hello > /dev/null" >> test_script.sh &&
187 echo "test \$? -ne 0" >> test_script.sh &&
188 chmod +x test_script.sh &&
189 git bisect start $HASH6 $HASH1 &&
190 if git bisect run ./test_script.sh > my_bisect_log.txt
191 then
192 echo Oops, should have failed.
193 false
194 else
195 test $? -eq 2 &&
196 grep "first bad commit could be any of" my_bisect_log.txt &&
197 ! grep $HASH3 my_bisect_log.txt &&
198 ! grep $HASH6 my_bisect_log.txt &&
199 grep $HASH4 my_bisect_log.txt &&
200 grep $HASH5 my_bisect_log.txt
204 HASH7=
205 test_expect_success 'bisect run & skip: find first bad' '
206 git bisect reset &&
207 add_line_into_file "7: Should be the last line." hello &&
208 HASH7=$(git rev-parse --verify HEAD) &&
209 echo "#"\!"/bin/sh" > test_script.sh &&
210 echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
211 echo "tail -1 hello | grep day > /dev/null && exit 125" >> test_script.sh &&
212 echo "grep Yet hello > /dev/null" >> test_script.sh &&
213 echo "test \$? -ne 0" >> test_script.sh &&
214 chmod +x test_script.sh &&
215 git bisect start $HASH7 $HASH1 &&
216 git bisect run ./test_script.sh > my_bisect_log.txt &&
217 grep "$HASH6 is first bad commit" my_bisect_log.txt
222 test_done