| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2010, Will Palmer |
| 4 | # Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests) |
| 5 | # |
| 6 | |
| 7 | test_description='Test pretty formats' |
| 8 | |
| 9 | . ./test-lib.sh |
| 10 | |
| 11 | # Tested non-UTF-8 encoding |
| 12 | if test_have_prereq ICONV |
| 13 | then |
| 14 | test_encoding="ISO8859-1" |
| 15 | else |
| 16 | test_encoding="UTF-8" |
| 17 | fi |
| 18 | |
| 19 | sample_utf8_part=$(printf "f\303\244ng") |
| 20 | |
| 21 | commit_msg () { |
| 22 | # String "initial. initial" partly in German |
| 23 | # (translated with Google Translate), |
| 24 | # encoded in UTF-8, used as a commit log message below. |
| 25 | msg="initial. an${sample_utf8_part}lich\n" |
| 26 | if test -n "$1" && test "$1" != "UTF-8" |
| 27 | then |
| 28 | printf "$msg" | iconv -f utf-8 -t "$1" |
| 29 | else |
| 30 | printf "$msg" |
| 31 | fi |
| 32 | } |
| 33 | |
| 34 | test_expect_success 'set up basic repos' ' |
| 35 | >foo && |
| 36 | >bar && |
| 37 | git add foo && |
| 38 | test_tick && |
| 39 | test_config i18n.commitEncoding $test_encoding && |
| 40 | commit_msg $test_encoding | git commit -F - && |
| 41 | git add bar && |
| 42 | test_tick && |
| 43 | git commit -m "add bar" |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'alias builtin format' ' |
| 47 | git log --pretty=oneline >expected && |
| 48 | test_config pretty.test-alias oneline && |
| 49 | git log --pretty=test-alias >actual && |
| 50 | test_cmp expected actual |
| 51 | ' |
| 52 | |
| 53 | test_expect_success 'alias masking builtin format' ' |
| 54 | git log --pretty=oneline >expected && |
| 55 | test_config pretty.oneline "%H" && |
| 56 | git log --pretty=oneline >actual && |
| 57 | test_cmp expected actual |
| 58 | ' |
| 59 | |
| 60 | test_expect_success 'alias user-defined format' ' |
| 61 | git log --pretty="format:%h" >expected && |
| 62 | test_config pretty.test-alias "format:%h" && |
| 63 | git log --pretty=test-alias >actual && |
| 64 | test_cmp expected actual |
| 65 | ' |
| 66 | |
| 67 | test_expect_success 'alias user-defined format is matched case-insensitively' ' |
| 68 | git log --pretty="format:%h" >expected && |
| 69 | test_config pretty.testone "format:%h" && |
| 70 | test_config pretty.testtwo testOne && |
| 71 | git log --pretty=testTwo >actual && |
| 72 | test_cmp expected actual |
| 73 | ' |
| 74 | |
| 75 | test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' ' |
| 76 | test_config i18n.logOutputEncoding $test_encoding && |
| 77 | git log --oneline >expected-s && |
| 78 | git log --pretty="tformat:%h %s" >actual-s && |
| 79 | test_cmp expected-s actual-s |
| 80 | ' |
| 81 | |
| 82 | test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' ' |
| 83 | git log --oneline >expected-s && |
| 84 | git log --pretty="tformat:%h %s" >actual-s && |
| 85 | test_cmp expected-s actual-s |
| 86 | ' |
| 87 | |
| 88 | test_expect_success 'alias user-defined tformat' ' |
| 89 | git log --pretty="tformat:%h" >expected && |
| 90 | test_config pretty.test-alias "tformat:%h" && |
| 91 | git log --pretty=test-alias >actual && |
| 92 | test_cmp expected actual |
| 93 | ' |
| 94 | |
| 95 | test_expect_success 'alias non-existent format' ' |
| 96 | test_config pretty.test-alias format-that-will-never-exist && |
| 97 | test_must_fail git log --pretty=test-alias |
| 98 | ' |
| 99 | |
| 100 | test_expect_success 'alias of an alias' ' |
| 101 | git log --pretty="tformat:%h" >expected && |
| 102 | test_config pretty.test-foo "tformat:%h" && |
| 103 | test_config pretty.test-bar test-foo && |
| 104 | git log --pretty=test-bar >actual && test_cmp expected actual |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'alias masking an alias' ' |
| 108 | git log --pretty=format:"Two %H" >expected && |
| 109 | test_config pretty.duplicate "format:One %H" && |
| 110 | test_config pretty.duplicate "format:Two %H" --add && |
| 111 | git log --pretty=duplicate >actual && |
| 112 | test_cmp expected actual |
| 113 | ' |
| 114 | |
| 115 | test_expect_success 'alias loop' ' |
| 116 | test_config pretty.test-foo test-bar && |
| 117 | test_config pretty.test-bar test-foo && |
| 118 | test_must_fail git log --pretty=test-foo |
| 119 | ' |
| 120 | |
| 121 | test_expect_success 'NUL separation' ' |
| 122 | printf "add bar\0$(commit_msg)" >expected && |
| 123 | git log -z --pretty="format:%s" >actual && |
| 124 | test_cmp expected actual |
| 125 | ' |
| 126 | |
| 127 | test_expect_success 'NUL termination' ' |
| 128 | printf "add bar\0$(commit_msg)\0" >expected && |
| 129 | git log -z --pretty="tformat:%s" >actual && |
| 130 | test_cmp expected actual |
| 131 | ' |
| 132 | |
| 133 | test_expect_success 'NUL separation with --stat' ' |
| 134 | stat0_part=$(git diff --stat HEAD^ HEAD) && |
| 135 | stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && |
| 136 | printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected && |
| 137 | git log -z --stat --pretty="format:%s" >actual && |
| 138 | test_cmp expected actual |
| 139 | ' |
| 140 | |
| 141 | test_expect_failure 'NUL termination with --stat' ' |
| 142 | stat0_part=$(git diff --stat HEAD^ HEAD) && |
| 143 | stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && |
| 144 | printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n\0" >expected && |
| 145 | git log -z --stat --pretty="tformat:%s" >actual && |
| 146 | test_cmp expected actual |
| 147 | ' |
| 148 | |
| 149 | for p in short medium full fuller email raw |
| 150 | do |
| 151 | test_expect_success "NUL termination with --reflog --pretty=$p" ' |
| 152 | revs="$(git rev-list --reflog)" && |
| 153 | for r in $revs |
| 154 | do |
| 155 | git show -s "$r" --pretty="$p" && |
| 156 | printf "\0" || return 1 |
| 157 | done >expect && |
| 158 | { |
| 159 | git log -z --reflog --pretty="$p" && |
| 160 | printf "\0" |
| 161 | } >actual && |
| 162 | test_cmp expect actual |
| 163 | ' |
| 164 | done |
| 165 | |
| 166 | test_expect_success 'NUL termination with --reflog --pretty=oneline' ' |
| 167 | revs="$(git rev-list --reflog)" && |
| 168 | for r in $revs |
| 169 | do |
| 170 | git show -s --pretty=oneline "$r" >raw && |
| 171 | lf_to_nul <raw || return 1 |
| 172 | done >expect && |
| 173 | # the trailing NUL is already produced so we do not need to |
| 174 | # output another one |
| 175 | git log -z --pretty=oneline --reflog >actual && |
| 176 | test_cmp expect actual |
| 177 | ' |
| 178 | |
| 179 | test_expect_success 'setup more commits' ' |
| 180 | test_commit "message one" one one message-one && |
| 181 | test_commit "message two" two two message-two && |
| 182 | head1=$(git rev-parse --verify --short HEAD~0) && |
| 183 | head2=$(git rev-parse --verify --short HEAD~1) && |
| 184 | head3=$(git rev-parse --verify --short HEAD~2) && |
| 185 | head4=$(git rev-parse --verify --short HEAD~3) |
| 186 | ' |
| 187 | |
| 188 | test_expect_success 'left alignment formatting' ' |
| 189 | git log --pretty="tformat:%<(40)%s" >actual && |
| 190 | qz_to_tab_space <<-EOF >expected && |
| 191 | message two Z |
| 192 | message one Z |
| 193 | add bar Z |
| 194 | $(commit_msg) Z |
| 195 | EOF |
| 196 | test_cmp expected actual |
| 197 | ' |
| 198 | |
| 199 | test_expect_success ICONV 'left alignment formatting. i18n.logOutputEncoding' ' |
| 200 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual && |
| 201 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 202 | message two Z |
| 203 | message one Z |
| 204 | add bar Z |
| 205 | $(commit_msg) Z |
| 206 | EOF |
| 207 | test_cmp expected actual |
| 208 | ' |
| 209 | |
| 210 | test_expect_success 'left alignment formatting at the nth column' ' |
| 211 | git log --pretty="tformat:%h %<|(40)%s" >actual && |
| 212 | qz_to_tab_space <<-EOF >expected && |
| 213 | $head1 message two Z |
| 214 | $head2 message one Z |
| 215 | $head3 add bar Z |
| 216 | $head4 $(commit_msg) Z |
| 217 | EOF |
| 218 | test_cmp expected actual |
| 219 | ' |
| 220 | |
| 221 | test_expect_success 'left alignment formatting at the nth column' ' |
| 222 | COLUMNS=50 git log --pretty="tformat:%h %<|(-10)%s" >actual && |
| 223 | qz_to_tab_space <<-EOF >expected && |
| 224 | $head1 message two Z |
| 225 | $head2 message one Z |
| 226 | $head3 add bar Z |
| 227 | $head4 $(commit_msg) Z |
| 228 | EOF |
| 229 | test_cmp expected actual |
| 230 | ' |
| 231 | |
| 232 | test_expect_success ICONV 'left alignment formatting at the nth column. i18n.logOutputEncoding' ' |
| 233 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual && |
| 234 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 235 | $head1 message two Z |
| 236 | $head2 message one Z |
| 237 | $head3 add bar Z |
| 238 | $head4 $(commit_msg) Z |
| 239 | EOF |
| 240 | test_cmp expected actual |
| 241 | ' |
| 242 | |
| 243 | test_expect_success 'left alignment formatting with no padding' ' |
| 244 | git log --pretty="tformat:%<(1)%s" >actual && |
| 245 | cat <<-EOF >expected && |
| 246 | message two |
| 247 | message one |
| 248 | add bar |
| 249 | $(commit_msg) |
| 250 | EOF |
| 251 | test_cmp expected actual |
| 252 | ' |
| 253 | |
| 254 | test_expect_success ICONV 'left alignment formatting with no padding. i18n.logOutputEncoding' ' |
| 255 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual && |
| 256 | cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 257 | message two |
| 258 | message one |
| 259 | add bar |
| 260 | $(commit_msg) |
| 261 | EOF |
| 262 | test_cmp expected actual |
| 263 | ' |
| 264 | |
| 265 | test_expect_success 'left alignment formatting with trunc' ' |
| 266 | git log --pretty="tformat:%<(10,trunc)%s" >actual && |
| 267 | qz_to_tab_space <<-\EOF >expected && |
| 268 | message .. |
| 269 | message .. |
| 270 | add bar Z |
| 271 | initial... |
| 272 | EOF |
| 273 | test_cmp expected actual |
| 274 | ' |
| 275 | |
| 276 | test_expect_success ICONV 'left alignment formatting with trunc. i18n.logOutputEncoding' ' |
| 277 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual && |
| 278 | qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 279 | message .. |
| 280 | message .. |
| 281 | add bar Z |
| 282 | initial... |
| 283 | EOF |
| 284 | test_cmp expected actual |
| 285 | ' |
| 286 | |
| 287 | test_expect_success 'left alignment formatting with ltrunc' ' |
| 288 | git log --pretty="tformat:%<(10,ltrunc)%s" >actual && |
| 289 | qz_to_tab_space <<-EOF >expected && |
| 290 | ..sage two |
| 291 | ..sage one |
| 292 | add bar Z |
| 293 | ..${sample_utf8_part}lich |
| 294 | EOF |
| 295 | test_cmp expected actual |
| 296 | ' |
| 297 | |
| 298 | test_expect_success ICONV 'left alignment formatting with ltrunc. i18n.logOutputEncoding' ' |
| 299 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual && |
| 300 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 301 | ..sage two |
| 302 | ..sage one |
| 303 | add bar Z |
| 304 | ..${sample_utf8_part}lich |
| 305 | EOF |
| 306 | test_cmp expected actual |
| 307 | ' |
| 308 | |
| 309 | test_expect_success 'left alignment formatting with mtrunc' ' |
| 310 | git log --pretty="tformat:%<(10,mtrunc)%s" >actual && |
| 311 | qz_to_tab_space <<-\EOF >expected && |
| 312 | mess.. two |
| 313 | mess.. one |
| 314 | add bar Z |
| 315 | init..lich |
| 316 | EOF |
| 317 | test_cmp expected actual |
| 318 | ' |
| 319 | |
| 320 | test_expect_success ICONV 'left alignment formatting with mtrunc. i18n.logOutputEncoding' ' |
| 321 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual && |
| 322 | qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 323 | mess.. two |
| 324 | mess.. one |
| 325 | add bar Z |
| 326 | init..lich |
| 327 | EOF |
| 328 | test_cmp expected actual |
| 329 | ' |
| 330 | |
| 331 | test_expect_success 'right alignment formatting' ' |
| 332 | git log --pretty="tformat:%>(40)%s" >actual && |
| 333 | qz_to_tab_space <<-EOF >expected && |
| 334 | Z message two |
| 335 | Z message one |
| 336 | Z add bar |
| 337 | Z $(commit_msg) |
| 338 | EOF |
| 339 | test_cmp expected actual |
| 340 | ' |
| 341 | |
| 342 | test_expect_success ICONV 'right alignment formatting. i18n.logOutputEncoding' ' |
| 343 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual && |
| 344 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 345 | Z message two |
| 346 | Z message one |
| 347 | Z add bar |
| 348 | Z $(commit_msg) |
| 349 | EOF |
| 350 | test_cmp expected actual |
| 351 | ' |
| 352 | |
| 353 | test_expect_success 'right alignment formatting at the nth column' ' |
| 354 | git log --pretty="tformat:%h %>|(40)%s" >actual && |
| 355 | qz_to_tab_space <<-EOF >expected && |
| 356 | $head1 message two |
| 357 | $head2 message one |
| 358 | $head3 add bar |
| 359 | $head4 $(commit_msg) |
| 360 | EOF |
| 361 | test_cmp expected actual |
| 362 | ' |
| 363 | |
| 364 | test_expect_success 'right alignment formatting at the nth column' ' |
| 365 | COLUMNS=50 git log --pretty="tformat:%h %>|(-10)%s" >actual && |
| 366 | qz_to_tab_space <<-EOF >expected && |
| 367 | $head1 message two |
| 368 | $head2 message one |
| 369 | $head3 add bar |
| 370 | $head4 $(commit_msg) |
| 371 | EOF |
| 372 | test_cmp expected actual |
| 373 | ' |
| 374 | |
| 375 | test_expect_success ICONV 'right alignment formatting at the nth column. i18n.logOutputEncoding' ' |
| 376 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual && |
| 377 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 378 | $head1 message two |
| 379 | $head2 message one |
| 380 | $head3 add bar |
| 381 | $head4 $(commit_msg) |
| 382 | EOF |
| 383 | test_cmp expected actual |
| 384 | ' |
| 385 | |
| 386 | # Note: Space between 'message' and 'two' should be in the same column |
| 387 | # as in previous test. |
| 388 | test_expect_success ICONV 'right alignment formatting at the nth column with --graph. i18n.logOutputEncoding' ' |
| 389 | git -c i18n.logOutputEncoding=$test_encoding log --graph --pretty="tformat:%h %>|(40)%s" >actual && |
| 390 | iconv -f utf-8 -t $test_encoding >expected <<-EOF && |
| 391 | * $head1 message two |
| 392 | * $head2 message one |
| 393 | * $head3 add bar |
| 394 | * $head4 $(commit_msg) |
| 395 | EOF |
| 396 | test_cmp expected actual |
| 397 | ' |
| 398 | |
| 399 | test_expect_success 'right alignment formatting with no padding' ' |
| 400 | git log --pretty="tformat:%>(1)%s" >actual && |
| 401 | cat <<-EOF >expected && |
| 402 | message two |
| 403 | message one |
| 404 | add bar |
| 405 | $(commit_msg) |
| 406 | EOF |
| 407 | test_cmp expected actual |
| 408 | ' |
| 409 | |
| 410 | test_expect_success 'right alignment formatting with no padding and with --graph' ' |
| 411 | git log --graph --pretty="tformat:%>(1)%s" >actual && |
| 412 | cat <<-EOF >expected && |
| 413 | * message two |
| 414 | * message one |
| 415 | * add bar |
| 416 | * $(commit_msg) |
| 417 | EOF |
| 418 | test_cmp expected actual |
| 419 | ' |
| 420 | |
| 421 | test_expect_success ICONV 'right alignment formatting with no padding. i18n.logOutputEncoding' ' |
| 422 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual && |
| 423 | cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 424 | message two |
| 425 | message one |
| 426 | add bar |
| 427 | $(commit_msg) |
| 428 | EOF |
| 429 | test_cmp expected actual |
| 430 | ' |
| 431 | |
| 432 | test_expect_success 'center alignment formatting' ' |
| 433 | git log --pretty="tformat:%><(40)%s" >actual && |
| 434 | qz_to_tab_space <<-EOF >expected && |
| 435 | Z message two Z |
| 436 | Z message one Z |
| 437 | Z add bar Z |
| 438 | Z $(commit_msg) Z |
| 439 | EOF |
| 440 | test_cmp expected actual |
| 441 | ' |
| 442 | |
| 443 | test_expect_success ICONV 'center alignment formatting. i18n.logOutputEncoding' ' |
| 444 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual && |
| 445 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 446 | Z message two Z |
| 447 | Z message one Z |
| 448 | Z add bar Z |
| 449 | Z $(commit_msg) Z |
| 450 | EOF |
| 451 | test_cmp expected actual |
| 452 | ' |
| 453 | |
| 454 | test_expect_success 'center alignment formatting at the nth column' ' |
| 455 | git log --pretty="tformat:%h %><|(40)%s" >actual && |
| 456 | qz_to_tab_space <<-EOF >expected && |
| 457 | $head1 message two Z |
| 458 | $head2 message one Z |
| 459 | $head3 add bar Z |
| 460 | $head4 $(commit_msg) Z |
| 461 | EOF |
| 462 | test_cmp expected actual |
| 463 | ' |
| 464 | |
| 465 | test_expect_success 'center alignment formatting at the nth column' ' |
| 466 | COLUMNS=70 git log --pretty="tformat:%h %><|(-30)%s" >actual && |
| 467 | qz_to_tab_space <<-EOF >expected && |
| 468 | $head1 message two Z |
| 469 | $head2 message one Z |
| 470 | $head3 add bar Z |
| 471 | $head4 $(commit_msg) Z |
| 472 | EOF |
| 473 | test_cmp expected actual |
| 474 | ' |
| 475 | |
| 476 | test_expect_success ICONV 'center alignment formatting at the nth column. i18n.logOutputEncoding' ' |
| 477 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual && |
| 478 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 479 | $head1 message two Z |
| 480 | $head2 message one Z |
| 481 | $head3 add bar Z |
| 482 | $head4 $(commit_msg) Z |
| 483 | EOF |
| 484 | test_cmp expected actual |
| 485 | ' |
| 486 | |
| 487 | test_expect_success 'center alignment formatting with no padding' ' |
| 488 | git log --pretty="tformat:%><(1)%s" >actual && |
| 489 | cat <<-EOF >expected && |
| 490 | message two |
| 491 | message one |
| 492 | add bar |
| 493 | $(commit_msg) |
| 494 | EOF |
| 495 | test_cmp expected actual |
| 496 | ' |
| 497 | |
| 498 | # save HEAD's SHA-1 digest (with no abbreviations) to use it below |
| 499 | # as far as the next test amends HEAD |
| 500 | old_head1=$(git rev-parse --verify HEAD~0) |
| 501 | test_expect_success ICONV 'center alignment formatting with no padding. i18n.logOutputEncoding' ' |
| 502 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual && |
| 503 | cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 504 | message two |
| 505 | message one |
| 506 | add bar |
| 507 | $(commit_msg) |
| 508 | EOF |
| 509 | test_cmp expected actual |
| 510 | ' |
| 511 | |
| 512 | test_expect_success ICONV 'left/right alignment formatting with stealing' ' |
| 513 | git commit --amend -m short --author "long long long <long@me.com>" && |
| 514 | git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && |
| 515 | cat <<-\EOF >expected && |
| 516 | short long long long |
| 517 | message .. A U Thor |
| 518 | add bar A U Thor |
| 519 | initial... A U Thor |
| 520 | EOF |
| 521 | test_cmp expected actual |
| 522 | ' |
| 523 | test_expect_success ICONV 'left/right alignment formatting with stealing. i18n.logOutputEncoding' ' |
| 524 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && |
| 525 | cat <<-\EOF | iconv -f utf-8 -t $test_encoding >expected && |
| 526 | short long long long |
| 527 | message .. A U Thor |
| 528 | add bar A U Thor |
| 529 | initial... A U Thor |
| 530 | EOF |
| 531 | test_cmp expected actual |
| 532 | ' |
| 533 | |
| 534 | test_expect_success 'strbuf_utf8_replace() not producing NUL' ' |
| 535 | git log --color --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)%C(auto)%d" | |
| 536 | test_decode_color | |
| 537 | nul_to_q >actual && |
| 538 | ! grep Q actual |
| 539 | ' |
| 540 | |
| 541 | # --date=[XXX] and corresponding %a[X] %c[X] format equivalency |
| 542 | test_expect_success '--date=iso-strict %ad%cd is the same as %aI%cI' ' |
| 543 | git log --format=%ad%n%cd --date=iso-strict >expected && |
| 544 | git log --format=%aI%n%cI >actual && |
| 545 | test_cmp expected actual |
| 546 | ' |
| 547 | |
| 548 | test_expect_success '--date=short %ad%cd is the same as %as%cs' ' |
| 549 | git log --format=%ad%n%cd --date=short >expected && |
| 550 | git log --format=%as%n%cs >actual && |
| 551 | test_cmp expected actual |
| 552 | ' |
| 553 | |
| 554 | test_expect_success '--date=human %ad%cd is the same as %ah%ch' ' |
| 555 | git log --format=%ad%n%cd --date=human >expected && |
| 556 | git log --format=%ah%n%ch >actual && |
| 557 | test_cmp expected actual |
| 558 | ' |
| 559 | |
| 560 | # get new digests (with no abbreviations) |
| 561 | test_expect_success 'set up log decoration tests' ' |
| 562 | head1=$(git rev-parse --verify HEAD~0) && |
| 563 | head2=$(git rev-parse --verify HEAD~1) |
| 564 | ' |
| 565 | |
| 566 | test_expect_success 'log decoration properly follows tag chain' ' |
| 567 | git tag -a tag1 -m tag1 && |
| 568 | git tag -a tag2 -m tag2 tag1 && |
| 569 | git tag -d tag1 && |
| 570 | git commit --amend -m shorter && |
| 571 | git log --no-walk --tags --pretty="%H %d" --decorate=full >actual && |
| 572 | if test_have_prereq ICONV |
| 573 | then |
| 574 | cat <<-EOF >expected |
| 575 | $head2 (tag: refs/tags/message-one) |
| 576 | $old_head1 (tag: refs/tags/message-two) |
| 577 | $head1 (tag: refs/tags/tag2) |
| 578 | EOF |
| 579 | else |
| 580 | cat <<-EOF >expected |
| 581 | $head2 (tag: refs/tags/message-one) |
| 582 | $old_head1 (tag: refs/tags/tag2, tag: refs/tags/message-two) |
| 583 | EOF |
| 584 | fi && |
| 585 | sort -k3 actual >actual1 && |
| 586 | test_cmp expected actual1 |
| 587 | ' |
| 588 | |
| 589 | test_expect_success 'clean log decoration' ' |
| 590 | git log --no-walk --tags --pretty="%H %D" --decorate=full >actual && |
| 591 | if test_have_prereq ICONV |
| 592 | then |
| 593 | cat <<-EOF >expected |
| 594 | $head2 tag: refs/tags/message-one |
| 595 | $old_head1 tag: refs/tags/message-two |
| 596 | $head1 tag: refs/tags/tag2 |
| 597 | EOF |
| 598 | else |
| 599 | cat <<-EOF >expected |
| 600 | $head2 tag: refs/tags/message-one |
| 601 | $old_head1 tag: refs/tags/tag2, tag: refs/tags/message-two |
| 602 | EOF |
| 603 | fi && |
| 604 | sort -k3 actual >actual1 && |
| 605 | test_cmp expected actual1 |
| 606 | ' |
| 607 | |
| 608 | test_expect_success 'pretty format %decorate' ' |
| 609 | git checkout -b foo && |
| 610 | git commit --allow-empty -m "new commit" && |
| 611 | git tag bar && |
| 612 | git branch qux && |
| 613 | |
| 614 | echo " (HEAD -> foo, tag: bar, qux)" >expect1 && |
| 615 | git log --format="%(decorate)" -1 >actual1 && |
| 616 | test_cmp expect1 actual1 && |
| 617 | |
| 618 | echo "HEAD -> foo, tag: bar, qux" >expect2 && |
| 619 | git log --format="%(decorate:prefix=,suffix=)" -1 >actual2 && |
| 620 | test_cmp expect2 actual2 && |
| 621 | |
| 622 | echo "[ bar; qux; foo ]" >expect3 && |
| 623 | git log --format="%(decorate:prefix=[ ,suffix= ],separator=%x3B ,tag=)" \ |
| 624 | --decorate-refs=refs/ -1 >actual3 && |
| 625 | test_cmp expect3 actual3 && |
| 626 | |
| 627 | # Try with a typo (in "separator"), in which case the placeholder should |
| 628 | # not be replaced. |
| 629 | echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 && |
| 630 | git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \ |
| 631 | -1 >actual4 && |
| 632 | test_cmp expect4 actual4 && |
| 633 | |
| 634 | echo "HEAD->foo bar qux" >expect5 && |
| 635 | git log --format="%(decorate:prefix=,suffix=,separator= ,tag=,pointer=->)" \ |
| 636 | -1 >actual5 && |
| 637 | test_cmp expect5 actual5 |
| 638 | ' |
| 639 | |
| 640 | cat >trailers <<EOF |
| 641 | Signed-off-by: A U Thor <author@example.com> |
| 642 | Acked-by: A U Thor <author@example.com> |
| 643 | [ v2 updated patch description ] |
| 644 | Signed-off-by: A U Thor |
| 645 | <author@example.com> |
| 646 | EOF |
| 647 | |
| 648 | unfold () { |
| 649 | perl -0pe 's/\n\s+/ /g' |
| 650 | } |
| 651 | |
| 652 | test_expect_success 'set up trailer tests' ' |
| 653 | echo "Some contents" >trailerfile && |
| 654 | git add trailerfile && |
| 655 | git commit -F - <<-EOF |
| 656 | trailers: this commit message has trailers |
| 657 | |
| 658 | This commit is a test commit with trailers at the end. We parse this |
| 659 | message and display the trailers using %(trailers). |
| 660 | |
| 661 | $(cat trailers) |
| 662 | EOF |
| 663 | ' |
| 664 | |
| 665 | test_expect_success 'pretty format %(trailers) shows trailers' ' |
| 666 | git log --no-walk --pretty="%(trailers)" >actual && |
| 667 | { |
| 668 | cat trailers && |
| 669 | echo |
| 670 | } >expect && |
| 671 | test_cmp expect actual |
| 672 | ' |
| 673 | |
| 674 | test_expect_success 'pretty format %(trailers:) enables no options' ' |
| 675 | git log --no-walk --pretty="%(trailers:)" >actual && |
| 676 | # "expect" the same as the test above |
| 677 | test_cmp expect actual |
| 678 | ' |
| 679 | |
| 680 | test_expect_success '%(trailers:only) shows only "key: value" trailers' ' |
| 681 | git log --no-walk --pretty="%(trailers:only)" >actual && |
| 682 | { |
| 683 | grep -v patch.description <trailers && |
| 684 | echo |
| 685 | } >expect && |
| 686 | test_cmp expect actual |
| 687 | ' |
| 688 | |
| 689 | test_expect_success '%(trailers:only=yes) shows only "key: value" trailers' ' |
| 690 | git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual && |
| 691 | grep -v patch.description <trailers >expect && |
| 692 | test_cmp expect actual |
| 693 | ' |
| 694 | |
| 695 | test_expect_success '%(trailers:only=no) shows all trailers' ' |
| 696 | git log --no-walk --pretty=format:"%(trailers:only=no)" >actual && |
| 697 | cat trailers >expect && |
| 698 | test_cmp expect actual |
| 699 | ' |
| 700 | |
| 701 | test_expect_success '%(trailers:only=no,only=true) shows only "key: value" trailers' ' |
| 702 | git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual && |
| 703 | grep -v patch.description <trailers >expect && |
| 704 | test_cmp expect actual |
| 705 | ' |
| 706 | |
| 707 | test_expect_success PERL_TEST_HELPERS '%(trailers:unfold) unfolds trailers' ' |
| 708 | git log --no-walk --pretty="%(trailers:unfold)" >actual && |
| 709 | { |
| 710 | unfold <trailers && |
| 711 | echo |
| 712 | } >expect && |
| 713 | test_cmp expect actual |
| 714 | ' |
| 715 | |
| 716 | test_expect_success PERL_TEST_HELPERS ':only and :unfold work together' ' |
| 717 | git log --no-walk --pretty="%(trailers:only,unfold)" >actual && |
| 718 | git log --no-walk --pretty="%(trailers:unfold,only)" >reverse && |
| 719 | test_cmp actual reverse && |
| 720 | { |
| 721 | grep -v patch.description <trailers | unfold && |
| 722 | echo |
| 723 | } >expect && |
| 724 | test_cmp expect actual |
| 725 | ' |
| 726 | |
| 727 | test_expect_success 'pretty format %(trailers:key=foo) shows that trailer' ' |
| 728 | git log --no-walk --pretty="format:%(trailers:key=Acked-by)" >actual && |
| 729 | echo "Acked-by: A U Thor <author@example.com>" >expect && |
| 730 | test_cmp expect actual |
| 731 | ' |
| 732 | |
| 733 | test_expect_success 'pretty format %(trailers:key=foo) is case insensitive' ' |
| 734 | git log --no-walk --pretty="format:%(trailers:key=AcKed-bY)" >actual && |
| 735 | echo "Acked-by: A U Thor <author@example.com>" >expect && |
| 736 | test_cmp expect actual |
| 737 | ' |
| 738 | |
| 739 | test_expect_success 'pretty format %(trailers:key=foo:) trailing colon also works' ' |
| 740 | git log --no-walk --pretty="format:%(trailers:key=Acked-by:)" >actual && |
| 741 | echo "Acked-by: A U Thor <author@example.com>" >expect && |
| 742 | test_cmp expect actual |
| 743 | ' |
| 744 | |
| 745 | test_expect_success 'pretty format %(trailers:key=foo) multiple keys' ' |
| 746 | git log --no-walk --pretty="format:%(trailers:key=Acked-by:,key=Signed-off-By)" >actual && |
| 747 | grep -v patch.description <trailers >expect && |
| 748 | test_cmp expect actual |
| 749 | ' |
| 750 | |
| 751 | test_expect_success '%(trailers:key=nonexistent) becomes empty' ' |
| 752 | git log --no-walk --pretty="x%(trailers:key=Nacked-by)x" >actual && |
| 753 | echo "xx" >expect && |
| 754 | test_cmp expect actual |
| 755 | ' |
| 756 | |
| 757 | test_expect_success '%(trailers:key=foo) handles multiple lines even if folded' ' |
| 758 | git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by)" >actual && |
| 759 | grep -v patch.description <trailers | grep -v Acked-by >expect && |
| 760 | test_cmp expect actual |
| 761 | ' |
| 762 | |
| 763 | test_expect_success PERL_TEST_HELPERS '%(trailers:key=foo,unfold) properly unfolds' ' |
| 764 | git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by,unfold)" >actual && |
| 765 | unfold <trailers | grep Signed-off-by >expect && |
| 766 | test_cmp expect actual |
| 767 | ' |
| 768 | |
| 769 | test_expect_success 'pretty format %(trailers:key=foo,only=no) also includes nontrailer lines' ' |
| 770 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,only=no)" >actual && |
| 771 | { |
| 772 | echo "Acked-by: A U Thor <author@example.com>" && |
| 773 | grep patch.description <trailers |
| 774 | } >expect && |
| 775 | test_cmp expect actual |
| 776 | ' |
| 777 | |
| 778 | test_expect_success '%(trailers:key) without value is error' ' |
| 779 | git log --no-walk --pretty="tformat:%(trailers:key)" >actual && |
| 780 | echo "%(trailers:key)" >expect && |
| 781 | test_cmp expect actual |
| 782 | ' |
| 783 | |
| 784 | test_expect_success '%(trailers:keyonly) shows only keys' ' |
| 785 | git log --no-walk --pretty="format:%(trailers:keyonly)" >actual && |
| 786 | test_write_lines \ |
| 787 | "Signed-off-by" \ |
| 788 | "Acked-by" \ |
| 789 | "[ v2 updated patch description ]" \ |
| 790 | "Signed-off-by" >expect && |
| 791 | test_cmp expect actual |
| 792 | ' |
| 793 | |
| 794 | test_expect_success '%(trailers:key=foo,keyonly) shows only key' ' |
| 795 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly)" >actual && |
| 796 | echo "Acked-by" >expect && |
| 797 | test_cmp expect actual |
| 798 | ' |
| 799 | |
| 800 | test_expect_success '%(trailers:key=foo,valueonly) shows only value' ' |
| 801 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,valueonly)" >actual && |
| 802 | echo "A U Thor <author@example.com>" >expect && |
| 803 | test_cmp expect actual |
| 804 | ' |
| 805 | |
| 806 | test_expect_success '%(trailers:valueonly) shows only values' ' |
| 807 | git log --no-walk --pretty="format:%(trailers:valueonly)" >actual && |
| 808 | test_write_lines \ |
| 809 | "A U Thor <author@example.com>" \ |
| 810 | "A U Thor <author@example.com>" \ |
| 811 | "[ v2 updated patch description ]" \ |
| 812 | "A U Thor" \ |
| 813 | " <author@example.com>" >expect && |
| 814 | test_cmp expect actual |
| 815 | ' |
| 816 | |
| 817 | test_expect_success '%(trailers:key=foo,keyonly,valueonly) shows nothing' ' |
| 818 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly,valueonly)" >actual && |
| 819 | echo >expect && |
| 820 | test_cmp expect actual |
| 821 | ' |
| 822 | |
| 823 | test_expect_success 'pretty format %(trailers:separator) changes separator' ' |
| 824 | git log --no-walk --pretty=format:"X%(trailers:separator=%x00)X" >actual && |
| 825 | ( |
| 826 | printf "XSigned-off-by: A U Thor <author@example.com>\0" && |
| 827 | printf "Acked-by: A U Thor <author@example.com>\0" && |
| 828 | printf "[ v2 updated patch description ]\0" && |
| 829 | printf "Signed-off-by: A U Thor\n <author@example.com>X" |
| 830 | ) >expect && |
| 831 | test_cmp expect actual |
| 832 | ' |
| 833 | |
| 834 | test_expect_success 'pretty format %(trailers:separator=X,unfold) changes separator' ' |
| 835 | git log --no-walk --pretty=format:"X%(trailers:separator=%x00,unfold)X" >actual && |
| 836 | ( |
| 837 | printf "XSigned-off-by: A U Thor <author@example.com>\0" && |
| 838 | printf "Acked-by: A U Thor <author@example.com>\0" && |
| 839 | printf "[ v2 updated patch description ]\0" && |
| 840 | printf "Signed-off-by: A U Thor <author@example.com>X" |
| 841 | ) >expect && |
| 842 | test_cmp expect actual |
| 843 | ' |
| 844 | |
| 845 | test_expect_success 'pretty format %(trailers:key_value_separator) changes key-value separator' ' |
| 846 | git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00)X" >actual && |
| 847 | ( |
| 848 | printf "XSigned-off-by\0A U Thor <author@example.com>\n" && |
| 849 | printf "Acked-by\0A U Thor <author@example.com>\n" && |
| 850 | printf "[ v2 updated patch description ]\n" && |
| 851 | printf "Signed-off-by\0A U Thor\n <author@example.com>\nX" |
| 852 | ) >expect && |
| 853 | test_cmp expect actual |
| 854 | ' |
| 855 | |
| 856 | test_expect_success 'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' ' |
| 857 | git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00,unfold)X" >actual && |
| 858 | ( |
| 859 | printf "XSigned-off-by\0A U Thor <author@example.com>\n" && |
| 860 | printf "Acked-by\0A U Thor <author@example.com>\n" && |
| 861 | printf "[ v2 updated patch description ]\n" && |
| 862 | printf "Signed-off-by\0A U Thor <author@example.com>\nX" |
| 863 | ) >expect && |
| 864 | test_cmp expect actual |
| 865 | ' |
| 866 | |
| 867 | test_expect_success 'pretty format %(trailers:separator,key_value_separator) changes both separators' ' |
| 868 | git log --no-walk --pretty=format:"%(trailers:separator=%x00,key_value_separator=%x00%x00,unfold)" >actual && |
| 869 | ( |
| 870 | printf "Signed-off-by\0\0A U Thor <author@example.com>\0" && |
| 871 | printf "Acked-by\0\0A U Thor <author@example.com>\0" && |
| 872 | printf "[ v2 updated patch description ]\0" && |
| 873 | printf "Signed-off-by\0\0A U Thor <author@example.com>" |
| 874 | ) >expect && |
| 875 | test_cmp expect actual |
| 876 | ' |
| 877 | |
| 878 | test_expect_success 'pretty format %(trailers) combining separator/key/keyonly/valueonly' ' |
| 879 | git commit --allow-empty -F - <<-\EOF && |
| 880 | Important fix |
| 881 | |
| 882 | The fix is explained here |
| 883 | |
| 884 | Closes: #1234 |
| 885 | EOF |
| 886 | |
| 887 | git commit --allow-empty -F - <<-\EOF && |
| 888 | Another fix |
| 889 | |
| 890 | The fix is explained here |
| 891 | |
| 892 | Closes: #567 |
| 893 | Closes: #890 |
| 894 | EOF |
| 895 | |
| 896 | git commit --allow-empty -F - <<-\EOF && |
| 897 | Does not close any tickets |
| 898 | EOF |
| 899 | |
| 900 | git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,valueonly)" HEAD~3.. >actual && |
| 901 | test_write_lines \ |
| 902 | "Does not close any tickets" \ |
| 903 | "Another fix #567, #890" \ |
| 904 | "Important fix #1234" >expect && |
| 905 | test_cmp expect actual && |
| 906 | |
| 907 | git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,keyonly)" HEAD~3.. >actual && |
| 908 | test_write_lines \ |
| 909 | "Does not close any tickets" \ |
| 910 | "Another fix Closes, Closes" \ |
| 911 | "Important fix Closes" >expect && |
| 912 | test_cmp expect actual |
| 913 | ' |
| 914 | |
| 915 | test_expect_success 'trailer parsing not fooled by --- line' ' |
| 916 | git commit --allow-empty -F - <<-\EOF && |
| 917 | this is the subject |
| 918 | |
| 919 | This is the body. The message has a "---" line which would confuse a |
| 920 | message+patch parser. But here we know we have only a commit message, |
| 921 | so we get it right. |
| 922 | |
| 923 | trailer: wrong |
| 924 | --- |
| 925 | This is more body. |
| 926 | |
| 927 | trailer: right |
| 928 | EOF |
| 929 | |
| 930 | { |
| 931 | echo "trailer: right" && |
| 932 | echo |
| 933 | } >expect && |
| 934 | git log --no-walk --format="%(trailers)" >actual && |
| 935 | test_cmp expect actual |
| 936 | ' |
| 937 | |
| 938 | test_expect_success 'set up %S tests' ' |
| 939 | git checkout --orphan source-a && |
| 940 | test_commit one && |
| 941 | test_commit two && |
| 942 | git checkout -b source-b HEAD^ && |
| 943 | test_commit three |
| 944 | ' |
| 945 | |
| 946 | test_expect_success 'log --format=%S paints branch names' ' |
| 947 | cat >expect <<-\EOF && |
| 948 | source-b |
| 949 | source-a |
| 950 | source-b |
| 951 | EOF |
| 952 | git log --format=%S source-a source-b >actual && |
| 953 | test_cmp expect actual |
| 954 | ' |
| 955 | |
| 956 | test_expect_success 'log --format=%S paints tag names' ' |
| 957 | git tag -m tagged source-tag && |
| 958 | cat >expect <<-\EOF && |
| 959 | source-tag |
| 960 | source-a |
| 961 | source-tag |
| 962 | EOF |
| 963 | git log --format=%S source-tag source-a >actual && |
| 964 | test_cmp expect actual |
| 965 | ' |
| 966 | |
| 967 | test_expect_success 'log --format=%S paints symmetric ranges' ' |
| 968 | cat >expect <<-\EOF && |
| 969 | source-b |
| 970 | source-a |
| 971 | EOF |
| 972 | git log --format=%S source-a...source-b >actual && |
| 973 | test_cmp expect actual |
| 974 | ' |
| 975 | |
| 976 | test_expect_success '%S in git log --format works with other placeholders (part 1)' ' |
| 977 | git log --format="source-b %h" source-b >expect && |
| 978 | git log --format="%S %h" source-b >actual && |
| 979 | test_cmp expect actual |
| 980 | ' |
| 981 | |
| 982 | test_expect_success '%S in git log --format works with other placeholders (part 2)' ' |
| 983 | git log --format="%h source-b" source-b >expect && |
| 984 | git log --format="%h %S" source-b >actual && |
| 985 | test_cmp expect actual |
| 986 | ' |
| 987 | |
| 988 | test_expect_success 'setup more commits for %S with --bisect' ' |
| 989 | test_commit four && |
| 990 | test_commit five && |
| 991 | |
| 992 | head1=$(git rev-parse --verify HEAD~0) && |
| 993 | head2=$(git rev-parse --verify HEAD~1) && |
| 994 | head3=$(git rev-parse --verify HEAD~2) && |
| 995 | head4=$(git rev-parse --verify HEAD~3) |
| 996 | ' |
| 997 | |
| 998 | test_expect_success '%S with --bisect labels commits with refs/bisect/bad ref' ' |
| 999 | git update-ref refs/bisect/bad-$head1 $head1 && |
| 1000 | git update-ref refs/bisect/go $head1 && |
| 1001 | git update-ref refs/bisect/bad-$head2 $head2 && |
| 1002 | git update-ref refs/bisect/b $head3 && |
| 1003 | git update-ref refs/bisect/bad-$head4 $head4 && |
| 1004 | git update-ref refs/bisect/good-$head4 $head4 && |
| 1005 | |
| 1006 | # We expect to see the range of commits betwee refs/bisect/good-$head4 |
| 1007 | # and refs/bisect/bad-$head1. The "source" ref is the nearest bisect ref |
| 1008 | # from which the commit is reachable. |
| 1009 | cat >expect <<-EOF && |
| 1010 | $head1 refs/bisect/bad-$head1 |
| 1011 | $head2 refs/bisect/bad-$head2 |
| 1012 | $head3 refs/bisect/bad-$head2 |
| 1013 | EOF |
| 1014 | git log --bisect --format="%H %S" >actual && |
| 1015 | test_cmp expect actual |
| 1016 | ' |
| 1017 | |
| 1018 | test_expect_success 'log --pretty=reference' ' |
| 1019 | git log --pretty="tformat:%h (%s, %as)" >expect && |
| 1020 | git log --pretty=reference >actual && |
| 1021 | test_cmp expect actual |
| 1022 | ' |
| 1023 | |
| 1024 | test_expect_success 'log --pretty=reference with log.date is overridden by short date' ' |
| 1025 | git log --pretty="tformat:%h (%s, %as)" >expect && |
| 1026 | test_config log.date rfc && |
| 1027 | git log --pretty=reference >actual && |
| 1028 | test_cmp expect actual |
| 1029 | ' |
| 1030 | |
| 1031 | test_expect_success 'log --pretty=reference with explicit date overrides short date' ' |
| 1032 | git log --date=rfc --pretty="tformat:%h (%s, %ad)" >expect && |
| 1033 | git log --date=rfc --pretty=reference >actual && |
| 1034 | test_cmp expect actual |
| 1035 | ' |
| 1036 | |
| 1037 | test_expect_success 'log --pretty=reference is never unabbreviated' ' |
| 1038 | git log --pretty="tformat:%h (%s, %as)" >expect && |
| 1039 | git log --no-abbrev-commit --pretty=reference >actual && |
| 1040 | test_cmp expect actual |
| 1041 | ' |
| 1042 | |
| 1043 | test_expect_success 'log --pretty=reference is never decorated' ' |
| 1044 | git log --pretty="tformat:%h (%s, %as)" >expect && |
| 1045 | git log --decorate=short --pretty=reference >actual && |
| 1046 | test_cmp expect actual |
| 1047 | ' |
| 1048 | |
| 1049 | test_expect_success 'log --pretty=reference does not output reflog info' ' |
| 1050 | git log --walk-reflogs --pretty="tformat:%h (%s, %as)" >expect && |
| 1051 | git log --walk-reflogs --pretty=reference >actual && |
| 1052 | test_cmp expect actual |
| 1053 | ' |
| 1054 | |
| 1055 | test_expect_success 'log --pretty=reference is colored appropriately' ' |
| 1056 | git log --color=always --pretty="tformat:%C(auto)%h (%s, %as)" >expect && |
| 1057 | git log --color=always --pretty=reference >actual && |
| 1058 | test_cmp expect actual |
| 1059 | ' |
| 1060 | |
| 1061 | test_expect_success '%(describe) vs git describe' ' |
| 1062 | git log --format="%H" | while read hash |
| 1063 | do |
| 1064 | if desc=$(git describe $hash) |
| 1065 | then |
| 1066 | : >expect-contains-good |
| 1067 | else |
| 1068 | : >expect-contains-bad |
| 1069 | fi && |
| 1070 | echo "$hash $desc" || return 1 |
| 1071 | done >expect && |
| 1072 | test_path_exists expect-contains-good && |
| 1073 | test_path_exists expect-contains-bad && |
| 1074 | |
| 1075 | git log --format="%H %(describe)" >actual 2>err && |
| 1076 | test_cmp expect actual && |
| 1077 | test_must_be_empty err |
| 1078 | ' |
| 1079 | |
| 1080 | test_expect_success '%(describe:match=...) vs git describe --match ...' ' |
| 1081 | test_when_finished "git tag -d tag-match" && |
| 1082 | git tag -a -m tagged tag-match && |
| 1083 | git describe --match "*-match" >expect && |
| 1084 | git log -1 --format="%(describe:match=*-match)" >actual && |
| 1085 | test_cmp expect actual |
| 1086 | ' |
| 1087 | |
| 1088 | test_expect_success '%(describe:exclude=...) vs git describe --exclude ...' ' |
| 1089 | test_when_finished "git tag -d tag-exclude" && |
| 1090 | git tag -a -m tagged tag-exclude && |
| 1091 | git describe --exclude "*-exclude" >expect && |
| 1092 | git log -1 --format="%(describe:exclude=*-exclude)" >actual && |
| 1093 | test_cmp expect actual |
| 1094 | ' |
| 1095 | |
| 1096 | test_expect_success '%(describe:tags) vs git describe --tags' ' |
| 1097 | test_when_finished "git tag -d tagname" && |
| 1098 | git tag tagname && |
| 1099 | git describe --tags >expect && |
| 1100 | git log -1 --format="%(describe:tags)" >actual && |
| 1101 | test_cmp expect actual |
| 1102 | ' |
| 1103 | |
| 1104 | test_expect_success '%(describe:abbrev=...) vs git describe --abbrev=...' ' |
| 1105 | test_when_finished "git tag -d tagname" && |
| 1106 | |
| 1107 | # Case 1: We have commits between HEAD and the most recent tag |
| 1108 | # reachable from it |
| 1109 | test_commit --no-tag file && |
| 1110 | git describe --abbrev=15 >expect && |
| 1111 | git log -1 --format="%(describe:abbrev=15)" >actual && |
| 1112 | test_cmp expect actual && |
| 1113 | |
| 1114 | # Make sure the hash used is at least 15 digits long |
| 1115 | sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart && |
| 1116 | test 16 -le $(wc -c <hexpart) && |
| 1117 | |
| 1118 | # Case 2: We have a tag at HEAD, describe directly gives the |
| 1119 | # name of the tag |
| 1120 | git tag -a -m tagged tagname && |
| 1121 | git describe --abbrev=15 >expect && |
| 1122 | git log -1 --format="%(describe:abbrev=15)" >actual && |
| 1123 | test_cmp expect actual && |
| 1124 | test tagname = $(cat actual) |
| 1125 | ' |
| 1126 | |
| 1127 | test_expect_success 'log --pretty with space stealing' ' |
| 1128 | printf mm0 >expect && |
| 1129 | git log -1 --pretty="format:mm%>>|(1)%x30" >actual && |
| 1130 | test_cmp expect actual |
| 1131 | ' |
| 1132 | |
| 1133 | test_expect_success 'log --pretty with invalid padding format' ' |
| 1134 | printf "%s%%<(20" "$(git rev-parse HEAD)" >expect && |
| 1135 | git log -1 --pretty="format:%H%<(20" >actual && |
| 1136 | test_cmp expect actual |
| 1137 | ' |
| 1138 | |
| 1139 | test_expect_success 'log --pretty with magical wrapping directives' ' |
| 1140 | commit_id=$(git commit-tree HEAD^{tree} -m "describe me") && |
| 1141 | git tag describe-me $commit_id && |
| 1142 | printf "\n(tag:\ndescribe-me)%%+w(2)" >expect && |
| 1143 | git log -1 --pretty="format:%w(1)%+d%+w(2)" $commit_id >actual && |
| 1144 | test_cmp expect actual |
| 1145 | ' |
| 1146 | |
| 1147 | test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing wrapping directive' ' |
| 1148 | printf "%%w(2147483649,1,1)0" >expect && |
| 1149 | git log -1 --pretty="format:%w(2147483649,1,1)%x30" >actual && |
| 1150 | test_cmp expect actual && |
| 1151 | printf "%%w(1,2147483649,1)0" >expect && |
| 1152 | git log -1 --pretty="format:%w(1,2147483649,1)%x30" >actual && |
| 1153 | test_cmp expect actual && |
| 1154 | printf "%%w(1,1,2147483649)0" >expect && |
| 1155 | git log -1 --pretty="format:%w(1,1,2147483649)%x30" >actual && |
| 1156 | test_cmp expect actual |
| 1157 | ' |
| 1158 | |
| 1159 | test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing padding directive' ' |
| 1160 | printf "%%<(2147483649)0" >expect && |
| 1161 | git log -1 --pretty="format:%<(2147483649)%x30" >actual && |
| 1162 | test_cmp expect actual |
| 1163 | ' |
| 1164 | |
| 1165 | test_expect_success 'log --pretty with padding and preceding control chars' ' |
| 1166 | printf "\20\20 0" >expect && |
| 1167 | git log -1 --pretty="format:%x10%x10%>|(4)%x30" >actual && |
| 1168 | test_cmp expect actual |
| 1169 | ' |
| 1170 | |
| 1171 | test_expect_success 'log --pretty truncation with control chars' ' |
| 1172 | test_commit "$(printf "\20\20\20\20xxxx")" file contents commit-with-control-chars && |
| 1173 | printf "\20\20\20\20x.." >expect && |
| 1174 | git log -1 --pretty="format:%<(3,trunc)%s" commit-with-control-chars >actual && |
| 1175 | test_cmp expect actual |
| 1176 | ' |
| 1177 | |
| 1178 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' ' |
| 1179 | # We only assert that this command does not crash. This needs to be |
| 1180 | # executed with the address sanitizer to demonstrate failure. |
| 1181 | git log -1 --pretty="format:%>(2147483646)%x41%41%>(2147483646)%x41" >/dev/null |
| 1182 | ' |
| 1183 | |
| 1184 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'set up huge commit' ' |
| 1185 | test-tool genzeros 2147483649 | tr "\000" "1" >expect && |
| 1186 | huge_commit=$(git commit-tree -F expect HEAD^{tree}) |
| 1187 | ' |
| 1188 | |
| 1189 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' ' |
| 1190 | git log -1 --format="%B%<(1)%x30" $huge_commit >actual && |
| 1191 | echo 0 >>expect && |
| 1192 | test_cmp expect actual |
| 1193 | ' |
| 1194 | |
| 1195 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message does not cause allocation failure' ' |
| 1196 | test_must_fail git log -1 --format="%<(1)%B" $huge_commit 2>error && |
| 1197 | cat >expect <<-EOF && |
| 1198 | fatal: number too large to represent as int on this platform: 2147483649 |
| 1199 | EOF |
| 1200 | test_cmp expect error |
| 1201 | ' |
| 1202 | |
| 1203 | # pretty-formats note wide char limitations, and add tests |
| 1204 | test_expect_failure 'wide and decomposed characters column counting' ' |
| 1205 | |
| 1206 | # from t/lib-unicode-nfc-nfd.sh hex values converted to octal |
| 1207 | utf8_nfc=$(printf "\303\251") && # e acute combined. |
| 1208 | utf8_nfd=$(printf "\145\314\201") && # e with a combining acute (i.e. decomposed) |
| 1209 | utf8_emoji=$(printf "\360\237\221\250") && |
| 1210 | |
| 1211 | # replacement character when requesting a wide char fits in a single display colum. |
| 1212 | # "half wide" alternative could be a plain ASCII dot `.` |
| 1213 | utf8_vert_ell=$(printf "\342\213\256") && |
| 1214 | |
| 1215 | # use ${xxx} here! |
| 1216 | nfc10="${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}" && |
| 1217 | nfd10="${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}" && |
| 1218 | emoji5="${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}" && |
| 1219 | # emoji5 uses 10 display columns |
| 1220 | |
| 1221 | test_commit "abcdefghij" && |
| 1222 | test_commit --no-tag "${nfc10}" && |
| 1223 | test_commit --no-tag "${nfd10}" && |
| 1224 | test_commit --no-tag "${emoji5}" && |
| 1225 | printf "${utf8_emoji}..${utf8_emoji}${utf8_vert_ell}\n${utf8_nfd}..${utf8_nfd}${utf8_nfd}\n${utf8_nfc}..${utf8_nfc}${utf8_nfc}\na..ij\n" >expected && |
| 1226 | git log --format="%<(5,mtrunc)%s" -4 >actual && |
| 1227 | test_cmp expected actual |
| 1228 | ' |
| 1229 | |
| 1230 | test_done |