Git fork
at reftables-rust 577 lines 12 kB view raw
1#!/bin/sh 2# 3# Copyright (c) 2023 Teng Long 4# 5 6test_description='Test commit notes with stripspace behavior' 7 8. ./test-lib.sh 9 10MULTI_LF="$LF$LF$LF" 11write_script fake_editor <<\EOF 12echo "$MSG" >"$1" 13echo "$MSG" >&2 14EOF 15GIT_EDITOR=./fake_editor 16export GIT_EDITOR 17 18test_expect_success 'setup the commit' ' 19 test_commit 1st 20' 21 22test_expect_success 'add note by editor' ' 23 test_when_finished "git notes remove" && 24 cat >expect <<-EOF && 25 first-line 26 27 second-line 28 EOF 29 30 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add && 31 git notes show >actual && 32 test_cmp expect actual 33' 34 35test_expect_success 'add note by specifying single "-m", "--stripspace" is the default behavior' ' 36 test_when_finished "git notes remove" && 37 cat >expect <<-EOF && 38 first-line 39 40 second-line 41 EOF 42 43 git notes add -m "${LF}first-line${MULTI_LF}second-line${LF}" && 44 git notes show >actual && 45 test_cmp expect actual && 46 git notes remove && 47 git notes add --stripspace -m "${LF}first-line${MULTI_LF}second-line${LF}" && 48 git notes show >actual && 49 test_cmp expect actual 50' 51 52test_expect_success 'add note by specifying single "-m" and "--no-stripspace" ' ' 53 test_when_finished "git notes remove" && 54 cat >expect <<-EOF && 55 ${LF}first-line${MULTI_LF}second-line 56 EOF 57 58 git notes add --no-stripspace \ 59 -m "${LF}first-line${MULTI_LF}second-line${LF}" && 60 git notes show >actual && 61 test_cmp expect actual 62' 63 64test_expect_success 'add note by specifying multiple "-m", "--stripspace" is the default behavior' ' 65 test_when_finished "git notes remove" && 66 cat >expect <<-EOF && 67 first-line 68 69 second-line 70 EOF 71 72 git notes add -m "${LF}" \ 73 -m "first-line" \ 74 -m "${MULTI_LF}" \ 75 -m "second-line" \ 76 -m "${LF}" && 77 git notes show >actual && 78 test_cmp expect actual && 79 git notes remove && 80 git notes add --stripspace -m "${LF}" \ 81 -m "first-line" \ 82 -m "${MULTI_LF}" \ 83 -m "second-line" \ 84 -m "${LF}" && 85 git notes show >actual && 86 test_cmp expect actual 87' 88 89test_expect_success 'add notes by specifying multiple "-m" and "--no-stripspace"' ' 90 test_when_finished "git notes remove" && 91 cat >expect <<-EOF && 92 ${LF} 93 first-line 94 ${MULTI_LF} 95 second-line${LF} 96 EOF 97 98 git notes add --no-stripspace \ 99 -m "${LF}" \ 100 -m "first-line" \ 101 -m "${MULTI_LF}" \ 102 -m "second-line" \ 103 -m "${LF}" && 104 git notes show >actual && 105 test_cmp expect actual 106' 107 108test_expect_success 'add note by specifying single "-F", "--stripspace" is the default behavior' ' 109 test_when_finished "git notes remove" && 110 cat >expect <<-EOF && 111 first-line 112 113 second-line 114 EOF 115 116 cat >note-file <<-EOF && 117 ${LF} 118 first-line 119 ${MULTI_LF} 120 second-line 121 ${LF} 122 EOF 123 124 git notes add -F note-file && 125 git notes show >actual && 126 test_cmp expect actual && 127 git notes remove && 128 git notes add --stripspace -F note-file && 129 git notes show >actual 130' 131 132test_expect_success 'add note by specifying single "-F" and "--no-stripspace"' ' 133 test_when_finished "git notes remove" && 134 cat >expect <<-EOF && 135 ${LF} 136 first-line 137 ${MULTI_LF} 138 second-line 139 ${LF} 140 EOF 141 142 cat >note-file <<-EOF && 143 ${LF} 144 first-line 145 ${MULTI_LF} 146 second-line 147 ${LF} 148 EOF 149 150 git notes add --no-stripspace -F note-file && 151 git notes show >actual && 152 test_cmp expect actual 153' 154 155test_expect_success 'add note by specifying multiple "-F", "--stripspace" is the default behavior' ' 156 test_when_finished "git notes remove" && 157 cat >expect <<-EOF && 158 file-1-first-line 159 160 file-1-second-line 161 162 file-2-first-line 163 164 file-2-second-line 165 EOF 166 167 cat >note-file-1 <<-EOF && 168 ${LF} 169 file-1-first-line 170 ${MULTI_LF} 171 file-1-second-line 172 ${LF} 173 EOF 174 175 cat >note-file-2 <<-EOF && 176 ${LF} 177 file-2-first-line 178 ${MULTI_LF} 179 file-2-second-line 180 ${LF} 181 EOF 182 183 git notes add -F note-file-1 -F note-file-2 && 184 git notes show >actual && 185 test_cmp expect actual && 186 git notes remove && 187 git notes add --stripspace -F note-file-1 -F note-file-2 && 188 git notes show >actual && 189 test_cmp expect actual 190' 191 192test_expect_success 'add note by specifying multiple "-F" with "--no-stripspace"' ' 193 test_when_finished "git notes remove" && 194 cat >expect <<-EOF && 195 ${LF} 196 file-1-first-line 197 ${MULTI_LF} 198 file-1-second-line 199 ${LF} 200 201 ${LF} 202 file-2-first-line 203 ${MULTI_LF} 204 file-2-second-line 205 ${LF} 206 EOF 207 208 cat >note-file-1 <<-EOF && 209 ${LF} 210 file-1-first-line 211 ${MULTI_LF} 212 file-1-second-line 213 ${LF} 214 EOF 215 216 cat >note-file-2 <<-EOF && 217 ${LF} 218 file-2-first-line 219 ${MULTI_LF} 220 file-2-second-line 221 ${LF} 222 EOF 223 224 git notes add --no-stripspace -F note-file-1 -F note-file-2 && 225 git notes show >actual && 226 test_cmp expect actual 227' 228 229test_expect_success 'append note by editor' ' 230 test_when_finished "git notes remove" && 231 cat >expect <<-EOF && 232 first-line 233 234 second-line 235 EOF 236 237 git notes add -m "first-line" && 238 MSG="${MULTI_LF}second-line${LF}" git notes append && 239 git notes show >actual && 240 test_cmp expect actual 241' 242 243test_expect_success 'append note by specifying single "-m"' ' 244 test_when_finished "git notes remove" && 245 cat >expect <<-EOF && 246 first-line 247 248 second-line 249 EOF 250 251 git notes add -m "${LF}first-line" && 252 git notes append -m "${MULTI_LF}second-line${LF}" && 253 git notes show >actual && 254 test_cmp expect actual 255' 256 257test_expect_success 'append note by specifying multiple "-m"' ' 258 test_when_finished "git notes remove" && 259 cat >expect <<-EOF && 260 first-line 261 262 second-line 263 EOF 264 265 git notes add -m "${LF}first-line" && 266 git notes append -m "${MULTI_LF}" \ 267 -m "second-line" \ 268 -m "${LF}" && 269 git notes show >actual && 270 test_cmp expect actual 271' 272 273test_expect_success 'add note by specifying single "-F"' ' 274 test_when_finished "git notes remove" && 275 cat >expect <<-EOF && 276 first-line 277 278 second-line 279 EOF 280 281 cat >note-file <<-EOF && 282 ${LF} 283 first-line 284 ${MULTI_LF} 285 second-line 286 ${LF} 287 EOF 288 289 git notes add -F note-file && 290 git notes show >actual && 291 test_cmp expect actual 292' 293 294test_expect_success 'add notes by specifying multiple "-F"' ' 295 test_when_finished "git notes remove" && 296 cat >expect <<-EOF && 297 file-1-first-line 298 299 file-1-second-line 300 301 file-2-first-line 302 303 file-2-second-line 304 EOF 305 306 cat >note-file-1 <<-EOF && 307 ${LF} 308 file-1-first-line 309 ${MULTI_LF} 310 file-1-second-line 311 ${LF} 312 EOF 313 314 cat >note-file-2 <<-EOF && 315 ${LF} 316 file-2-first-line 317 ${MULTI_LF} 318 file-2-second-line 319 ${LF} 320 EOF 321 322 git notes add -F note-file-1 -F note-file-2 && 323 git notes show >actual && 324 test_cmp expect actual 325' 326 327test_expect_success 'append note by specifying single "-F"' ' 328 test_when_finished "git notes remove" && 329 cat >expect <<-EOF && 330 initial-line 331 332 first-line 333 334 second-line 335 EOF 336 337 cat >note-file <<-EOF && 338 ${LF} 339 first-line 340 ${MULTI_LF} 341 second-line 342 ${LF} 343 EOF 344 345 git notes add -m "initial-line" && 346 git notes append -F note-file && 347 git notes show >actual && 348 test_cmp expect actual 349' 350 351test_expect_success 'append notes by specifying multiple "-F"' ' 352 test_when_finished "git notes remove" && 353 cat >expect <<-EOF && 354 initial-line 355 356 file-1-first-line 357 358 file-1-second-line 359 360 file-2-first-line 361 362 file-2-second-line 363 EOF 364 365 cat >note-file-1 <<-EOF && 366 ${LF} 367 file-1-first-line 368 ${MULTI_LF} 369 file-1-second-line 370 ${LF} 371 EOF 372 373 cat >note-file-2 <<-EOF && 374 ${LF} 375 file-2-first-line 376 ${MULTI_LF} 377 file-2-second-line 378 ${LF} 379 EOF 380 381 git notes add -m "initial-line" && 382 git notes append -F note-file-1 -F note-file-2 && 383 git notes show >actual && 384 test_cmp expect actual 385' 386 387test_expect_success 'append note by specifying multiple "-F" with "--no-stripspace"' ' 388 test_when_finished "git notes remove" && 389 cat >expect <<-EOF && 390 initial-line 391 ${LF}${LF} 392 file-1-first-line 393 ${MULTI_LF} 394 file-1-second-line 395 ${LF} 396 397 ${LF} 398 file-2-first-line 399 ${MULTI_LF} 400 file-2-second-line 401 ${LF} 402 EOF 403 404 cat >note-file-1 <<-EOF && 405 ${LF} 406 file-1-first-line 407 ${MULTI_LF} 408 file-1-second-line 409 ${LF} 410 EOF 411 412 cat >note-file-2 <<-EOF && 413 ${LF} 414 file-2-first-line 415 ${MULTI_LF} 416 file-2-second-line 417 ${LF} 418 EOF 419 420 git notes add -m "initial-line" && 421 git notes append --no-stripspace -F note-file-1 -F note-file-2 && 422 git notes show >actual && 423 test_cmp expect actual 424' 425 426test_expect_success 'add notes with empty messages' ' 427 rev=$(git rev-parse HEAD) && 428 git notes add -m "${LF}" \ 429 -m "${MULTI_LF}" \ 430 -m "${LF}" >actual 2>&1 && 431 test_grep "Removing note for object" actual 432' 433 434test_expect_success 'add note by specifying "-C", "--no-stripspace" is the default behavior' ' 435 test_when_finished "git notes remove" && 436 cat >expect <<-EOF && 437 ${LF} 438 first-line 439 ${MULTI_LF} 440 second-line 441 ${LF} 442 EOF 443 444 git hash-object -w --stdin <expect >blob && 445 git notes add -C $(cat blob) && 446 git notes show >actual && 447 test_cmp expect actual && 448 git notes remove && 449 git notes add --no-stripspace -C $(cat blob) && 450 git notes show >actual && 451 test_cmp expect actual 452' 453 454test_expect_success 'reuse note by specifying "-C" and "--stripspace"' ' 455 test_when_finished "git notes remove" && 456 cat >data <<-EOF && 457 ${LF} 458 first-line 459 ${MULTI_LF} 460 second-line 461 ${LF} 462 EOF 463 464 cat >expect <<-EOF && 465 first-line 466 467 second-line 468 EOF 469 470 git hash-object -w --stdin <data >blob && 471 git notes add --stripspace -C $(cat blob) && 472 git notes show >actual && 473 test_cmp expect actual 474' 475 476test_expect_success 'reuse with "-C" and add note with "-m", "-m" will stripspace all together' ' 477 test_when_finished "git notes remove" && 478 cat >data <<-EOF && 479 ${LF} 480 first-line 481 ${MULTI_LF} 482 second-line 483 ${LF} 484 EOF 485 486 cat >expect <<-EOF && 487 first-line 488 489 second-line 490 491 third-line 492 EOF 493 494 git hash-object -w --stdin <data >blob && 495 git notes add -C $(cat blob) -m "third-line" && 496 git notes show >actual && 497 test_cmp expect actual 498' 499 500test_expect_success 'add note with "-m" and reuse note with "-C", "-C" will not stripspace all together' ' 501 test_when_finished "git notes remove" && 502 cat >data <<-EOF && 503 504 second-line 505 EOF 506 507 cat >expect <<-EOF && 508 first-line 509 ${LF} 510 second-line 511 EOF 512 513 git hash-object -w --stdin <data >blob && 514 git notes add -m "first-line" -C $(cat blob) && 515 git notes show >actual && 516 test_cmp expect actual 517' 518 519test_expect_success 'add note by specifying "-c", "--stripspace" is the default behavior' ' 520 test_when_finished "git notes remove" && 521 cat >expect <<-EOF && 522 first-line 523 524 second-line 525 EOF 526 527 echo "initial-line" | git hash-object -w --stdin >blob && 528 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add -c $(cat blob) && 529 git notes show >actual && 530 test_cmp expect actual && 531 git notes remove && 532 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --stripspace -c $(cat blob) && 533 git notes show >actual && 534 test_cmp expect actual 535' 536 537test_expect_success 'add note by specifying "-c" with "--no-stripspace"' ' 538 test_when_finished "git notes remove" && 539 cat >expect <<-EOF && 540 ${LF}first-line${MULTI_LF}second-line${LF} 541 EOF 542 543 echo "initial-line" | git hash-object -w --stdin >blob && 544 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --no-stripspace -c $(cat blob) && 545 git notes show >actual && 546 test_cmp expect actual 547' 548 549test_expect_success 'edit note by specifying "-c", "--stripspace" is the default behavior' ' 550 test_when_finished "git notes remove" && 551 cat >expect <<-EOF && 552 first-line 553 554 second-line 555 EOF 556 557 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes edit && 558 git notes show >actual && 559 test_cmp expect actual && 560 git notes remove && 561 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes edit --stripspace && 562 git notes show >actual && 563 test_cmp expect actual 564' 565 566test_expect_success 'edit note by specifying "-c" with "--no-stripspace"' ' 567 test_when_finished "git notes remove" && 568 cat >expect <<-EOF && 569 ${LF}first-line${MULTI_LF}second-line${LF} 570 EOF 571 572 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --no-stripspace && 573 git notes show >actual && 574 test_cmp expect actual 575' 576 577test_done