| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006 Junio C Hamano |
| 4 | # |
| 5 | |
| 6 | test_description='Various diff formatting options' |
| 7 | |
| 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
| 11 | . ./test-lib.sh |
| 12 | . "$TEST_DIRECTORY"/lib-diff.sh |
| 13 | |
| 14 | if ! test_have_prereq PERL_TEST_HELPERS |
| 15 | then |
| 16 | skip_all='skipping diff various tests; Perl not available' |
| 17 | test_done |
| 18 | fi |
| 19 | |
| 20 | test_expect_success setup ' |
| 21 | |
| 22 | GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" && |
| 23 | GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" && |
| 24 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && |
| 25 | |
| 26 | mkdir dir && |
| 27 | mkdir dir2 && |
| 28 | test_write_lines 1 2 3 >file0 && |
| 29 | test_write_lines A B >dir/sub && |
| 30 | cat file0 >file2 && |
| 31 | git add file0 file2 dir/sub && |
| 32 | git commit -m Initial && |
| 33 | |
| 34 | git branch initial && |
| 35 | git branch side && |
| 36 | |
| 37 | GIT_AUTHOR_DATE="2006-06-26 00:01:00 +0000" && |
| 38 | GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" && |
| 39 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && |
| 40 | |
| 41 | test_write_lines 4 5 6 >>file0 && |
| 42 | test_write_lines C D >>dir/sub && |
| 43 | rm -f file2 && |
| 44 | git update-index --remove file0 file2 dir/sub && |
| 45 | git commit -m "Second${LF}${LF}This is the second commit." && |
| 46 | |
| 47 | GIT_AUTHOR_DATE="2006-06-26 00:02:00 +0000" && |
| 48 | GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" && |
| 49 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && |
| 50 | |
| 51 | test_write_lines A B C >file1 && |
| 52 | git add file1 && |
| 53 | test_write_lines E F >>dir/sub && |
| 54 | git update-index dir/sub && |
| 55 | git commit -m Third && |
| 56 | |
| 57 | GIT_AUTHOR_DATE="2006-06-26 00:03:00 +0000" && |
| 58 | GIT_COMMITTER_DATE="2006-06-26 00:03:00 +0000" && |
| 59 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && |
| 60 | |
| 61 | git checkout side && |
| 62 | test_write_lines A B C >>file0 && |
| 63 | test_write_lines 1 2 >>dir/sub && |
| 64 | cat dir/sub >file3 && |
| 65 | git add file3 && |
| 66 | git update-index file0 dir/sub && |
| 67 | git commit -m Side && |
| 68 | |
| 69 | GIT_AUTHOR_DATE="2006-06-26 00:04:00 +0000" && |
| 70 | GIT_COMMITTER_DATE="2006-06-26 00:04:00 +0000" && |
| 71 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && |
| 72 | |
| 73 | git checkout main && |
| 74 | git pull -s ours --no-rebase . side && |
| 75 | |
| 76 | GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" && |
| 77 | GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" && |
| 78 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && |
| 79 | |
| 80 | test_write_lines A B C >>file0 && |
| 81 | test_write_lines 1 2 >>dir/sub && |
| 82 | git update-index file0 dir/sub && |
| 83 | |
| 84 | mkdir dir3 && |
| 85 | cp dir/sub dir3/sub && |
| 86 | test-tool chmtime +1 dir3/sub && |
| 87 | |
| 88 | git config log.showroot false && |
| 89 | git commit --amend && |
| 90 | |
| 91 | GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" && |
| 92 | GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" && |
| 93 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && |
| 94 | git checkout -b rearrange initial && |
| 95 | test_write_lines B A >dir/sub && |
| 96 | git add dir/sub && |
| 97 | git commit -m "Rearranged lines in dir/sub" && |
| 98 | git checkout main && |
| 99 | |
| 100 | GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" && |
| 101 | GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" && |
| 102 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && |
| 103 | git checkout -b mode initial && |
| 104 | git update-index --chmod=+x file0 && |
| 105 | git commit -m "update mode" && |
| 106 | git checkout -f main && |
| 107 | |
| 108 | GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" && |
| 109 | GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" && |
| 110 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && |
| 111 | git checkout -b note initial && |
| 112 | git update-index --chmod=+x file2 && |
| 113 | git commit -m "update mode (file2)" && |
| 114 | git notes add -m "note" && |
| 115 | git checkout -f main && |
| 116 | |
| 117 | # Same merge as main, but with parents reversed. Hide it in a |
| 118 | # pseudo-ref to avoid impacting tests with --all. |
| 119 | commit=$(echo reverse | |
| 120 | git commit-tree -p main^2 -p main^1 main^{tree}) && |
| 121 | git update-ref REVERSE $commit && |
| 122 | |
| 123 | git config diff.renames false && |
| 124 | |
| 125 | git show-branch |
| 126 | ' |
| 127 | |
| 128 | : <<\EOF |
| 129 | ! [initial] Initial |
| 130 | * [main] Merge branch 'side' |
| 131 | ! [rearrange] Rearranged lines in dir/sub |
| 132 | ! [side] Side |
| 133 | ---- |
| 134 | + [rearrange] Rearranged lines in dir/sub |
| 135 | - [main] Merge branch 'side' |
| 136 | * + [side] Side |
| 137 | * [main^] Third |
| 138 | * [main~2] Second |
| 139 | +*++ [initial] Initial |
| 140 | EOF |
| 141 | |
| 142 | process_diffs () { |
| 143 | perl -e ' |
| 144 | my $oid_length = length($ARGV[0]); |
| 145 | my $x40 = "[0-9a-f]{40}"; |
| 146 | my $xab = "[0-9a-f]{4,16}"; |
| 147 | my $orx = "[0-9a-f]" x $oid_length; |
| 148 | |
| 149 | sub munge_oid { |
| 150 | my ($oid) = @_; |
| 151 | my $x; |
| 152 | |
| 153 | return "" unless length $oid; |
| 154 | |
| 155 | if ($oid =~ /^(100644|100755|120000)$/) { |
| 156 | return $oid; |
| 157 | } |
| 158 | |
| 159 | if ($oid =~ /^0*$/) { |
| 160 | $x = "0"; |
| 161 | } else { |
| 162 | $x = "f"; |
| 163 | } |
| 164 | |
| 165 | if (length($oid) == 40) { |
| 166 | return $x x $oid_length; |
| 167 | } else { |
| 168 | return $x x length($oid); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | while (<STDIN>) { |
| 173 | s/($orx)/munge_oid($1)/ge; |
| 174 | s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge; |
| 175 | s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge; |
| 176 | s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge; |
| 177 | s/^($x40)($| )/munge_oid($1) . $2/e; |
| 178 | s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge; |
| 179 | print; |
| 180 | } |
| 181 | ' "$ZERO_OID" <"$1" |
| 182 | } |
| 183 | |
| 184 | V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g') |
| 185 | while read magic cmd |
| 186 | do |
| 187 | case "$magic" in |
| 188 | '' | '#'*) |
| 189 | continue ;; |
| 190 | :noellipses) |
| 191 | magic=noellipses |
| 192 | label="$magic-$cmd" |
| 193 | ;; |
| 194 | :*) |
| 195 | BUG "unknown magic $magic" |
| 196 | ;; |
| 197 | *) |
| 198 | cmd="$magic $cmd" |
| 199 | magic= |
| 200 | label="$cmd" |
| 201 | ;; |
| 202 | esac |
| 203 | |
| 204 | test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g') |
| 205 | pfx=$(printf "%04d" $test_count) |
| 206 | expect="$TEST_DIRECTORY/t4013/diff.$test" |
| 207 | actual="$pfx-diff.$test" |
| 208 | |
| 209 | case "$cmd" in |
| 210 | whatchanged | whatchanged" "*) |
| 211 | prereq=!WITH_BREAKING_CHANGES |
| 212 | ;; |
| 213 | *) |
| 214 | prereq=;; |
| 215 | esac |
| 216 | |
| 217 | test_expect_success $prereq "git $cmd # magic is ${magic:-(not used)}" ' |
| 218 | { |
| 219 | echo "$ git $cmd" |
| 220 | |
| 221 | case "$cmd" in |
| 222 | whatchanged | whatchanged" "*) |
| 223 | run="whatchanged --i-still-use-this" |
| 224 | run="$run ${cmd#whatchanged}" ;; |
| 225 | *) |
| 226 | run=$cmd ;; |
| 227 | esac && |
| 228 | case "$magic" in |
| 229 | "") |
| 230 | GIT_PRINT_SHA1_ELLIPSIS=yes git $run ;; |
| 231 | noellipses) |
| 232 | git $run ;; |
| 233 | esac | |
| 234 | sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \ |
| 235 | -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/" |
| 236 | echo "\$" |
| 237 | } >"$actual" && |
| 238 | if test -f "$expect" |
| 239 | then |
| 240 | process_diffs "$actual" >actual && |
| 241 | process_diffs "$expect" >expect && |
| 242 | case $cmd in |
| 243 | *format-patch* | *-stat*) |
| 244 | test_cmp expect actual;; |
| 245 | *) |
| 246 | test_cmp expect actual;; |
| 247 | esac && |
| 248 | rm -f "$actual" actual expect |
| 249 | else |
| 250 | # this is to help developing new tests. |
| 251 | cp "$actual" "$expect" |
| 252 | false |
| 253 | fi |
| 254 | ' |
| 255 | done <<\EOF |
| 256 | diff-tree initial |
| 257 | diff-tree -r initial |
| 258 | diff-tree -r --abbrev initial |
| 259 | diff-tree -r --abbrev=4 initial |
| 260 | diff-tree --root initial |
| 261 | diff-tree --root --abbrev initial |
| 262 | :noellipses diff-tree --root --abbrev initial |
| 263 | diff-tree --root -r initial |
| 264 | diff-tree --root -r --abbrev initial |
| 265 | :noellipses diff-tree --root -r --abbrev initial |
| 266 | diff-tree --root -r --abbrev=4 initial |
| 267 | :noellipses diff-tree --root -r --abbrev=4 initial |
| 268 | diff-tree -p initial |
| 269 | diff-tree --root -p initial |
| 270 | diff-tree --root -p --abbrev=10 initial |
| 271 | diff-tree --root -p --full-index initial |
| 272 | diff-tree --root -p --full-index --abbrev=10 initial |
| 273 | diff-tree --patch-with-stat initial |
| 274 | diff-tree --root --patch-with-stat initial |
| 275 | diff-tree --patch-with-raw initial |
| 276 | diff-tree --root --patch-with-raw initial |
| 277 | |
| 278 | diff-tree --pretty initial |
| 279 | diff-tree --pretty --root initial |
| 280 | diff-tree --pretty -p initial |
| 281 | diff-tree --pretty --stat initial |
| 282 | diff-tree --pretty --summary initial |
| 283 | diff-tree --pretty --stat --summary initial |
| 284 | diff-tree --pretty --root -p initial |
| 285 | diff-tree --pretty --root --stat initial |
| 286 | # improved by Timo's patch |
| 287 | diff-tree --pretty --root --summary initial |
| 288 | # improved by Timo's patch |
| 289 | diff-tree --pretty --root --summary -r initial |
| 290 | diff-tree --pretty --root --stat --summary initial |
| 291 | diff-tree --pretty --patch-with-stat initial |
| 292 | diff-tree --pretty --root --patch-with-stat initial |
| 293 | diff-tree --pretty --patch-with-raw initial |
| 294 | diff-tree --pretty --root --patch-with-raw initial |
| 295 | |
| 296 | diff-tree --pretty=oneline initial |
| 297 | diff-tree --pretty=oneline --root initial |
| 298 | diff-tree --pretty=oneline -p initial |
| 299 | diff-tree --pretty=oneline --root -p initial |
| 300 | diff-tree --pretty=oneline --patch-with-stat initial |
| 301 | # improved by Timo's patch |
| 302 | diff-tree --pretty=oneline --root --patch-with-stat initial |
| 303 | diff-tree --pretty=oneline --patch-with-raw initial |
| 304 | diff-tree --pretty=oneline --root --patch-with-raw initial |
| 305 | |
| 306 | diff-tree --pretty side |
| 307 | diff-tree --pretty -p side |
| 308 | diff-tree --pretty --patch-with-stat side |
| 309 | |
| 310 | diff-tree initial mode |
| 311 | diff-tree --stat initial mode |
| 312 | diff-tree --summary initial mode |
| 313 | |
| 314 | diff-tree main |
| 315 | diff-tree -m main |
| 316 | diff-tree -p main |
| 317 | diff-tree -p -m main |
| 318 | diff-tree -c main |
| 319 | diff-tree -c --abbrev main |
| 320 | :noellipses diff-tree -c --abbrev main |
| 321 | diff-tree --cc main |
| 322 | # stat only should show the diffstat with the first parent |
| 323 | diff-tree -c --stat main |
| 324 | diff-tree --cc --stat main |
| 325 | diff-tree -c --stat --summary main |
| 326 | diff-tree --cc --stat --summary main |
| 327 | # stat summary should show the diffstat and summary with the first parent |
| 328 | diff-tree -c --stat --summary side |
| 329 | diff-tree --cc --stat --summary side |
| 330 | diff-tree --cc --shortstat main |
| 331 | diff-tree --cc --summary REVERSE |
| 332 | # improved by Timo's patch |
| 333 | diff-tree --cc --patch-with-stat main |
| 334 | # improved by Timo's patch |
| 335 | diff-tree --cc --patch-with-stat --summary main |
| 336 | # this is correct |
| 337 | diff-tree --cc --patch-with-stat --summary side |
| 338 | |
| 339 | log main |
| 340 | log -p main |
| 341 | log --root main |
| 342 | log --root -p main |
| 343 | log --patch-with-stat main |
| 344 | log --root --patch-with-stat main |
| 345 | log --root --patch-with-stat --summary main |
| 346 | # improved by Timo's patch |
| 347 | log --root -c --patch-with-stat --summary main |
| 348 | # improved by Timo's patch |
| 349 | log --root --cc --patch-with-stat --summary main |
| 350 | log --no-diff-merges -p --first-parent main |
| 351 | log --diff-merges=off -p --first-parent main |
| 352 | log --first-parent --diff-merges=off -p main |
| 353 | log -p --first-parent main |
| 354 | log -p --diff-merges=first-parent main |
| 355 | log --diff-merges=first-parent main |
| 356 | log -m -p --first-parent main |
| 357 | log -m -p main |
| 358 | log --cc -m -p main |
| 359 | log -c -m -p main |
| 360 | log -m --raw main |
| 361 | log -m --stat main |
| 362 | log -SF main |
| 363 | log -S F main |
| 364 | log -SF -p main |
| 365 | log -SF main --max-count=0 |
| 366 | log -SF main --max-count=1 |
| 367 | log -SF main --max-count=2 |
| 368 | log -GF main |
| 369 | log -GF -p main |
| 370 | log -GF -p --pickaxe-all main |
| 371 | log -IA -IB -I1 -I2 -p main |
| 372 | log --decorate --all |
| 373 | log --decorate=full --all |
| 374 | log --decorate --clear-decorations --all |
| 375 | log --decorate=full --clear-decorations --all |
| 376 | |
| 377 | rev-list --parents HEAD |
| 378 | rev-list --children HEAD |
| 379 | |
| 380 | whatchanged main |
| 381 | :noellipses whatchanged main |
| 382 | whatchanged -p main |
| 383 | whatchanged --root main |
| 384 | :noellipses whatchanged --root main |
| 385 | whatchanged --root -p main |
| 386 | whatchanged --patch-with-stat main |
| 387 | whatchanged --root --patch-with-stat main |
| 388 | whatchanged --root --patch-with-stat --summary main |
| 389 | # improved by Timo's patch |
| 390 | whatchanged --root -c --patch-with-stat --summary main |
| 391 | # improved by Timo's patch |
| 392 | whatchanged --root --cc --patch-with-stat --summary main |
| 393 | whatchanged -SF main |
| 394 | :noellipses whatchanged -SF main |
| 395 | whatchanged -SF -p main |
| 396 | |
| 397 | log --patch-with-stat main -- dir/ |
| 398 | whatchanged --patch-with-stat main -- dir/ |
| 399 | log --patch-with-stat --summary main -- dir/ |
| 400 | whatchanged --patch-with-stat --summary main -- dir/ |
| 401 | |
| 402 | show initial |
| 403 | show --root initial |
| 404 | show side |
| 405 | show main |
| 406 | show -c main |
| 407 | show -m main |
| 408 | show --first-parent main |
| 409 | show --stat side |
| 410 | show --stat --summary side |
| 411 | show --patch-with-stat side |
| 412 | show --patch-with-raw side |
| 413 | :noellipses show --patch-with-raw side |
| 414 | show --patch-with-stat --summary side |
| 415 | |
| 416 | format-patch --stdout initial..side |
| 417 | format-patch --stdout initial..main^ |
| 418 | format-patch --stdout initial..main |
| 419 | format-patch --stdout --no-numbered initial..main |
| 420 | format-patch --stdout --numbered initial..main |
| 421 | format-patch --attach --stdout initial..side |
| 422 | format-patch --attach --stdout --suffix=.diff initial..side |
| 423 | format-patch --attach --stdout initial..main^ |
| 424 | format-patch --attach --stdout initial..main |
| 425 | format-patch --inline --stdout initial..side |
| 426 | format-patch --inline --stdout initial..main^ |
| 427 | format-patch --inline --stdout --numbered-files initial..main |
| 428 | format-patch --inline --stdout initial..main |
| 429 | format-patch --inline --stdout --subject-prefix=TESTCASE initial..main |
| 430 | config format.subjectprefix DIFFERENT_PREFIX |
| 431 | format-patch --inline --stdout initial..main^^ |
| 432 | format-patch --stdout --cover-letter -n initial..main^ |
| 433 | |
| 434 | diff --abbrev initial..side |
| 435 | diff -U initial..side |
| 436 | diff -U1 initial..side |
| 437 | diff -r initial..side |
| 438 | diff --stat initial..side |
| 439 | diff -r --stat initial..side |
| 440 | diff initial..side |
| 441 | diff --patch-with-stat initial..side |
| 442 | diff --patch-with-raw initial..side |
| 443 | :noellipses diff --patch-with-raw initial..side |
| 444 | diff --patch-with-stat -r initial..side |
| 445 | diff --patch-with-raw -r initial..side |
| 446 | :noellipses diff --patch-with-raw -r initial..side |
| 447 | diff --name-status dir2 dir |
| 448 | diff --no-index --name-status dir2 dir |
| 449 | diff --no-index --name-status -- dir2 dir |
| 450 | diff --no-index dir dir3 |
| 451 | diff main main^ side |
| 452 | # Can't use spaces... |
| 453 | diff --line-prefix=abc main main^ side |
| 454 | diff --dirstat main~1 main~2 |
| 455 | diff --dirstat initial rearrange |
| 456 | diff --dirstat-by-file initial rearrange |
| 457 | diff --dirstat --cc main~1 main |
| 458 | # No-index --abbrev and --no-abbrev |
| 459 | diff --raw initial |
| 460 | :noellipses diff --raw initial |
| 461 | diff --raw --abbrev=4 initial |
| 462 | :noellipses diff --raw --abbrev=4 initial |
| 463 | diff --raw --no-abbrev initial |
| 464 | diff --no-index --raw dir2 dir |
| 465 | :noellipses diff --no-index --raw dir2 dir |
| 466 | diff --no-index --raw --abbrev=4 dir2 dir |
| 467 | :noellipses diff --no-index --raw --abbrev=4 dir2 dir |
| 468 | diff --no-index --raw --no-abbrev dir2 dir |
| 469 | |
| 470 | diff-tree --pretty --root --stat --compact-summary initial |
| 471 | diff-tree --pretty -R --root --stat --compact-summary initial |
| 472 | diff-tree --pretty note |
| 473 | diff-tree --pretty --notes note |
| 474 | diff-tree --format=%N note |
| 475 | diff-tree --stat --compact-summary initial mode |
| 476 | diff-tree -R --stat --compact-summary initial mode |
| 477 | EOF |
| 478 | |
| 479 | test_expect_success !WITH_BREAKING_CHANGES 'whatchanged needs --i-still-use-this' ' |
| 480 | test_must_fail git whatchanged >message 2>&1 && |
| 481 | test_grep "nominated for removal" message |
| 482 | ' |
| 483 | |
| 484 | test_expect_success 'log -m matches pure log' ' |
| 485 | git log main >result && |
| 486 | process_diffs result >expected && |
| 487 | git log -m >result && |
| 488 | process_diffs result >actual && |
| 489 | test_cmp expected actual |
| 490 | ' |
| 491 | |
| 492 | test_expect_success 'log --diff-merges=on matches --diff-merges=separate' ' |
| 493 | git log -p --diff-merges=separate main >result && |
| 494 | process_diffs result >expected && |
| 495 | git log -p --diff-merges=on main >result && |
| 496 | process_diffs result >actual && |
| 497 | test_cmp expected actual |
| 498 | ' |
| 499 | |
| 500 | test_expect_success 'log --dd matches --diff-merges=1 -p' ' |
| 501 | git log --diff-merges=1 -p main >result && |
| 502 | process_diffs result >expected && |
| 503 | git log --dd main >result && |
| 504 | process_diffs result >actual && |
| 505 | test_cmp expected actual |
| 506 | ' |
| 507 | |
| 508 | test_expect_success 'deny wrong log.diffMerges config' ' |
| 509 | test_config log.diffMerges wrong-value && |
| 510 | test_expect_code 128 git log |
| 511 | ' |
| 512 | |
| 513 | test_expect_success 'git config log.diffMerges first-parent' ' |
| 514 | git log -p --diff-merges=first-parent main >result && |
| 515 | process_diffs result >expected && |
| 516 | test_config log.diffMerges first-parent && |
| 517 | git log -p --diff-merges=on main >result && |
| 518 | process_diffs result >actual && |
| 519 | test_cmp expected actual |
| 520 | ' |
| 521 | |
| 522 | test_expect_success 'git config log.diffMerges first-parent vs -m' ' |
| 523 | git log -p --diff-merges=first-parent main >result && |
| 524 | process_diffs result >expected && |
| 525 | test_config log.diffMerges first-parent && |
| 526 | git log -p -m main >result && |
| 527 | process_diffs result >actual && |
| 528 | test_cmp expected actual |
| 529 | ' |
| 530 | |
| 531 | # -m in "git diff-index" means "match missing", that differs |
| 532 | # from its meaning in "git diff". Let's check it in diff-index. |
| 533 | # The line in the output for removed file should disappear when |
| 534 | # we provide -m in diff-index. |
| 535 | test_expect_success 'git diff-index -m' ' |
| 536 | rm -f file1 && |
| 537 | git diff-index HEAD >without-m && |
| 538 | lines_count=$(wc -l <without-m) && |
| 539 | git diff-index -m HEAD >with-m && |
| 540 | git restore file1 && |
| 541 | test_line_count = $((lines_count - 1)) with-m |
| 542 | ' |
| 543 | |
| 544 | test_expect_success 'log -S requires an argument' ' |
| 545 | test_must_fail git log -S |
| 546 | ' |
| 547 | |
| 548 | test_expect_success 'diff --cached on unborn branch' ' |
| 549 | git symbolic-ref HEAD refs/heads/unborn && |
| 550 | git diff --cached >result && |
| 551 | process_diffs result >actual && |
| 552 | process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected && |
| 553 | test_cmp expected actual |
| 554 | ' |
| 555 | |
| 556 | test_expect_success 'diff --cached -- file on unborn branch' ' |
| 557 | git diff --cached -- file0 >result && |
| 558 | process_diffs result >actual && |
| 559 | process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected && |
| 560 | test_cmp expected actual |
| 561 | ' |
| 562 | test_expect_success 'diff --line-prefix with spaces' ' |
| 563 | git diff --line-prefix="| | | " --cached -- file0 >result && |
| 564 | process_diffs result >actual && |
| 565 | process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected && |
| 566 | test_cmp expected actual |
| 567 | ' |
| 568 | |
| 569 | test_expect_success 'diff-tree --stdin with log formatting' ' |
| 570 | cat >expect <<-\EOF && |
| 571 | Side |
| 572 | Third |
| 573 | Second |
| 574 | EOF |
| 575 | git rev-list main | git diff-tree --stdin --format=%s -s >actual && |
| 576 | test_cmp expect actual |
| 577 | ' |
| 578 | |
| 579 | test_expect_success 'diff-tree --stdin with pathspec' ' |
| 580 | cat >expect <<-EOF && |
| 581 | Third |
| 582 | |
| 583 | dir/sub |
| 584 | Second |
| 585 | |
| 586 | dir/sub |
| 587 | EOF |
| 588 | git rev-list main^ | |
| 589 | git diff-tree -r --stdin --name-only --format=%s dir >actual && |
| 590 | test_cmp expect actual |
| 591 | ' |
| 592 | |
| 593 | test_expect_success 'show A B ... -- <pathspec>' ' |
| 594 | # side touches dir/sub, file0, and file3 |
| 595 | # main^ touches dir/sub, and file1 |
| 596 | # main^^ touches dir/sub, file0, and file2 |
| 597 | git show --name-only --format="<%s>" side main^ main^^ -- dir >actual && |
| 598 | cat >expect <<-\EOF && |
| 599 | <Side> |
| 600 | |
| 601 | dir/sub |
| 602 | <Third> |
| 603 | |
| 604 | dir/sub |
| 605 | <Second> |
| 606 | |
| 607 | dir/sub |
| 608 | EOF |
| 609 | test_cmp expect actual |
| 610 | ' |
| 611 | |
| 612 | test_expect_success 'diff -I<regex>: setup' ' |
| 613 | git checkout main && |
| 614 | test_seq 50 >file0 && |
| 615 | git commit -m "Set up -I<regex> test file" file0 && |
| 616 | test_seq 50 | sed -e "s/13/ten and three/" -e "/7\$/d" >file0 && |
| 617 | echo >>file0 |
| 618 | ' |
| 619 | test_expect_success 'diff -I<regex>' ' |
| 620 | git diff --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual && |
| 621 | cat >expect <<-\EOF && |
| 622 | diff --git a/file0 b/file0 |
| 623 | --- a/file0 |
| 624 | +++ b/file0 |
| 625 | @@ -34,7 +31,6 @@ |
| 626 | 34 |
| 627 | 35 |
| 628 | 36 |
| 629 | -37 |
| 630 | 38 |
| 631 | 39 |
| 632 | 40 |
| 633 | EOF |
| 634 | compare_diff_patch expect actual |
| 635 | ' |
| 636 | |
| 637 | test_expect_success 'diff -I<regex> --stat' ' |
| 638 | git diff --stat --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual && |
| 639 | cat >expect <<-\EOF && |
| 640 | file0 | 1 - |
| 641 | 1 file changed, 1 deletion(-) |
| 642 | EOF |
| 643 | test_cmp expect actual |
| 644 | ' |
| 645 | |
| 646 | test_expect_success 'diff -I<regex>: detect malformed regex' ' |
| 647 | test_expect_code 129 git diff --ignore-matching-lines="^[124-9" 2>error && |
| 648 | test_grep "invalid regex given to -I: " error |
| 649 | ' |
| 650 | |
| 651 | test_expect_success 'diff -I<regex>: ignore matching file' ' |
| 652 | test_when_finished "git rm -f file1" && |
| 653 | test_seq 50 >file1 && |
| 654 | git add file1 && |
| 655 | test_seq 50 | sed -e "s/13/ten and three/" -e "s/^[124-9].*/& /" >file1 && |
| 656 | |
| 657 | : >actual && |
| 658 | git diff --raw --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >>actual && |
| 659 | git diff --name-only --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >>actual && |
| 660 | git diff --name-status --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >>actual && |
| 661 | test_grep ! "file1" actual |
| 662 | ' |
| 663 | |
| 664 | test_expect_success 'diff -I<regex>: ignore all content changes' ' |
| 665 | test_when_finished "git rm -f file1 file2 file3" && |
| 666 | : >file1 && |
| 667 | git add file1 && |
| 668 | : >file2 && |
| 669 | git add file2 && |
| 670 | : >file3 && |
| 671 | git add file3 && |
| 672 | |
| 673 | rm -f file1 file2 && |
| 674 | mkdir file2 && |
| 675 | echo "A" >file3 && |
| 676 | A_hash=$(git hash-object -w file3) && |
| 677 | echo "B" >file3 && |
| 678 | B_hash=$(git hash-object -w file3) && |
| 679 | cat <<-EOF | git update-index --index-info && |
| 680 | 100644 $A_hash 1 file3 |
| 681 | 100644 $B_hash 2 file3 |
| 682 | EOF |
| 683 | |
| 684 | test_diff_no_content_changes () { |
| 685 | git diff $1 --ignore-blank-lines -I".*" >actual && |
| 686 | test_line_count = 3 actual && |
| 687 | test_grep "file1" actual && |
| 688 | test_grep "file2" actual && |
| 689 | test_grep "file3" actual && |
| 690 | test_grep ! "diff --git" actual |
| 691 | } && |
| 692 | test_diff_no_content_changes "--raw" && |
| 693 | test_diff_no_content_changes "--name-only" && |
| 694 | test_diff_no_content_changes "--name-status" && |
| 695 | |
| 696 | : >actual && |
| 697 | test_must_fail git diff --quiet -I".*" >actual && |
| 698 | test_must_be_empty actual |
| 699 | ' |
| 700 | |
| 701 | # check_prefix <patch> <src> <dst> |
| 702 | # check only lines with paths to avoid dependency on exact oid/contents |
| 703 | check_prefix () { |
| 704 | grep -E '^(diff|---|\+\+\+) ' "$1" >actual.paths && |
| 705 | cat >expect <<-EOF && |
| 706 | diff --git $2 $3 |
| 707 | --- $2 |
| 708 | +++ $3 |
| 709 | EOF |
| 710 | test_cmp expect actual.paths |
| 711 | } |
| 712 | |
| 713 | test_expect_success 'diff-files does not respect diff.noPrefix' ' |
| 714 | git -c diff.noPrefix diff-files -p >actual && |
| 715 | check_prefix actual a/file0 b/file0 |
| 716 | ' |
| 717 | |
| 718 | test_expect_success 'diff-files respects --no-prefix' ' |
| 719 | git diff-files -p --no-prefix >actual && |
| 720 | check_prefix actual file0 file0 |
| 721 | ' |
| 722 | |
| 723 | test_expect_success 'diff respects diff.noPrefix' ' |
| 724 | git -c diff.noPrefix diff >actual && |
| 725 | check_prefix actual file0 file0 |
| 726 | ' |
| 727 | |
| 728 | test_expect_success 'diff --default-prefix overrides diff.noPrefix' ' |
| 729 | git -c diff.noPrefix diff --default-prefix >actual && |
| 730 | check_prefix actual a/file0 b/file0 |
| 731 | ' |
| 732 | |
| 733 | test_expect_success 'diff respects diff.mnemonicPrefix' ' |
| 734 | git -c diff.mnemonicPrefix diff >actual && |
| 735 | check_prefix actual i/file0 w/file0 |
| 736 | ' |
| 737 | |
| 738 | test_expect_success 'diff --default-prefix overrides diff.mnemonicPrefix' ' |
| 739 | git -c diff.mnemonicPrefix diff --default-prefix >actual && |
| 740 | check_prefix actual a/file0 b/file0 |
| 741 | ' |
| 742 | |
| 743 | test_expect_success 'diff respects diff.srcPrefix' ' |
| 744 | git -c diff.srcPrefix=x/ diff >actual && |
| 745 | check_prefix actual x/file0 b/file0 |
| 746 | ' |
| 747 | |
| 748 | test_expect_success 'diff respects diff.dstPrefix' ' |
| 749 | git -c diff.dstPrefix=y/ diff >actual && |
| 750 | check_prefix actual a/file0 y/file0 |
| 751 | ' |
| 752 | |
| 753 | test_expect_success 'diff --src-prefix overrides diff.srcPrefix' ' |
| 754 | git -c diff.srcPrefix=y/ diff --src-prefix=z/ >actual && |
| 755 | check_prefix actual z/file0 b/file0 |
| 756 | ' |
| 757 | |
| 758 | test_expect_success 'diff --dst-prefix overrides diff.dstPrefix' ' |
| 759 | git -c diff.dstPrefix=y/ diff --dst-prefix=z/ >actual && |
| 760 | check_prefix actual a/file0 z/file0 |
| 761 | ' |
| 762 | |
| 763 | test_expect_success 'diff.{src,dst}Prefix ignored with diff.noPrefix' ' |
| 764 | git -c diff.dstPrefix=y/ -c diff.srcPrefix=x/ -c diff.noPrefix diff >actual && |
| 765 | check_prefix actual file0 file0 |
| 766 | ' |
| 767 | |
| 768 | test_expect_success 'diff.{src,dst}Prefix ignored with diff.mnemonicPrefix' ' |
| 769 | git -c diff.dstPrefix=x/ -c diff.srcPrefix=y/ -c diff.mnemonicPrefix diff >actual && |
| 770 | check_prefix actual i/file0 w/file0 |
| 771 | ' |
| 772 | |
| 773 | test_expect_success 'diff.{src,dst}Prefix ignored with --default-prefix' ' |
| 774 | git -c diff.dstPrefix=x/ -c diff.srcPrefix=y/ diff --default-prefix >actual && |
| 775 | check_prefix actual a/file0 b/file0 |
| 776 | ' |
| 777 | |
| 778 | test_expect_success 'diff --no-renames cannot be abbreviated' ' |
| 779 | test_expect_code 129 git diff --no-rename >actual 2>error && |
| 780 | test_must_be_empty actual && |
| 781 | test_grep "invalid option: --no-rename" error |
| 782 | ' |
| 783 | |
| 784 | test_done |