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 | |
Karsten Blees | e8d0887 | 2014-07-17 17:37:05 +0200 | [diff] [blame] | 4 | if test_have_prereq MINGW |
| 5 | then |
| 6 | sanitize_L () { |
| 7 | echo "$1" | sed 'sX\(^-L\|,\)\^\?/X&\\;*Xg' |
| 8 | } |
| 9 | else |
| 10 | sanitize_L () { |
| 11 | echo "$1" |
| 12 | } |
| 13 | fi |
| 14 | |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 15 | check_count () { |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 16 | head= && |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 17 | file='file' && |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 18 | options= && |
| 19 | while : |
| 20 | do |
| 21 | case "$1" in |
| 22 | -h) head="$2"; shift; shift ;; |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 23 | -f) file="$2"; shift; shift ;; |
Karsten Blees | e8d0887 | 2014-07-17 17:37:05 +0200 | [diff] [blame] | 24 | -L*) options="$options $(sanitize_L "$1")"; shift ;; |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 25 | -*) options="$options $1"; shift ;; |
| 26 | *) break ;; |
| 27 | esac |
| 28 | done && |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 29 | echo "$PROG $options $file $head" >&4 && |
| 30 | $PROG $options $file $head >actual && |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 31 | perl -e ' |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 32 | my %expect = (@ARGV); |
Kevin Ballard | 27eea66 | 2010-10-16 04:09:20 -0700 | [diff] [blame] | 33 | my %count = map { $_ => 0 } keys %expect; |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 34 | while (<STDIN>) { |
| 35 | if (/^[0-9a-f]+\t\(([^\t]+)\t/) { |
| 36 | my $author = $1; |
| 37 | for ($author) { s/^\s*//; s/\s*$//; } |
Kevin Ballard | 27eea66 | 2010-10-16 04:09:20 -0700 | [diff] [blame] | 38 | $count{$author}++; |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | my $bad = 0; |
| 42 | while (my ($author, $count) = each %count) { |
| 43 | my $ok; |
Kevin Ballard | 27eea66 | 2010-10-16 04:09:20 -0700 | [diff] [blame] | 44 | my $value = 0; |
| 45 | $value = $expect{$author} if defined $expect{$author}; |
| 46 | if ($value != $count) { |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 47 | $bad = 1; |
| 48 | $ok = "bad"; |
| 49 | } |
| 50 | else { |
| 51 | $ok = "good"; |
| 52 | } |
Kevin Ballard | 27eea66 | 2010-10-16 04:09:20 -0700 | [diff] [blame] | 53 | print STDERR "Author $author (expected $value, attributed $count) $ok\n"; |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 54 | } |
| 55 | exit($bad); |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 56 | ' "$@" <actual |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Edmundo Carmona Antoranz | e5f5d7d | 2022-04-06 20:13:20 +0200 | [diff] [blame] | 59 | get_progress_result () { |
| 60 | tr '\015' '\012' | tail -n 1 |
| 61 | } |
| 62 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 63 | test_expect_success 'setup A lines' ' |
| 64 | echo "1A quick brown fox jumps over the" >file && |
| 65 | echo "lazy dog" >>file && |
| 66 | git add file && |
| 67 | GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \ |
| 68 | git commit -a -m "Initial." |
| 69 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 70 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 71 | test_expect_success 'blame 1 author' ' |
| 72 | check_count A 2 |
| 73 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 74 | |
Jacob Keller | 603d0fd | 2023-04-24 12:35:08 -0700 | [diff] [blame] | 75 | test_expect_success 'blame working copy' ' |
| 76 | test_when_finished "git restore file" && |
| 77 | echo "1A quick brown fox jumps over the" >file && |
| 78 | echo "another lazy dog" >>file && |
| 79 | check_count A 1 "Not Committed Yet" 1 |
| 80 | ' |
| 81 | |
Jacob Keller | 1a3119e | 2023-03-24 10:08:00 -0700 | [diff] [blame] | 82 | test_expect_success 'blame with --contents' ' |
| 83 | check_count --contents=file A 2 |
| 84 | ' |
| 85 | |
| 86 | test_expect_success 'blame with --contents changed' ' |
| 87 | echo "1A quick brown fox jumps over the" >contents && |
| 88 | echo "another lazy dog" >>contents && |
Jacob Keller | 603d0fd | 2023-04-24 12:35:08 -0700 | [diff] [blame] | 89 | check_count --contents=contents A 1 "External file (--contents)" 1 |
Jacob Keller | 1a3119e | 2023-03-24 10:08:00 -0700 | [diff] [blame] | 90 | ' |
| 91 | |
SZEDER Gábor | a544fb0 | 2019-04-08 01:43:27 +0200 | [diff] [blame] | 92 | test_expect_success 'blame in a bare repo without starting commit' ' |
| 93 | git clone --bare . bare.git && |
| 94 | ( |
| 95 | cd bare.git && |
| 96 | check_count A 2 |
| 97 | ) |
| 98 | ' |
| 99 | |
Jeff King | 7cb5f7c | 2015-11-17 18:22:37 -0500 | [diff] [blame] | 100 | test_expect_success 'blame by tag objects' ' |
| 101 | git tag -m "test tag" testTag && |
| 102 | git tag -m "test tag #2" testTag2 testTag && |
| 103 | check_count -h testTag A 2 && |
| 104 | check_count -h testTag2 A 2 |
| 105 | ' |
| 106 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 107 | test_expect_success 'setup B lines' ' |
| 108 | echo "2A quick brown fox jumps over the" >>file && |
| 109 | echo "lazy dog" >>file && |
| 110 | GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \ |
| 111 | git commit -a -m "Second." |
| 112 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 113 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 114 | test_expect_success 'blame 2 authors' ' |
| 115 | check_count A 2 B 2 |
| 116 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 117 | |
Jacob Keller | 1a3119e | 2023-03-24 10:08:00 -0700 | [diff] [blame] | 118 | test_expect_success 'blame with --contents and revision' ' |
Jacob Keller | 603d0fd | 2023-04-24 12:35:08 -0700 | [diff] [blame] | 119 | check_count -h testTag --contents=file A 2 "External file (--contents)" 2 |
Jacob Keller | 1a3119e | 2023-03-24 10:08:00 -0700 | [diff] [blame] | 120 | ' |
| 121 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 122 | test_expect_success 'setup B1 lines (branch1)' ' |
Johannes Schindelin | 747f6c6 | 2020-11-18 23:44:41 +0000 | [diff] [blame] | 123 | git checkout -b branch1 main && |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 124 | echo "3A slow green fox jumps into the" >>file && |
| 125 | echo "well." >>file && |
| 126 | GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" \ |
| 127 | git commit -a -m "Branch1-1" |
| 128 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 129 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 130 | test_expect_success 'blame 2 authors + 1 branch1 author' ' |
| 131 | check_count A 2 B 2 B1 2 |
| 132 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 133 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 134 | test_expect_success 'setup B2 lines (branch2)' ' |
Johannes Schindelin | 747f6c6 | 2020-11-18 23:44:41 +0000 | [diff] [blame] | 135 | git checkout -b branch2 main && |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 136 | sed -e "s/2A quick brown/4A quick brown lazy dog/" <file >file.new && |
| 137 | mv file.new file && |
| 138 | GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" \ |
| 139 | git commit -a -m "Branch2-1" |
| 140 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 141 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 142 | test_expect_success 'blame 2 authors + 1 branch2 author' ' |
| 143 | check_count A 2 B 1 B2 1 |
| 144 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 145 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 146 | test_expect_success 'merge branch1 & branch2' ' |
Felipe Contreras | 501a75a | 2013-10-31 03:25:33 -0600 | [diff] [blame] | 147 | git merge branch1 |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 148 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 149 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 150 | test_expect_success 'blame 2 authors + 2 merged-in authors' ' |
| 151 | check_count A 2 B 1 B1 2 B2 1 |
| 152 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 153 | |
Jeff King | 95a4fb0 | 2015-09-15 06:05:39 -0400 | [diff] [blame] | 154 | test_expect_success 'blame --first-parent blames merge for branch1' ' |
| 155 | check_count --first-parent A 2 B 1 "A U Thor" 2 B2 1 |
| 156 | ' |
| 157 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 158 | test_expect_success 'blame ancestor' ' |
Johannes Schindelin | 747f6c6 | 2020-11-18 23:44:41 +0000 | [diff] [blame] | 159 | check_count -h main A 2 B 2 |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 160 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 161 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 162 | test_expect_success 'blame great-ancestor' ' |
Johannes Schindelin | 747f6c6 | 2020-11-18 23:44:41 +0000 | [diff] [blame] | 163 | check_count -h main^ A 2 |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 164 | ' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 165 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 166 | test_expect_success 'setup evil merge' ' |
| 167 | echo "evil merge." >>file && |
| 168 | git commit -a --amend |
| 169 | ' |
Junio C Hamano | ce5b6e7 | 2006-03-05 22:37:15 -0800 | [diff] [blame] | 170 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 171 | test_expect_success 'blame evil merge' ' |
| 172 | check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 |
| 173 | ' |
Junio C Hamano | ce5b6e7 | 2006-03-05 22:37:15 -0800 | [diff] [blame] | 174 | |
Johannes Schindelin | e228c17 | 2013-12-27 21:49:57 +0100 | [diff] [blame] | 175 | test_expect_success 'blame huge graft' ' |
| 176 | test_when_finished "git checkout branch2" && |
Ævar Arnfjörð Bjarmason | 93e02b6 | 2022-06-03 13:15:05 +0200 | [diff] [blame] | 177 | test_when_finished "rm -rf .git/info" && |
Johannes Schindelin | e228c17 | 2013-12-27 21:49:57 +0100 | [diff] [blame] | 178 | graft= && |
| 179 | for i in 0 1 2 |
| 180 | do |
| 181 | for j in 0 1 2 3 4 5 6 7 8 9 |
| 182 | do |
| 183 | git checkout --orphan "$i$j" && |
| 184 | printf "%s\n" "$i" "$j" >file && |
| 185 | test_tick && |
| 186 | GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \ |
| 187 | git commit -a -m "$i$j" && |
| 188 | commit=$(git rev-parse --verify HEAD) && |
Eric Sunshine | 0c51d6b | 2021-12-09 00:11:15 -0500 | [diff] [blame] | 189 | graft="$graft$commit " || return 1 |
Johannes Schindelin | e228c17 | 2013-12-27 21:49:57 +0100 | [diff] [blame] | 190 | done |
| 191 | done && |
Ævar Arnfjörð Bjarmason | 93e02b6 | 2022-06-03 13:15:05 +0200 | [diff] [blame] | 192 | mkdir .git/info && |
Johannes Schindelin | e228c17 | 2013-12-27 21:49:57 +0100 | [diff] [blame] | 193 | printf "%s " $graft >.git/info/grafts && |
| 194 | check_count -h 00 01 1 10 1 |
| 195 | ' |
| 196 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 197 | test_expect_success 'setup incomplete line' ' |
| 198 | echo "incomplete" | tr -d "\\012" >>file && |
| 199 | GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \ |
| 200 | git commit -a -m "Incomplete" |
| 201 | ' |
Junio C Hamano | 1242642 | 2006-03-06 00:41:17 -0800 | [diff] [blame] | 202 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 203 | test_expect_success 'blame incomplete line' ' |
| 204 | check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1 |
| 205 | ' |
Junio C Hamano | 1242642 | 2006-03-06 00:41:17 -0800 | [diff] [blame] | 206 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 207 | test_expect_success 'setup edits' ' |
| 208 | mv file file.orig && |
| 209 | { |
| 210 | cat file.orig && |
| 211 | echo |
| 212 | } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" >file && |
| 213 | echo "incomplete" | tr -d "\\012" >>file && |
| 214 | GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" \ |
| 215 | git commit -a -m "edit" |
| 216 | ' |
Junio C Hamano | 1242642 | 2006-03-06 00:41:17 -0800 | [diff] [blame] | 217 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 218 | test_expect_success 'blame edits' ' |
| 219 | check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 |
| 220 | ' |
Josh Stone | 9b01f00 | 2011-04-21 15:07:36 -0700 | [diff] [blame] | 221 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 222 | test_expect_success 'setup obfuscated email' ' |
| 223 | echo "No robots allowed" >file.new && |
| 224 | cat file >>file.new && |
| 225 | mv file.new file && |
| 226 | GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \ |
| 227 | git commit -a -m "norobots" |
| 228 | ' |
Josh Stone | 9b01f00 | 2011-04-21 15:07:36 -0700 | [diff] [blame] | 229 | |
Eric Sunshine | e37f39c | 2013-07-17 17:25:28 -0400 | [diff] [blame] | 230 | test_expect_success 'blame obfuscated email' ' |
| 231 | check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 |
| 232 | ' |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 233 | |
| 234 | test_expect_success 'blame -L 1 (all)' ' |
| 235 | check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 |
| 236 | ' |
| 237 | |
| 238 | test_expect_success 'blame -L , (all)' ' |
| 239 | check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 |
| 240 | ' |
| 241 | |
| 242 | test_expect_success 'blame -L X (X to end)' ' |
| 243 | check_count -L5 B1 1 C 1 D 1 "A U Thor" 1 |
| 244 | ' |
| 245 | |
| 246 | test_expect_success 'blame -L X, (X to end)' ' |
| 247 | check_count -L5, B1 1 C 1 D 1 "A U Thor" 1 |
| 248 | ' |
| 249 | |
| 250 | test_expect_success 'blame -L ,Y (up to Y)' ' |
| 251 | check_count -L,3 A 1 B2 1 E 1 |
| 252 | ' |
| 253 | |
| 254 | test_expect_success 'blame -L X,X' ' |
| 255 | check_count -L3,3 B2 1 |
| 256 | ' |
| 257 | |
| 258 | test_expect_success 'blame -L X,Y' ' |
| 259 | check_count -L3,6 B 1 B1 1 B2 1 D 1 |
| 260 | ' |
| 261 | |
| 262 | test_expect_success 'blame -L Y,X (undocumented)' ' |
| 263 | check_count -L6,3 B 1 B1 1 B2 1 D 1 |
| 264 | ' |
| 265 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 266 | test_expect_success 'blame -L -X' ' |
Eric Sunshine | 9527604 | 2013-08-06 09:59:48 -0400 | [diff] [blame] | 267 | test_must_fail $PROG -L-1 file |
| 268 | ' |
| 269 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 270 | test_expect_success 'blame -L 0' ' |
Eric Sunshine | 9527604 | 2013-08-06 09:59:48 -0400 | [diff] [blame] | 271 | test_must_fail $PROG -L0 file |
| 272 | ' |
| 273 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 274 | test_expect_success 'blame -L ,0' ' |
Eric Sunshine | 9527604 | 2013-08-06 09:59:48 -0400 | [diff] [blame] | 275 | test_must_fail $PROG -L,0 file |
| 276 | ' |
| 277 | |
Eric Sunshine | 5d57cac | 2013-07-31 04:15:45 -0400 | [diff] [blame] | 278 | test_expect_success 'blame -L ,+0' ' |
Eric Sunshine | 82cd7e5 | 2013-07-31 04:15:44 -0400 | [diff] [blame] | 279 | test_must_fail $PROG -L,+0 file |
| 280 | ' |
| 281 | |
Eric Sunshine | abba353 | 2013-07-31 04:15:43 -0400 | [diff] [blame] | 282 | test_expect_success 'blame -L X,+0' ' |
Eric Sunshine | dedb912 | 2013-07-31 04:15:42 -0400 | [diff] [blame] | 283 | test_must_fail $PROG -L1,+0 file |
| 284 | ' |
| 285 | |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 286 | test_expect_success 'blame -L X,+1' ' |
| 287 | check_count -L3,+1 B2 1 |
| 288 | ' |
| 289 | |
| 290 | test_expect_success 'blame -L X,+N' ' |
| 291 | check_count -L3,+4 B 1 B1 1 B2 1 D 1 |
| 292 | ' |
| 293 | |
Eric Sunshine | 5d57cac | 2013-07-31 04:15:45 -0400 | [diff] [blame] | 294 | test_expect_success 'blame -L ,-0' ' |
Eric Sunshine | 82cd7e5 | 2013-07-31 04:15:44 -0400 | [diff] [blame] | 295 | test_must_fail $PROG -L,-0 file |
| 296 | ' |
| 297 | |
Eric Sunshine | abba353 | 2013-07-31 04:15:43 -0400 | [diff] [blame] | 298 | test_expect_success 'blame -L X,-0' ' |
Eric Sunshine | dedb912 | 2013-07-31 04:15:42 -0400 | [diff] [blame] | 299 | test_must_fail $PROG -L1,-0 file |
| 300 | ' |
| 301 | |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 302 | test_expect_success 'blame -L X,-1' ' |
| 303 | check_count -L3,-1 B2 1 |
| 304 | ' |
| 305 | |
| 306 | test_expect_success 'blame -L X,-N' ' |
| 307 | check_count -L6,-4 B 1 B1 1 B2 1 D 1 |
| 308 | ' |
| 309 | |
| 310 | test_expect_success 'blame -L /RE/ (RE to end)' ' |
| 311 | check_count -L/evil/ C 1 "A U Thor" 1 |
| 312 | ' |
| 313 | |
| 314 | test_expect_success 'blame -L /RE/,/RE2/' ' |
| 315 | check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1 |
| 316 | ' |
| 317 | |
| 318 | test_expect_success 'blame -L X,/RE/' ' |
| 319 | check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1 |
| 320 | ' |
| 321 | |
| 322 | test_expect_success 'blame -L /RE/,Y' ' |
| 323 | check_count -L/99/,7 B1 1 D 1 "A U Thor" 1 |
| 324 | ' |
| 325 | |
| 326 | test_expect_success 'blame -L /RE/,+N' ' |
| 327 | check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1 |
| 328 | ' |
| 329 | |
| 330 | test_expect_success 'blame -L /RE/,-N' ' |
| 331 | check_count -L/99/,-3 B 1 B2 1 D 1 |
| 332 | ' |
| 333 | |
Eric Sunshine | 580b4f3 | 2013-07-31 04:15:36 -0400 | [diff] [blame] | 334 | # 'file' ends with an incomplete line, so 'wc' reports one fewer lines than |
| 335 | # git-blame sees, hence the last line is actually $(wc...)+1. |
| 336 | test_expect_success 'blame -L X (X == nlines)' ' |
| 337 | n=$(expr $(wc -l <file) + 1) && |
| 338 | check_count -L$n C 1 |
| 339 | ' |
| 340 | |
Eric Sunshine | 164a9cf | 2013-07-31 04:15:38 -0400 | [diff] [blame] | 341 | test_expect_success 'blame -L X (X == nlines + 1)' ' |
Eric Sunshine | 580b4f3 | 2013-07-31 04:15:36 -0400 | [diff] [blame] | 342 | n=$(expr $(wc -l <file) + 2) && |
| 343 | test_must_fail $PROG -L$n file |
| 344 | ' |
| 345 | |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 346 | test_expect_success 'blame -L X (X > nlines)' ' |
| 347 | test_must_fail $PROG -L12345 file |
| 348 | ' |
| 349 | |
Eric Sunshine | 580b4f3 | 2013-07-31 04:15:36 -0400 | [diff] [blame] | 350 | test_expect_success 'blame -L ,Y (Y == nlines)' ' |
| 351 | n=$(expr $(wc -l <file) + 1) && |
| 352 | check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 |
| 353 | ' |
| 354 | |
| 355 | test_expect_success 'blame -L ,Y (Y == nlines + 1)' ' |
| 356 | n=$(expr $(wc -l <file) + 2) && |
Isabella Stephens | 96cfa94 | 2018-06-15 16:29:27 +1000 | [diff] [blame] | 357 | check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 |
Eric Sunshine | 580b4f3 | 2013-07-31 04:15:36 -0400 | [diff] [blame] | 358 | ' |
| 359 | |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 360 | test_expect_success 'blame -L ,Y (Y > nlines)' ' |
Isabella Stephens | 96cfa94 | 2018-06-15 16:29:27 +1000 | [diff] [blame] | 361 | check_count -L,12345 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 362 | ' |
| 363 | |
Eric Sunshine | 91b5494 | 2013-08-06 09:59:39 -0400 | [diff] [blame] | 364 | test_expect_success 'blame -L multiple (disjoint)' ' |
| 365 | check_count -L2,3 -L6,7 A 1 B1 1 B2 1 "A U Thor" 1 |
| 366 | ' |
| 367 | |
| 368 | test_expect_success 'blame -L multiple (disjoint: unordered)' ' |
| 369 | check_count -L6,7 -L2,3 A 1 B1 1 B2 1 "A U Thor" 1 |
| 370 | ' |
| 371 | |
| 372 | test_expect_success 'blame -L multiple (adjacent)' ' |
| 373 | check_count -L2,3 -L4,5 A 1 B 1 B2 1 D 1 |
| 374 | ' |
| 375 | |
| 376 | test_expect_success 'blame -L multiple (adjacent: unordered)' ' |
| 377 | check_count -L4,5 -L2,3 A 1 B 1 B2 1 D 1 |
| 378 | ' |
| 379 | |
| 380 | test_expect_success 'blame -L multiple (overlapping)' ' |
| 381 | check_count -L2,4 -L3,5 A 1 B 1 B2 1 D 1 |
| 382 | ' |
| 383 | |
| 384 | test_expect_success 'blame -L multiple (overlapping: unordered)' ' |
| 385 | check_count -L3,5 -L2,4 A 1 B 1 B2 1 D 1 |
| 386 | ' |
| 387 | |
| 388 | test_expect_success 'blame -L multiple (superset/subset)' ' |
| 389 | check_count -L2,8 -L3,5 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1 |
| 390 | ' |
| 391 | |
| 392 | test_expect_success 'blame -L multiple (superset/subset: unordered)' ' |
| 393 | check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1 |
| 394 | ' |
| 395 | |
Eric Sunshine | 52f4d12 | 2013-08-06 09:59:42 -0400 | [diff] [blame] | 396 | test_expect_success 'blame -L /RE/ (relative)' ' |
| 397 | check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1 |
| 398 | ' |
| 399 | |
| 400 | test_expect_success 'blame -L /RE/ (relative: no preceding range)' ' |
| 401 | check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1 |
| 402 | ' |
| 403 | |
| 404 | test_expect_success 'blame -L /RE/ (relative: adjacent)' ' |
| 405 | check_count -L1,1 -L/dog/,+1 A 1 E 1 |
| 406 | ' |
| 407 | |
| 408 | test_expect_success 'blame -L /RE/ (relative: not found)' ' |
| 409 | test_must_fail $PROG -L4,4 -L/dog/ file |
| 410 | ' |
| 411 | |
| 412 | test_expect_success 'blame -L /RE/ (relative: end-of-file)' ' |
| 413 | test_must_fail $PROG -L, -L/$/ file |
| 414 | ' |
| 415 | |
Eric Sunshine | a6ac5f9 | 2013-08-06 09:59:45 -0400 | [diff] [blame] | 416 | test_expect_success 'blame -L ^/RE/ (absolute)' ' |
| 417 | check_count -L3,3 -L^/dog/,+2 A 1 B2 1 |
| 418 | ' |
| 419 | |
| 420 | test_expect_success 'blame -L ^/RE/ (absolute: no preceding range)' ' |
| 421 | check_count -L^/dog/,+2 A 1 B2 1 |
| 422 | ' |
| 423 | |
| 424 | test_expect_success 'blame -L ^/RE/ (absolute: not found)' ' |
| 425 | test_must_fail $PROG -L4,4 -L^/tambourine/ file |
| 426 | ' |
| 427 | |
| 428 | test_expect_success 'blame -L ^/RE/ (absolute: end-of-file)' ' |
| 429 | n=$(expr $(wc -l <file) + 1) && |
| 430 | check_count -L$n -L^/$/,+2 A 1 C 1 E 1 |
| 431 | ' |
| 432 | |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 433 | test_expect_success 'setup -L :regex' ' |
| 434 | tr Q "\\t" >hello.c <<-\EOF && |
| 435 | int main(int argc, const char *argv[]) |
| 436 | { |
| 437 | Qputs("hello"); |
| 438 | } |
| 439 | EOF |
| 440 | git add hello.c && |
| 441 | GIT_AUTHOR_NAME="F" GIT_AUTHOR_EMAIL="F@test.git" \ |
| 442 | git commit -m "hello" && |
| 443 | |
| 444 | mv hello.c hello.orig && |
René Scharfe | 3a4fc21 | 2013-08-05 17:21:17 +0200 | [diff] [blame] | 445 | sed -e "/}/ {x; s/$/Qputs(\"goodbye\");/; G;}" <hello.orig | |
| 446 | tr Q "\\t" >hello.c && |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 447 | GIT_AUTHOR_NAME="G" GIT_AUTHOR_EMAIL="G@test.git" \ |
| 448 | git commit -a -m "goodbye" && |
| 449 | |
| 450 | mv hello.c hello.orig && |
| 451 | echo "#include <stdio.h>" >hello.c && |
| 452 | cat hello.orig >>hello.c && |
Jeff King | 99094a7 | 2015-03-20 06:07:15 -0400 | [diff] [blame] | 453 | tr Q "\\t" >>hello.c <<-\EOF && |
Eric Sunshine | 5a9830c | 2013-07-17 17:25:30 -0400 | [diff] [blame] | 454 | void mail() |
| 455 | { |
| 456 | Qputs("mail"); |
| 457 | } |
| 458 | EOF |
| 459 | GIT_AUTHOR_NAME="H" GIT_AUTHOR_EMAIL="H@test.git" \ |
| 460 | git commit -a -m "mail" |
| 461 | ' |
| 462 | |
| 463 | test_expect_success 'blame -L :literal' ' |
| 464 | check_count -f hello.c -L:main F 4 G 1 |
| 465 | ' |
| 466 | |
| 467 | test_expect_success 'blame -L :regex' ' |
| 468 | check_count -f hello.c "-L:m[a-z][a-z]l" H 4 |
| 469 | ' |
| 470 | |
| 471 | test_expect_success 'blame -L :nomatch' ' |
| 472 | test_must_fail $PROG -L:nomatch hello.c |
| 473 | ' |
| 474 | |
Eric Sunshine | 1ce761a | 2013-08-06 09:59:46 -0400 | [diff] [blame] | 475 | test_expect_success 'blame -L :RE (relative)' ' |
| 476 | check_count -f hello.c -L3,3 -L:ma.. F 1 H 4 |
| 477 | ' |
| 478 | |
| 479 | test_expect_success 'blame -L :RE (relative: no preceding range)' ' |
| 480 | check_count -f hello.c -L:ma.. F 4 G 1 |
| 481 | ' |
| 482 | |
| 483 | test_expect_success 'blame -L :RE (relative: not found)' ' |
| 484 | test_must_fail $PROG -L3,3 -L:tambourine hello.c |
| 485 | ' |
| 486 | |
| 487 | test_expect_success 'blame -L :RE (relative: end-of-file)' ' |
| 488 | test_must_fail $PROG -L, -L:main hello.c |
| 489 | ' |
| 490 | |
Eric Sunshine | 215e76c | 2013-08-06 09:59:47 -0400 | [diff] [blame] | 491 | test_expect_success 'blame -L ^:RE (absolute)' ' |
| 492 | check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1 |
| 493 | ' |
| 494 | |
| 495 | test_expect_success 'blame -L ^:RE (absolute: no preceding range)' ' |
| 496 | check_count -f hello.c -L^:ma.. F 4 G 1 |
| 497 | ' |
| 498 | |
| 499 | test_expect_success 'blame -L ^:RE (absolute: not found)' ' |
| 500 | test_must_fail $PROG -L4,4 -L^:tambourine hello.c |
| 501 | ' |
| 502 | |
| 503 | test_expect_success 'blame -L ^:RE (absolute: end-of-file)' ' |
| 504 | n=$(printf "%d" $(wc -l <hello.c)) && |
| 505 | check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1 |
| 506 | ' |
| 507 | |
Ævar Arnfjörð Bjarmason | f08b401 | 2021-04-08 17:04:24 +0200 | [diff] [blame] | 508 | test_expect_success 'blame -L :funcname with userdiff driver' ' |
| 509 | cat >file.template <<-\EOF && |
| 510 | DO NOT MATCH THIS LINE |
Ævar Arnfjörð Bjarmason | b269441 | 2021-04-08 17:04:23 +0200 | [diff] [blame] | 511 | function RIGHT(a, b) result(c) |
Ævar Arnfjörð Bjarmason | f08b401 | 2021-04-08 17:04:24 +0200 | [diff] [blame] | 512 | AS THE DEFAULT DRIVER WOULD |
Ævar Arnfjörð Bjarmason | b269441 | 2021-04-08 17:04:23 +0200 | [diff] [blame] | 513 | |
| 514 | integer, intent(in) :: ChangeMe |
Ævar Arnfjörð Bjarmason | b269441 | 2021-04-08 17:04:23 +0200 | [diff] [blame] | 515 | EOF |
Philippe Blain | 9466e38 | 2020-11-01 17:28:45 +0000 | [diff] [blame] | 516 | |
Ævar Arnfjörð Bjarmason | f08b401 | 2021-04-08 17:04:24 +0200 | [diff] [blame] | 517 | fortran_file=file.f03 && |
| 518 | test_when_finished "rm .gitattributes" && |
| 519 | echo "$fortran_file diff=fortran" >.gitattributes && |
| 520 | |
| 521 | test_commit --author "A <A@test.git>" \ |
| 522 | "add" "$fortran_file" \ |
| 523 | "$(cat file.template)" && |
| 524 | test_commit --author "B <B@test.git>" \ |
| 525 | "change" "$fortran_file" \ |
| 526 | "$(cat file.template | sed -e s/ChangeMe/IWasChanged/)" && |
| 527 | check_count -f "$fortran_file" -L:RIGHT A 3 B 1 |
Philippe Blain | 9466e38 | 2020-11-01 17:28:45 +0000 | [diff] [blame] | 528 | ' |
| 529 | |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 530 | test_expect_success 'setup incremental' ' |
| 531 | ( |
| 532 | GIT_AUTHOR_NAME=I && |
| 533 | export GIT_AUTHOR_NAME && |
| 534 | GIT_AUTHOR_EMAIL=I@test.git && |
| 535 | export GIT_AUTHOR_EMAIL && |
| 536 | >incremental && |
| 537 | git add incremental && |
| 538 | git commit -m "step 0" && |
| 539 | printf "partial" >>incremental && |
| 540 | git commit -a -m "step 0.5" && |
| 541 | echo >>incremental && |
| 542 | git commit -a -m "step 1" |
| 543 | ) |
| 544 | ' |
| 545 | |
| 546 | test_expect_success 'blame empty' ' |
| 547 | check_count -h HEAD^^ -f incremental |
| 548 | ' |
| 549 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 550 | test_expect_success 'blame -L 0 empty' ' |
| 551 | test_must_fail $PROG -L0 incremental HEAD^^ |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 552 | ' |
| 553 | |
Eric Sunshine | 164a9cf | 2013-07-31 04:15:38 -0400 | [diff] [blame] | 554 | test_expect_success 'blame -L 1 empty' ' |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 555 | test_must_fail $PROG -L1 incremental HEAD^^ |
| 556 | ' |
| 557 | |
| 558 | test_expect_success 'blame -L 2 empty' ' |
| 559 | test_must_fail $PROG -L2 incremental HEAD^^ |
| 560 | ' |
| 561 | |
| 562 | test_expect_success 'blame half' ' |
| 563 | check_count -h HEAD^ -f incremental I 1 |
| 564 | ' |
| 565 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 566 | test_expect_success 'blame -L 0 half' ' |
| 567 | test_must_fail $PROG -L0 incremental HEAD^ |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 568 | ' |
| 569 | |
| 570 | test_expect_success 'blame -L 1 half' ' |
| 571 | check_count -h HEAD^ -f incremental -L1 I 1 |
| 572 | ' |
| 573 | |
Eric Sunshine | 164a9cf | 2013-07-31 04:15:38 -0400 | [diff] [blame] | 574 | test_expect_success 'blame -L 2 half' ' |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 575 | test_must_fail $PROG -L2 incremental HEAD^ |
| 576 | ' |
| 577 | |
| 578 | test_expect_success 'blame -L 3 half' ' |
| 579 | test_must_fail $PROG -L3 incremental HEAD^ |
| 580 | ' |
| 581 | |
| 582 | test_expect_success 'blame full' ' |
| 583 | check_count -f incremental I 1 |
| 584 | ' |
| 585 | |
Eric Sunshine | 5ce922a | 2013-08-06 09:59:49 -0400 | [diff] [blame] | 586 | test_expect_success 'blame -L 0 full' ' |
| 587 | test_must_fail $PROG -L0 incremental |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 588 | ' |
| 589 | |
| 590 | test_expect_success 'blame -L 1 full' ' |
| 591 | check_count -f incremental -L1 I 1 |
| 592 | ' |
| 593 | |
Eric Sunshine | 164a9cf | 2013-07-31 04:15:38 -0400 | [diff] [blame] | 594 | test_expect_success 'blame -L 2 full' ' |
Eric Sunshine | a8fa8ec | 2013-07-31 04:15:37 -0400 | [diff] [blame] | 595 | test_must_fail $PROG -L2 incremental |
| 596 | ' |
| 597 | |
| 598 | test_expect_success 'blame -L 3 full' ' |
| 599 | test_must_fail $PROG -L3 incremental |
| 600 | ' |
| 601 | |
Eric Sunshine | f350cf9 | 2013-07-31 04:15:35 -0400 | [diff] [blame] | 602 | test_expect_success 'blame -L' ' |
| 603 | test_must_fail $PROG -L file |
| 604 | ' |
| 605 | |
| 606 | test_expect_success 'blame -L X,+' ' |
| 607 | test_must_fail $PROG -L1,+ file |
| 608 | ' |
| 609 | |
| 610 | test_expect_success 'blame -L X,-' ' |
| 611 | test_must_fail $PROG -L1,- file |
| 612 | ' |
| 613 | |
| 614 | test_expect_success 'blame -L X (non-numeric X)' ' |
| 615 | test_must_fail $PROG -LX file |
| 616 | ' |
| 617 | |
| 618 | test_expect_success 'blame -L X,Y (non-numeric Y)' ' |
| 619 | test_must_fail $PROG -L1,Y file |
| 620 | ' |
| 621 | |
| 622 | test_expect_success 'blame -L X,+N (non-numeric N)' ' |
| 623 | test_must_fail $PROG -L1,+N file |
| 624 | ' |
| 625 | |
| 626 | test_expect_success 'blame -L X,-N (non-numeric N)' ' |
Eric Sunshine | 03e15fc | 2013-07-17 17:25:29 -0400 | [diff] [blame] | 627 | test_must_fail $PROG -L1,-N file |
| 628 | ' |
Eric Sunshine | a6ac5f9 | 2013-08-06 09:59:45 -0400 | [diff] [blame] | 629 | |
| 630 | test_expect_success 'blame -L ,^/RE/' ' |
| 631 | test_must_fail $PROG -L1,^/99/ file |
| 632 | ' |
Edmundo Carmona Antoranz | e5f5d7d | 2022-04-06 20:13:20 +0200 | [diff] [blame] | 633 | |
| 634 | test_expect_success 'blame progress on a full file' ' |
| 635 | cat >expect <<-\EOF && |
| 636 | Blaming lines: 100% (10/10), done. |
| 637 | EOF |
| 638 | |
| 639 | GIT_PROGRESS_DELAY=0 \ |
| 640 | git blame --progress hello.c 2>stderr && |
| 641 | |
| 642 | get_progress_result <stderr >actual && |
| 643 | test_cmp expect actual |
| 644 | ' |
| 645 | |
| 646 | test_expect_success 'blame progress on a single range' ' |
| 647 | cat >expect <<-\EOF && |
| 648 | Blaming lines: 100% (4/4), done. |
| 649 | EOF |
| 650 | |
| 651 | GIT_PROGRESS_DELAY=0 \ |
| 652 | git blame --progress -L 3,6 hello.c 2>stderr && |
| 653 | |
| 654 | get_progress_result <stderr >actual && |
| 655 | test_cmp expect actual |
| 656 | ' |
| 657 | |
| 658 | test_expect_success 'blame progress on multiple ranges' ' |
| 659 | cat >expect <<-\EOF && |
| 660 | Blaming lines: 100% (7/7), done. |
| 661 | EOF |
| 662 | |
| 663 | GIT_PROGRESS_DELAY=0 \ |
| 664 | git blame --progress -L 3,6 -L 8,10 hello.c 2>stderr && |
| 665 | |
| 666 | get_progress_result <stderr >actual && |
| 667 | test_cmp expect actual |
| 668 | ' |