Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 1 | # This file isn't used as a test script directly, instead it is |
Josh Stone | 9b01f00 | 2011-04-21 15:07:36 -0700 | [diff] [blame] | 2 | # sourced from t8001-annotate.sh and t8002-blame.sh. |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 3 | |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 4 | check_count () { |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 5 | head= && |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 6 | file='file' && |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 7 | options= && |
| 8 | while : |
| 9 | do |
| 10 | case "$1" in |
| 11 | -h) head="$2"; shift; shift ;; |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 12 | -f) file="$2"; shift; shift ;; |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 13 | -*) options="$options $1"; shift ;; |
| 14 | *) break ;; |
| 15 | esac |
| 16 | done && |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 17 | echo "$PROG $options $file $head" >&4 && |
| 18 | $PROG $options $file $head >actual && |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 19 | perl -e ' |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 20 | my %expect = (@ARGV); |
Kevin Ballard | 27eea66 | 2010-10-16 04:09:20 -0700 | [diff] [blame] | 21 | my %count = map { $_ => 0 } keys %expect; |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 22 | while (<STDIN>) { |
| 23 | if (/^[0-9a-f]+\t\(([^\t]+)\t/) { |
| 24 | my $author = $1; |
| 25 | for ($author) { s/^\s*//; s/\s*$//; } |
Kevin Ballard | 27eea66 | 2010-10-16 04:09:20 -0700 | [diff] [blame] | 26 | $count{$author}++; |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | my $bad = 0; |
| 30 | while (my ($author, $count) = each %count) { |
| 31 | my $ok; |
Kevin Ballard | 27eea66 | 2010-10-16 04:09:20 -0700 | [diff] [blame] | 32 | my $value = 0; |
| 33 | $value = $expect{$author} if defined $expect{$author}; |
| 34 | if ($value != $count) { |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 35 | $bad = 1; |
| 36 | $ok = "bad"; |
| 37 | } |
| 38 | else { |
| 39 | $ok = "good"; |
| 40 | } |
Kevin Ballard | 27eea66 | 2010-10-16 04:09:20 -0700 | [diff] [blame] | 41 | print STDERR "Author $author (expected $value, attributed $count) $ok\n"; |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 42 | } |
| 43 | exit($bad); |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 44 | ' "$@" <actual |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 47 | test_expect_success 'setup A lines' ' |
| 48 | echo "1A quick brown fox jumps over the" >file && |
| 49 | echo "lazy dog" >>file && |
| 50 | git add file && |
| 51 | GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \ |
| 52 | git commit -a -m "Initial." |
| 53 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 54 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 55 | test_expect_success 'blame 1 author' ' |
| 56 | check_count A 2 |
| 57 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 58 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 59 | test_expect_success 'setup B lines' ' |
| 60 | echo "2A quick brown fox jumps over the" >>file && |
| 61 | echo "lazy dog" >>file && |
| 62 | GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \ |
| 63 | git commit -a -m "Second." |
| 64 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 65 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 66 | test_expect_success 'blame 2 authors' ' |
| 67 | check_count A 2 B 2 |
| 68 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 69 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 70 | test_expect_success 'setup B1 lines (branch1)' ' |
| 71 | git checkout -b branch1 master && |
| 72 | echo "3A slow green fox jumps into the" >>file && |
| 73 | echo "well." >>file && |
| 74 | GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" \ |
| 75 | git commit -a -m "Branch1-1" |
| 76 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 77 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 78 | test_expect_success 'blame 2 authors + 1 branch1 author' ' |
| 79 | check_count A 2 B 2 B1 2 |
| 80 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 81 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 82 | test_expect_success 'setup B2 lines (branch2)' ' |
| 83 | git checkout -b branch2 master && |
| 84 | sed -e "s/2A quick brown/4A quick brown lazy dog/" <file >file.new && |
| 85 | mv file.new file && |
| 86 | GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" \ |
| 87 | git commit -a -m "Branch2-1" |
| 88 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 89 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 90 | test_expect_success 'blame 2 authors + 1 branch2 author' ' |
| 91 | check_count A 2 B 1 B2 1 |
| 92 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 93 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 94 | test_expect_success 'merge branch1 & branch2' ' |
Felipe Contreras | 501a75a | 2013-10-31 03:25:33 -0600 | [diff] [blame] | 95 | git merge branch1 |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 96 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 97 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 98 | test_expect_success 'blame 2 authors + 2 merged-in authors' ' |
| 99 | check_count A 2 B 1 B1 2 B2 1 |
| 100 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 101 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 102 | test_expect_success 'blame ancestor' ' |
| 103 | check_count -h master A 2 B 2 |
| 104 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 105 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 106 | test_expect_success 'blame great-ancestor' ' |
| 107 | check_count -h master^ A 2 |
| 108 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 109 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 110 | test_expect_success 'setup evil merge' ' |
| 111 | echo "evil merge." >>file && |
| 112 | git commit -a --amend |
| 113 | ' |
Junio C Hamano | ce5b6e7 | 2006-03-05 22:37:15 -0800 | [diff] [blame] | 114 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 115 | test_expect_success 'blame evil merge' ' |
| 116 | check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 |
| 117 | ' |
Junio C Hamano | ce5b6e7 | 2006-03-05 22:37:15 -0800 | [diff] [blame] | 118 | |
Johannes Schindelin | e228c17 | 2013-12-27 21:49:57 +0100 | [diff] [blame] | 119 | test_expect_success 'blame huge graft' ' |
| 120 | test_when_finished "git checkout branch2" && |
| 121 | test_when_finished "rm -f .git/info/grafts" && |
| 122 | graft= && |
| 123 | for i in 0 1 2 |
| 124 | do |
| 125 | for j in 0 1 2 3 4 5 6 7 8 9 |
| 126 | do |
| 127 | git checkout --orphan "$i$j" && |
| 128 | printf "%s\n" "$i" "$j" >file && |
| 129 | test_tick && |
| 130 | GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \ |
| 131 | git commit -a -m "$i$j" && |
| 132 | commit=$(git rev-parse --verify HEAD) && |
| 133 | graft="$graft$commit " |
| 134 | done |
| 135 | done && |
| 136 | printf "%s " $graft >.git/info/grafts && |
| 137 | check_count -h 00 01 1 10 1 |
| 138 | ' |
| 139 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 140 | test_expect_success 'setup incomplete line' ' |
| 141 | echo "incomplete" | tr -d "\\012" >>file && |
| 142 | GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \ |
| 143 | git commit -a -m "Incomplete" |
| 144 | ' |
Junio C Hamano | 1242642 | 2006-03-06 00:41:17 -0800 | [diff] [blame] | 145 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 146 | test_expect_success 'blame incomplete line' ' |
| 147 | check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1 |
| 148 | ' |
Junio C Hamano | 1242642 | 2006-03-06 00:41:17 -0800 | [diff] [blame] | 149 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 150 | test_expect_success 'setup edits' ' |
| 151 | mv file file.orig && |
| 152 | { |
| 153 | cat file.orig && |
| 154 | echo |
| 155 | } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" >file && |
| 156 | echo "incomplete" | tr -d "\\012" >>file && |
| 157 | GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" \ |
| 158 | git commit -a -m "edit" |
| 159 | ' |
Junio C Hamano | 1242642 | 2006-03-06 00:41:17 -0800 | [diff] [blame] | 160 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 161 | test_expect_success 'blame edits' ' |
| 162 | check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 |
| 163 | ' |
Josh Stone | 9b01f00 | 2011-04-21 15:07:36 -0700 | [diff] [blame] | 164 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 165 | test_expect_success 'setup obfuscated email' ' |
| 166 | echo "No robots allowed" >file.new && |
| 167 | cat file >>file.new && |
| 168 | mv file.new file && |
| 169 | GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \ |
| 170 | git commit -a -m "norobots" |
| 171 | ' |
Josh Stone | 9b01f00 | 2011-04-21 15:07:36 -0700 | [diff] [blame] | 172 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 173 | test_expect_success 'blame obfuscated email' ' |
| 174 | check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 |
| 175 | ' |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 176 | |
| 177 | test_expect_success 'blame -L 1 (all)' ' |
| 178 | check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 |
| 179 | ' |
| 180 | |
| 181 | test_expect_success 'blame -L , (all)' ' |
| 182 | check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 |
| 183 | ' |
| 184 | |
| 185 | test_expect_success 'blame -L X (X to end)' ' |
| 186 | check_count -L5 B1 1 C 1 D 1 "A U Thor" 1 |
| 187 | ' |
| 188 | |
| 189 | test_expect_success 'blame -L X, (X to end)' ' |
| 190 | check_count -L5, B1 1 C 1 D 1 "A U Thor" 1 |
| 191 | ' |
| 192 | |
| 193 | test_expect_success 'blame -L ,Y (up to Y)' ' |
| 194 | check_count -L,3 A 1 B2 1 E 1 |
| 195 | ' |
| 196 | |
| 197 | test_expect_success 'blame -L X,X' ' |
| 198 | check_count -L3,3 B2 1 |
| 199 | ' |
| 200 | |
| 201 | test_expect_success 'blame -L X,Y' ' |
| 202 | check_count -L3,6 B 1 B1 1 B2 1 D 1 |
| 203 | ' |
| 204 | |
| 205 | test_expect_success 'blame -L Y,X (undocumented)' ' |
| 206 | check_count -L6,3 B 1 B1 1 B2 1 D 1 |
| 207 | ' |
| 208 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 209 | test_expect_success 'blame -L -X' ' |
Eric Sunshine | 9527604 | 2013-08-06 09:59:48 -0400 | [diff] [blame] | 210 | test_must_fail $PROG -L-1 file |
| 211 | ' |
| 212 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 213 | test_expect_success 'blame -L 0' ' |
Eric Sunshine | 9527604 | 2013-08-06 09:59:48 -0400 | [diff] [blame] | 214 | test_must_fail $PROG -L0 file |
| 215 | ' |
| 216 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 217 | test_expect_success 'blame -L ,0' ' |
Eric Sunshine | 9527604 | 2013-08-06 09:59:48 -0400 | [diff] [blame] | 218 | test_must_fail $PROG -L,0 file |
| 219 | ' |
| 220 | |
Eric Sunshine | 5d57cac | 2013-07-31 04:15:45 -0400 | [diff] [blame] | 221 | test_expect_success 'blame -L ,+0' ' |
Eric Sunshine | 82cd7e5 | 2013-07-31 04:15:44 -0400 | [diff] [blame] | 222 | test_must_fail $PROG -L,+0 file |
| 223 | ' |
| 224 | |
Eric Sunshine | abba353 | 2013-07-31 04:15:43 -0400 | [diff] [blame] | 225 | test_expect_success 'blame -L X,+0' ' |
Eric Sunshine | dedb912 | 2013-07-31 04:15:42 -0400 | [diff] [blame] | 226 | test_must_fail $PROG -L1,+0 file |
| 227 | ' |
| 228 | |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 229 | test_expect_success 'blame -L X,+1' ' |
| 230 | check_count -L3,+1 B2 1 |
| 231 | ' |
| 232 | |
| 233 | test_expect_success 'blame -L X,+N' ' |
| 234 | check_count -L3,+4 B 1 B1 1 B2 1 D 1 |
| 235 | ' |
| 236 | |
Eric Sunshine | 5d57cac | 2013-07-31 04:15:45 -0400 | [diff] [blame] | 237 | test_expect_success 'blame -L ,-0' ' |
Eric Sunshine | 82cd7e5 | 2013-07-31 04:15:44 -0400 | [diff] [blame] | 238 | test_must_fail $PROG -L,-0 file |
| 239 | ' |
| 240 | |
Eric Sunshine | abba353 | 2013-07-31 04:15:43 -0400 | [diff] [blame] | 241 | test_expect_success 'blame -L X,-0' ' |
Eric Sunshine | dedb912 | 2013-07-31 04:15:42 -0400 | [diff] [blame] | 242 | test_must_fail $PROG -L1,-0 file |
| 243 | ' |
| 244 | |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 245 | test_expect_success 'blame -L X,-1' ' |
| 246 | check_count -L3,-1 B2 1 |
| 247 | ' |
| 248 | |
| 249 | test_expect_success 'blame -L X,-N' ' |
| 250 | check_count -L6,-4 B 1 B1 1 B2 1 D 1 |
| 251 | ' |
| 252 | |
| 253 | test_expect_success 'blame -L /RE/ (RE to end)' ' |
| 254 | check_count -L/evil/ C 1 "A U Thor" 1 |
| 255 | ' |
| 256 | |
| 257 | test_expect_success 'blame -L /RE/,/RE2/' ' |
| 258 | check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1 |
| 259 | ' |
| 260 | |
| 261 | test_expect_success 'blame -L X,/RE/' ' |
| 262 | check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1 |
| 263 | ' |
| 264 | |
| 265 | test_expect_success 'blame -L /RE/,Y' ' |
| 266 | check_count -L/99/,7 B1 1 D 1 "A U Thor" 1 |
| 267 | ' |
| 268 | |
| 269 | test_expect_success 'blame -L /RE/,+N' ' |
| 270 | check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1 |
| 271 | ' |
| 272 | |
| 273 | test_expect_success 'blame -L /RE/,-N' ' |
| 274 | check_count -L/99/,-3 B 1 B2 1 D 1 |
| 275 | ' |
| 276 | |
Eric Sunshine | 580b4f3 | 2013-07-31 04:15:36 -0400 | [diff] [blame] | 277 | # 'file' ends with an incomplete line, so 'wc' reports one fewer lines than |
| 278 | # git-blame sees, hence the last line is actually $(wc...)+1. |
| 279 | test_expect_success 'blame -L X (X == nlines)' ' |
| 280 | n=$(expr $(wc -l <file) + 1) && |
| 281 | check_count -L$n C 1 |
| 282 | ' |
| 283 | |
Eric Sunshine | 164a9cf | 2013-07-31 04:15:38 -0400 | [diff] [blame] | 284 | test_expect_success 'blame -L X (X == nlines + 1)' ' |
Eric Sunshine | 580b4f3 | 2013-07-31 04:15:36 -0400 | [diff] [blame] | 285 | n=$(expr $(wc -l <file) + 2) && |
| 286 | test_must_fail $PROG -L$n file |
| 287 | ' |
| 288 | |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 289 | test_expect_success 'blame -L X (X > nlines)' ' |
| 290 | test_must_fail $PROG -L12345 file |
| 291 | ' |
| 292 | |
Eric Sunshine | 580b4f3 | 2013-07-31 04:15:36 -0400 | [diff] [blame] | 293 | test_expect_success 'blame -L ,Y (Y == nlines)' ' |
| 294 | n=$(expr $(wc -l <file) + 1) && |
| 295 | check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 |
| 296 | ' |
| 297 | |
| 298 | test_expect_success 'blame -L ,Y (Y == nlines + 1)' ' |
| 299 | n=$(expr $(wc -l <file) + 2) && |
| 300 | test_must_fail $PROG -L,$n file |
| 301 | ' |
| 302 | |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 303 | test_expect_success 'blame -L ,Y (Y > nlines)' ' |
| 304 | test_must_fail $PROG -L,12345 file |
| 305 | ' |
| 306 | |
Eric Sunshine | 91b5494 | 2013-08-06 09:59:39 -0400 | [diff] [blame] | 307 | test_expect_success 'blame -L multiple (disjoint)' ' |
| 308 | check_count -L2,3 -L6,7 A 1 B1 1 B2 1 "A U Thor" 1 |
| 309 | ' |
| 310 | |
| 311 | test_expect_success 'blame -L multiple (disjoint: unordered)' ' |
| 312 | check_count -L6,7 -L2,3 A 1 B1 1 B2 1 "A U Thor" 1 |
| 313 | ' |
| 314 | |
| 315 | test_expect_success 'blame -L multiple (adjacent)' ' |
| 316 | check_count -L2,3 -L4,5 A 1 B 1 B2 1 D 1 |
| 317 | ' |
| 318 | |
| 319 | test_expect_success 'blame -L multiple (adjacent: unordered)' ' |
| 320 | check_count -L4,5 -L2,3 A 1 B 1 B2 1 D 1 |
| 321 | ' |
| 322 | |
| 323 | test_expect_success 'blame -L multiple (overlapping)' ' |
| 324 | check_count -L2,4 -L3,5 A 1 B 1 B2 1 D 1 |
| 325 | ' |
| 326 | |
| 327 | test_expect_success 'blame -L multiple (overlapping: unordered)' ' |
| 328 | check_count -L3,5 -L2,4 A 1 B 1 B2 1 D 1 |
| 329 | ' |
| 330 | |
| 331 | test_expect_success 'blame -L multiple (superset/subset)' ' |
| 332 | check_count -L2,8 -L3,5 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1 |
| 333 | ' |
| 334 | |
| 335 | test_expect_success 'blame -L multiple (superset/subset: unordered)' ' |
| 336 | check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1 |
| 337 | ' |
| 338 | |
Eric Sunshine | 52f4d12 | 2013-08-06 09:59:42 -0400 | [diff] [blame] | 339 | test_expect_success 'blame -L /RE/ (relative)' ' |
| 340 | check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1 |
| 341 | ' |
| 342 | |
| 343 | test_expect_success 'blame -L /RE/ (relative: no preceding range)' ' |
| 344 | check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1 |
| 345 | ' |
| 346 | |
| 347 | test_expect_success 'blame -L /RE/ (relative: adjacent)' ' |
| 348 | check_count -L1,1 -L/dog/,+1 A 1 E 1 |
| 349 | ' |
| 350 | |
| 351 | test_expect_success 'blame -L /RE/ (relative: not found)' ' |
| 352 | test_must_fail $PROG -L4,4 -L/dog/ file |
| 353 | ' |
| 354 | |
| 355 | test_expect_success 'blame -L /RE/ (relative: end-of-file)' ' |
| 356 | test_must_fail $PROG -L, -L/$/ file |
| 357 | ' |
| 358 | |
Eric Sunshine | a6ac5f9 | 2013-08-06 09:59:45 -0400 | [diff] [blame] | 359 | test_expect_success 'blame -L ^/RE/ (absolute)' ' |
| 360 | check_count -L3,3 -L^/dog/,+2 A 1 B2 1 |
| 361 | ' |
| 362 | |
| 363 | test_expect_success 'blame -L ^/RE/ (absolute: no preceding range)' ' |
| 364 | check_count -L^/dog/,+2 A 1 B2 1 |
| 365 | ' |
| 366 | |
| 367 | test_expect_success 'blame -L ^/RE/ (absolute: not found)' ' |
| 368 | test_must_fail $PROG -L4,4 -L^/tambourine/ file |
| 369 | ' |
| 370 | |
| 371 | test_expect_success 'blame -L ^/RE/ (absolute: end-of-file)' ' |
| 372 | n=$(expr $(wc -l <file) + 1) && |
| 373 | check_count -L$n -L^/$/,+2 A 1 C 1 E 1 |
| 374 | ' |
| 375 | |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 376 | test_expect_success 'setup -L :regex' ' |
| 377 | tr Q "\\t" >hello.c <<-\EOF && |
| 378 | int main(int argc, const char *argv[]) |
| 379 | { |
| 380 | Qputs("hello"); |
| 381 | } |
| 382 | EOF |
| 383 | git add hello.c && |
| 384 | GIT_AUTHOR_NAME="F" GIT_AUTHOR_EMAIL="F@test.git" \ |
| 385 | git commit -m "hello" && |
| 386 | |
| 387 | mv hello.c hello.orig && |
René Scharfe | 3a4fc21 | 2013-08-05 17:21:17 +0200 | [diff] [blame] | 388 | sed -e "/}/ {x; s/$/Qputs(\"goodbye\");/; G;}" <hello.orig | |
| 389 | tr Q "\\t" >hello.c && |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 390 | GIT_AUTHOR_NAME="G" GIT_AUTHOR_EMAIL="G@test.git" \ |
| 391 | git commit -a -m "goodbye" && |
| 392 | |
| 393 | mv hello.c hello.orig && |
| 394 | echo "#include <stdio.h>" >hello.c && |
| 395 | cat hello.orig >>hello.c && |
| 396 | tr Q "\\t" >>hello.c <<-\EOF |
| 397 | void mail() |
| 398 | { |
| 399 | Qputs("mail"); |
| 400 | } |
| 401 | EOF |
| 402 | GIT_AUTHOR_NAME="H" GIT_AUTHOR_EMAIL="H@test.git" \ |
| 403 | git commit -a -m "mail" |
| 404 | ' |
| 405 | |
| 406 | test_expect_success 'blame -L :literal' ' |
| 407 | check_count -f hello.c -L:main F 4 G 1 |
| 408 | ' |
| 409 | |
| 410 | test_expect_success 'blame -L :regex' ' |
| 411 | check_count -f hello.c "-L:m[a-z][a-z]l" H 4 |
| 412 | ' |
| 413 | |
| 414 | test_expect_success 'blame -L :nomatch' ' |
| 415 | test_must_fail $PROG -L:nomatch hello.c |
| 416 | ' |
| 417 | |
Eric Sunshine | 1ce761a | 2013-08-06 09:59:46 -0400 | [diff] [blame] | 418 | test_expect_success 'blame -L :RE (relative)' ' |
| 419 | check_count -f hello.c -L3,3 -L:ma.. F 1 H 4 |
| 420 | ' |
| 421 | |
| 422 | test_expect_success 'blame -L :RE (relative: no preceding range)' ' |
| 423 | check_count -f hello.c -L:ma.. F 4 G 1 |
| 424 | ' |
| 425 | |
| 426 | test_expect_success 'blame -L :RE (relative: not found)' ' |
| 427 | test_must_fail $PROG -L3,3 -L:tambourine hello.c |
| 428 | ' |
| 429 | |
| 430 | test_expect_success 'blame -L :RE (relative: end-of-file)' ' |
| 431 | test_must_fail $PROG -L, -L:main hello.c |
| 432 | ' |
| 433 | |
Eric Sunshine | 215e76c | 2013-08-06 09:59:47 -0400 | [diff] [blame] | 434 | test_expect_success 'blame -L ^:RE (absolute)' ' |
| 435 | check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1 |
| 436 | ' |
| 437 | |
| 438 | test_expect_success 'blame -L ^:RE (absolute: no preceding range)' ' |
| 439 | check_count -f hello.c -L^:ma.. F 4 G 1 |
| 440 | ' |
| 441 | |
| 442 | test_expect_success 'blame -L ^:RE (absolute: not found)' ' |
| 443 | test_must_fail $PROG -L4,4 -L^:tambourine hello.c |
| 444 | ' |
| 445 | |
| 446 | test_expect_success 'blame -L ^:RE (absolute: end-of-file)' ' |
| 447 | n=$(printf "%d" $(wc -l <hello.c)) && |
| 448 | check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1 |
| 449 | ' |
| 450 | |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 451 | test_expect_success 'setup incremental' ' |
| 452 | ( |
| 453 | GIT_AUTHOR_NAME=I && |
| 454 | export GIT_AUTHOR_NAME && |
| 455 | GIT_AUTHOR_EMAIL=I@test.git && |
| 456 | export GIT_AUTHOR_EMAIL && |
| 457 | >incremental && |
| 458 | git add incremental && |
| 459 | git commit -m "step 0" && |
| 460 | printf "partial" >>incremental && |
| 461 | git commit -a -m "step 0.5" && |
| 462 | echo >>incremental && |
| 463 | git commit -a -m "step 1" |
| 464 | ) |
| 465 | ' |
| 466 | |
| 467 | test_expect_success 'blame empty' ' |
| 468 | check_count -h HEAD^^ -f incremental |
| 469 | ' |
| 470 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 471 | test_expect_success 'blame -L 0 empty' ' |
| 472 | test_must_fail $PROG -L0 incremental HEAD^^ |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 473 | ' |
| 474 | |
Eric Sunshine | 164a9cf | 2013-07-31 04:15:38 -0400 | [diff] [blame] | 475 | test_expect_success 'blame -L 1 empty' ' |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 476 | test_must_fail $PROG -L1 incremental HEAD^^ |
| 477 | ' |
| 478 | |
| 479 | test_expect_success 'blame -L 2 empty' ' |
| 480 | test_must_fail $PROG -L2 incremental HEAD^^ |
| 481 | ' |
| 482 | |
| 483 | test_expect_success 'blame half' ' |
| 484 | check_count -h HEAD^ -f incremental I 1 |
| 485 | ' |
| 486 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 487 | test_expect_success 'blame -L 0 half' ' |
| 488 | test_must_fail $PROG -L0 incremental HEAD^ |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 489 | ' |
| 490 | |
| 491 | test_expect_success 'blame -L 1 half' ' |
| 492 | check_count -h HEAD^ -f incremental -L1 I 1 |
| 493 | ' |
| 494 | |
Eric Sunshine | 164a9cf | 2013-07-31 04:15:38 -0400 | [diff] [blame] | 495 | test_expect_success 'blame -L 2 half' ' |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 496 | test_must_fail $PROG -L2 incremental HEAD^ |
| 497 | ' |
| 498 | |
| 499 | test_expect_success 'blame -L 3 half' ' |
| 500 | test_must_fail $PROG -L3 incremental HEAD^ |
| 501 | ' |
| 502 | |
| 503 | test_expect_success 'blame full' ' |
| 504 | check_count -f incremental I 1 |
| 505 | ' |
| 506 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 507 | test_expect_success 'blame -L 0 full' ' |
| 508 | test_must_fail $PROG -L0 incremental |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 509 | ' |
| 510 | |
| 511 | test_expect_success 'blame -L 1 full' ' |
| 512 | check_count -f incremental -L1 I 1 |
| 513 | ' |
| 514 | |
Eric Sunshine | 164a9cf | 2013-07-31 04:15:38 -0400 | [diff] [blame] | 515 | test_expect_success 'blame -L 2 full' ' |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 516 | test_must_fail $PROG -L2 incremental |
| 517 | ' |
| 518 | |
| 519 | test_expect_success 'blame -L 3 full' ' |
| 520 | test_must_fail $PROG -L3 incremental |
| 521 | ' |
| 522 | |
Eric Sunshine | f350cf9 | 2013-07-31 04:15:35 -0400 | [diff] [blame] | 523 | test_expect_success 'blame -L' ' |
| 524 | test_must_fail $PROG -L file |
| 525 | ' |
| 526 | |
| 527 | test_expect_success 'blame -L X,+' ' |
| 528 | test_must_fail $PROG -L1,+ file |
| 529 | ' |
| 530 | |
| 531 | test_expect_success 'blame -L X,-' ' |
| 532 | test_must_fail $PROG -L1,- file |
| 533 | ' |
| 534 | |
| 535 | test_expect_success 'blame -L X (non-numeric X)' ' |
| 536 | test_must_fail $PROG -LX file |
| 537 | ' |
| 538 | |
| 539 | test_expect_success 'blame -L X,Y (non-numeric Y)' ' |
| 540 | test_must_fail $PROG -L1,Y file |
| 541 | ' |
| 542 | |
| 543 | test_expect_success 'blame -L X,+N (non-numeric N)' ' |
| 544 | test_must_fail $PROG -L1,+N file |
| 545 | ' |
| 546 | |
| 547 | test_expect_success 'blame -L X,-N (non-numeric N)' ' |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 548 | test_must_fail $PROG -L1,-N file |
| 549 | ' |
Eric Sunshine | a6ac5f9 | 2013-08-06 09:59:45 -0400 | [diff] [blame] | 550 | |
| 551 | test_expect_success 'blame -L ,^/RE/' ' |
| 552 | test_must_fail $PROG -L1,^/99/ file |
| 553 | ' |