]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6030-bisect-porcelain.sh
Bisect: add "bisect skip" to the documentation.
[thirdparty/git.git] / t / t6030-bisect-porcelain.sh
CommitLineData
a17c4101
CC
1#!/bin/sh
2#
3# Copyright (c) 2007 Christian Couder
4#
4f506716 5test_description='Tests git-bisect functionality'
a17c4101 6
0a5280a9
JH
7exec </dev/null
8
a17c4101
CC
9. ./test-lib.sh
10
11add_line_into_file()
12{
13 _line=$1
14 _file=$2
15
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."
23 fi
24
ab69e89c
JH
25 test_tick
26 git-commit --quiet -m "$MSG" $_file
a17c4101
CC
27}
28
29HASH1=
ab69e89c 30HASH2=
a17c4101
CC
31HASH3=
32HASH4=
33
ab69e89c
JH
34test_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) &&
a17c4101 37 add_line_into_file "2: A new day for git" hello &&
ab69e89c 38 HASH2=$(git rev-parse --verify HEAD) &&
a17c4101 39 add_line_into_file "3: Another new day for git" hello &&
ab69e89c 40 HASH3=$(git rev-parse --verify HEAD) &&
a17c4101 41 add_line_into_file "4: Ciao for now" hello &&
ab69e89c
JH
42 HASH4=$(git rev-parse --verify HEAD)
43'
a17c4101 44
0a5280a9 45test_expect_success 'bisect starts with only one bad' '
4f506716
JH
46 git bisect reset &&
47 git bisect start &&
0a5280a9
JH
48 git bisect bad $HASH4 &&
49 git bisect next
4f506716
JH
50'
51
f9487929 52test_expect_success 'bisect does not start with only one good' '
4f506716
JH
53 git bisect reset &&
54 git bisect start &&
55 git bisect good $HASH1 || return 1
56
57 if git bisect next
58 then
59 echo Oops, should have failed.
60 false
61 else
62 :
63 fi
64'
65
66test_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
72'
73
97e1c51e
CC
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
77test_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
84'
85
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
89test_expect_success 'bisect skip: cannot tell between 3 commits' '
90 git bisect start $HASH4 $HASH1 &&
91 git bisect skip || return 1
92
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
105 fi
106'
107
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
112test_expect_success 'bisect skip: cannot tell between 2 commits' '
113 git bisect start $HASH4 $HASH1 &&
114 git bisect skip || return 1
115
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
128 fi
129'
130
a17c4101
CC
131# We want to automatically find the commit that
132# introduced "Another" into hello.
133test_expect_success \
38a47fd6
CC
134 '"git bisect run" simple case' \
135 'echo "#"\!"/bin/sh" > test_script.sh &&
a17c4101
CC
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 &&
38a47fd6
CC
143 grep "$HASH3 is first bad commit" my_bisect_log.txt &&
144 git bisect reset'
145
146# We want to automatically find the commit that
147# introduced "Ciao" into hello.
148test_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'
a17c4101 158
97e1c51e
CC
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
162HASH5=
163test_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 reset
171'
172
a17c4101
CC
173#
174#
175test_done