Junio C Hamano | c2a0636 | 2007-05-05 22:36:19 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git blame corner cases' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/' |
| 7 | |
| 8 | test_expect_success setup ' |
| 9 | |
| 10 | echo A A A A A >one && |
| 11 | echo B B B B B >two && |
| 12 | echo C C C C C >tres && |
| 13 | echo ABC >mouse && |
René Scharfe | 00fb3d2 | 2010-03-13 11:25:12 +0100 | [diff] [blame] | 14 | for i in 1 2 3 4 5 6 7 8 9 |
| 15 | do |
| 16 | echo $i |
| 17 | done >nine_lines && |
| 18 | for i in 1 2 3 4 5 6 7 8 9 a |
| 19 | do |
| 20 | echo $i |
| 21 | done >ten_lines && |
| 22 | git add one two tres mouse nine_lines ten_lines && |
Junio C Hamano | c2a0636 | 2007-05-05 22:36:19 -0700 | [diff] [blame] | 23 | test_tick && |
| 24 | GIT_AUTHOR_NAME=Initial git commit -m Initial && |
| 25 | |
| 26 | cat one >uno && |
| 27 | mv two dos && |
| 28 | cat one >>tres && |
Jeff King | 99094a7 | 2015-03-20 06:07:15 -0400 | [diff] [blame] | 29 | echo DEF >>mouse && |
Junio C Hamano | c2a0636 | 2007-05-05 22:36:19 -0700 | [diff] [blame] | 30 | git add uno dos tres mouse && |
| 31 | test_tick && |
| 32 | GIT_AUTHOR_NAME=Second git commit -a -m Second && |
| 33 | |
| 34 | echo GHIJK >>mouse && |
| 35 | git add mouse && |
| 36 | test_tick && |
| 37 | GIT_AUTHOR_NAME=Third git commit -m Third && |
| 38 | |
| 39 | cat mouse >cow && |
| 40 | git add cow && |
| 41 | test_tick && |
| 42 | GIT_AUTHOR_NAME=Fourth git commit -m Fourth && |
| 43 | |
Mike Hommey | c66b470 | 2016-07-16 08:23:46 +0900 | [diff] [blame] | 44 | cat >cow <<-\EOF && |
| 45 | ABC |
| 46 | DEF |
| 47 | XXXX |
| 48 | GHIJK |
| 49 | EOF |
Junio C Hamano | c2a0636 | 2007-05-05 22:36:19 -0700 | [diff] [blame] | 50 | git add cow && |
| 51 | test_tick && |
| 52 | GIT_AUTHOR_NAME=Fifth git commit -m Fifth |
| 53 | ' |
| 54 | |
| 55 | test_expect_success 'straight copy without -C' ' |
| 56 | |
| 57 | git blame uno | grep Second |
| 58 | |
| 59 | ' |
| 60 | |
| 61 | test_expect_success 'straight move without -C' ' |
| 62 | |
| 63 | git blame dos | grep Initial |
| 64 | |
| 65 | ' |
| 66 | |
| 67 | test_expect_success 'straight copy with -C' ' |
| 68 | |
| 69 | git blame -C1 uno | grep Second |
| 70 | |
| 71 | ' |
| 72 | |
| 73 | test_expect_success 'straight move with -C' ' |
| 74 | |
| 75 | git blame -C1 dos | grep Initial |
| 76 | |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'straight copy with -C -C' ' |
| 80 | |
| 81 | git blame -C -C1 uno | grep Initial |
| 82 | |
| 83 | ' |
| 84 | |
| 85 | test_expect_success 'straight move with -C -C' ' |
| 86 | |
| 87 | git blame -C -C1 dos | grep Initial |
| 88 | |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'append without -C' ' |
| 92 | |
| 93 | git blame -L2 tres | grep Second |
| 94 | |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'append with -C' ' |
| 98 | |
| 99 | git blame -L2 -C1 tres | grep Second |
| 100 | |
| 101 | ' |
| 102 | |
| 103 | test_expect_success 'append with -C -C' ' |
| 104 | |
| 105 | git blame -L2 -C -C1 tres | grep Second |
| 106 | |
| 107 | ' |
| 108 | |
| 109 | test_expect_success 'append with -C -C -C' ' |
| 110 | |
| 111 | git blame -L2 -C -C -C1 tres | grep Initial |
| 112 | |
| 113 | ' |
| 114 | |
| 115 | test_expect_success 'blame wholesale copy' ' |
| 116 | |
| 117 | git blame -f -C -C1 HEAD^ -- cow | sed -e "$pick_fc" >current && |
Mike Hommey | c66b470 | 2016-07-16 08:23:46 +0900 | [diff] [blame] | 118 | cat >expected <<-\EOF && |
| 119 | mouse-Initial |
| 120 | mouse-Second |
| 121 | mouse-Third |
| 122 | EOF |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 123 | test_cmp expected current |
Junio C Hamano | c2a0636 | 2007-05-05 22:36:19 -0700 | [diff] [blame] | 124 | |
| 125 | ' |
| 126 | |
| 127 | test_expect_success 'blame wholesale copy and more' ' |
| 128 | |
| 129 | git blame -f -C -C1 HEAD -- cow | sed -e "$pick_fc" >current && |
Mike Hommey | c66b470 | 2016-07-16 08:23:46 +0900 | [diff] [blame] | 130 | cat >expected <<-\EOF && |
| 131 | mouse-Initial |
| 132 | mouse-Second |
| 133 | cow-Fifth |
| 134 | mouse-Third |
| 135 | EOF |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 136 | test_cmp expected current |
Junio C Hamano | c2a0636 | 2007-05-05 22:36:19 -0700 | [diff] [blame] | 137 | |
| 138 | ' |
| 139 | |
Mike Hommey | 3b75ee9 | 2016-07-16 08:23:45 +0900 | [diff] [blame] | 140 | test_expect_success 'blame wholesale copy and more in the index' ' |
| 141 | |
| 142 | cat >horse <<-\EOF && |
| 143 | ABC |
| 144 | DEF |
| 145 | XXXX |
| 146 | YYYY |
| 147 | GHIJK |
| 148 | EOF |
| 149 | git add horse && |
| 150 | test_when_finished "git rm -f horse" && |
| 151 | git blame -f -C -C1 -- horse | sed -e "$pick_fc" >current && |
| 152 | cat >expected <<-\EOF && |
| 153 | mouse-Initial |
| 154 | mouse-Second |
| 155 | cow-Fifth |
| 156 | horse-Not |
| 157 | mouse-Third |
| 158 | EOF |
| 159 | test_cmp expected current |
| 160 | |
| 161 | ' |
| 162 | |
| 163 | test_expect_success 'blame during cherry-pick with file rename conflict' ' |
| 164 | |
| 165 | test_when_finished "git reset --hard && git checkout master" && |
| 166 | git checkout HEAD~3 && |
| 167 | echo MOUSE >> mouse && |
| 168 | git mv mouse rodent && |
| 169 | git add rodent && |
| 170 | GIT_AUTHOR_NAME=Rodent git commit -m "rodent" && |
| 171 | git checkout --detach master && |
| 172 | (git cherry-pick HEAD@{1} || test $? -eq 1) && |
| 173 | git show HEAD@{1}:rodent > rodent && |
| 174 | git add rodent && |
| 175 | git blame -f -C -C1 rodent | sed -e "$pick_fc" >current && |
| 176 | cat current && |
| 177 | cat >expected <<-\EOF && |
| 178 | mouse-Initial |
| 179 | mouse-Second |
| 180 | rodent-Not |
| 181 | EOF |
| 182 | test_cmp expected current |
| 183 | ' |
| 184 | |
Junio C Hamano | a9b2d42 | 2009-06-03 00:43:22 -0700 | [diff] [blame] | 185 | test_expect_success 'blame path that used to be a directory' ' |
| 186 | mkdir path && |
| 187 | echo A A A A A >path/file && |
| 188 | echo B B B B B >path/elif && |
| 189 | git add path && |
| 190 | test_tick && |
| 191 | git commit -m "path was a directory" && |
| 192 | rm -fr path && |
| 193 | echo A A A A A >path && |
| 194 | git add path && |
| 195 | test_tick && |
| 196 | git commit -m "path is a regular file" && |
| 197 | git blame HEAD^.. -- path |
| 198 | ' |
| 199 | |
David Reiss | c8cba79 | 2009-12-22 10:51:41 -0800 | [diff] [blame] | 200 | test_expect_success 'blame to a commit with no author name' ' |
Elia Pinto | 844116d | 2016-01-08 12:06:26 +0100 | [diff] [blame] | 201 | TREE=$(git rev-parse HEAD:) && |
Jeff King | 99094a7 | 2015-03-20 06:07:15 -0400 | [diff] [blame] | 202 | cat >badcommit <<EOF && |
David Reiss | c8cba79 | 2009-12-22 10:51:41 -0800 | [diff] [blame] | 203 | tree $TREE |
| 204 | author <noname> 1234567890 +0000 |
| 205 | committer David Reiss <dreiss@facebook.com> 1234567890 +0000 |
| 206 | |
| 207 | some message |
| 208 | EOF |
Elia Pinto | 844116d | 2016-01-08 12:06:26 +0100 | [diff] [blame] | 209 | COMMIT=$(git hash-object -t commit -w badcommit) && |
David Reiss | c8cba79 | 2009-12-22 10:51:41 -0800 | [diff] [blame] | 210 | git --no-pager blame $COMMIT -- uno >/dev/null |
| 211 | ' |
| 212 | |
Jay Soffian | 92f9e27 | 2010-02-08 22:48:13 -0500 | [diff] [blame] | 213 | test_expect_success 'blame -L with invalid start' ' |
Junio C Hamano | 33f0ea4 | 2010-02-09 10:06:33 -0800 | [diff] [blame] | 214 | test_must_fail git blame -L5 tres 2>errors && |
Vasco Almeida | e3f54bf | 2016-09-15 14:58:58 +0000 | [diff] [blame] | 215 | test_i18ngrep "has only 2 lines" errors |
Jay Soffian | 92f9e27 | 2010-02-08 22:48:13 -0500 | [diff] [blame] | 216 | ' |
| 217 | |
| 218 | test_expect_success 'blame -L with invalid end' ' |
Isabella Stephens | 96cfa94 | 2018-06-15 16:29:27 +1000 | [diff] [blame] | 219 | git blame -L1,5 tres >out && |
| 220 | test_line_count = 2 out |
Jay Soffian | 92f9e27 | 2010-02-08 22:48:13 -0500 | [diff] [blame] | 221 | ' |
| 222 | |
Bo Yang | 25ed341 | 2013-03-28 17:47:30 +0100 | [diff] [blame] | 223 | test_expect_success 'blame parses <end> part of -L' ' |
| 224 | git blame -L1,1 tres >out && |
Isabella Stephens | 96cfa94 | 2018-06-15 16:29:27 +1000 | [diff] [blame] | 225 | test_line_count = 1 out |
| 226 | ' |
| 227 | |
| 228 | test_expect_success 'blame -Ln,-(n+1)' ' |
| 229 | git blame -L3,-4 nine_lines >out && |
| 230 | test_line_count = 3 out |
Bo Yang | 25ed341 | 2013-03-28 17:47:30 +0100 | [diff] [blame] | 231 | ' |
| 232 | |
René Scharfe | 00fb3d2 | 2010-03-13 11:25:12 +0100 | [diff] [blame] | 233 | test_expect_success 'indent of line numbers, nine lines' ' |
| 234 | git blame nine_lines >actual && |
| 235 | test $(grep -c " " actual) = 0 |
| 236 | ' |
| 237 | |
| 238 | test_expect_success 'indent of line numbers, ten lines' ' |
| 239 | git blame ten_lines >actual && |
| 240 | test $(grep -c " " actual) = 9 |
| 241 | ' |
| 242 | |
Torsten Bögershausen | 4bf256d | 2015-05-03 18:38:01 +0200 | [diff] [blame] | 243 | test_expect_success 'setup file with CRLF newlines' ' |
brian m. carlson | 4d4813a | 2014-04-26 23:10:40 +0000 | [diff] [blame] | 244 | git config core.autocrlf false && |
Torsten Bögershausen | 4bf256d | 2015-05-03 18:38:01 +0200 | [diff] [blame] | 245 | printf "testcase\n" >crlffile && |
brian m. carlson | 4d4813a | 2014-04-26 23:10:40 +0000 | [diff] [blame] | 246 | git add crlffile && |
| 247 | git commit -m testcase && |
Torsten Bögershausen | 4bf256d | 2015-05-03 18:38:01 +0200 | [diff] [blame] | 248 | printf "testcase\r\n" >crlffile |
| 249 | ' |
| 250 | |
| 251 | test_expect_success 'blame file with CRLF core.autocrlf true' ' |
| 252 | git config core.autocrlf true && |
| 253 | git blame crlffile >actual && |
| 254 | grep "A U Thor" actual |
| 255 | ' |
| 256 | |
| 257 | test_expect_success 'blame file with CRLF attributes text' ' |
| 258 | git config core.autocrlf false && |
| 259 | echo "crlffile text" >.gitattributes && |
| 260 | git blame crlffile >actual && |
brian m. carlson | 4d4813a | 2014-04-26 23:10:40 +0000 | [diff] [blame] | 261 | grep "A U Thor" actual |
| 262 | ' |
| 263 | |
Torsten Bögershausen | a08feb8 | 2016-04-05 21:23:54 +0200 | [diff] [blame] | 264 | test_expect_success 'blame file with CRLF core.autocrlf=true' ' |
| 265 | git config core.autocrlf false && |
| 266 | printf "testcase\r\n" >crlfinrepo && |
| 267 | >.gitattributes && |
| 268 | git add crlfinrepo && |
| 269 | git commit -m "add crlfinrepo" && |
| 270 | git config core.autocrlf true && |
| 271 | mv crlfinrepo tmp && |
| 272 | git checkout crlfinrepo && |
| 273 | rm tmp && |
| 274 | git blame crlfinrepo >actual && |
| 275 | grep "A U Thor" actual |
| 276 | ' |
| 277 | |
Junio C Hamano | c2a0636 | 2007-05-05 22:36:19 -0700 | [diff] [blame] | 278 | test_done |