t / t4047-diff-dirstat.shon commit t: branch: fix broken && chains (d0423dd)
   1#!/bin/sh
   2
   3test_description='diff --dirstat tests'
   4. ./test-lib.sh
   5
   6# set up two commits where the second commit has these files
   7# (10 lines in each file):
   8#
   9#   unchanged/text           (unchanged from 1st commit)
  10#   changed/text             (changed 1st line)
  11#   rearranged/text          (swapped 1st and 2nd line)
  12#   dst/copy/unchanged/text  (copied from src/copy/unchanged/text, unchanged)
  13#   dst/copy/changed/text    (copied from src/copy/changed/text, changed)
  14#   dst/copy/rearranged/text (copied from src/copy/rearranged/text, rearranged)
  15#   dst/move/unchanged/text  (moved from src/move/unchanged/text, unchanged)
  16#   dst/move/changed/text    (moved from src/move/changed/text, changed)
  17#   dst/move/rearranged/text (moved from src/move/rearranged/text, rearranged)
  18
  19test_expect_success 'setup' '
  20        mkdir unchanged &&
  21        mkdir changed &&
  22        mkdir rearranged &&
  23        mkdir src &&
  24        mkdir src/copy &&
  25        mkdir src/copy/unchanged &&
  26        mkdir src/copy/changed &&
  27        mkdir src/copy/rearranged &&
  28        mkdir src/move &&
  29        mkdir src/move/unchanged &&
  30        mkdir src/move/changed &&
  31        mkdir src/move/rearranged &&
  32        cat <<EOF >unchanged/text &&
  33unchanged       line #0
  34unchanged       line #1
  35unchanged       line #2
  36unchanged       line #3
  37unchanged       line #4
  38unchanged       line #5
  39unchanged       line #6
  40unchanged       line #7
  41unchanged       line #8
  42unchanged       line #9
  43EOF
  44        cat <<EOF >changed/text &&
  45changed         line #0
  46changed         line #1
  47changed         line #2
  48changed         line #3
  49changed         line #4
  50changed         line #5
  51changed         line #6
  52changed         line #7
  53changed         line #8
  54changed         line #9
  55EOF
  56        cat <<EOF >rearranged/text &&
  57rearranged      line #0
  58rearranged      line #1
  59rearranged      line #2
  60rearranged      line #3
  61rearranged      line #4
  62rearranged      line #5
  63rearranged      line #6
  64rearranged      line #7
  65rearranged      line #8
  66rearranged      line #9
  67EOF
  68        cat <<EOF >src/copy/unchanged/text &&
  69copy  unchanged line #0
  70copy  unchanged line #1
  71copy  unchanged line #2
  72copy  unchanged line #3
  73copy  unchanged line #4
  74copy  unchanged line #5
  75copy  unchanged line #6
  76copy  unchanged line #7
  77copy  unchanged line #8
  78copy  unchanged line #9
  79EOF
  80        cat <<EOF >src/copy/changed/text &&
  81copy    changed line #0
  82copy    changed line #1
  83copy    changed line #2
  84copy    changed line #3
  85copy    changed line #4
  86copy    changed line #5
  87copy    changed line #6
  88copy    changed line #7
  89copy    changed line #8
  90copy    changed line #9
  91EOF
  92        cat <<EOF >src/copy/rearranged/text &&
  93copy rearranged line #0
  94copy rearranged line #1
  95copy rearranged line #2
  96copy rearranged line #3
  97copy rearranged line #4
  98copy rearranged line #5
  99copy rearranged line #6
 100copy rearranged line #7
 101copy rearranged line #8
 102copy rearranged line #9
 103EOF
 104        cat <<EOF >src/move/unchanged/text &&
 105move  unchanged line #0
 106move  unchanged line #1
 107move  unchanged line #2
 108move  unchanged line #3
 109move  unchanged line #4
 110move  unchanged line #5
 111move  unchanged line #6
 112move  unchanged line #7
 113move  unchanged line #8
 114move  unchanged line #9
 115EOF
 116        cat <<EOF >src/move/changed/text &&
 117move    changed line #0
 118move    changed line #1
 119move    changed line #2
 120move    changed line #3
 121move    changed line #4
 122move    changed line #5
 123move    changed line #6
 124move    changed line #7
 125move    changed line #8
 126move    changed line #9
 127EOF
 128        cat <<EOF >src/move/rearranged/text &&
 129move rearranged line #0
 130move rearranged line #1
 131move rearranged line #2
 132move rearranged line #3
 133move rearranged line #4
 134move rearranged line #5
 135move rearranged line #6
 136move rearranged line #7
 137move rearranged line #8
 138move rearranged line #9
 139EOF
 140        git add . &&
 141        git commit -m "initial" &&
 142        mkdir dst &&
 143        mkdir dst/copy &&
 144        mkdir dst/copy/unchanged &&
 145        mkdir dst/copy/changed &&
 146        mkdir dst/copy/rearranged &&
 147        mkdir dst/move &&
 148        mkdir dst/move/unchanged &&
 149        mkdir dst/move/changed &&
 150        mkdir dst/move/rearranged &&
 151        cat <<EOF >changed/text &&
 152CHANGED XXXXXXX line #0
 153changed         line #1
 154changed         line #2
 155changed         line #3
 156changed         line #4
 157changed         line #5
 158changed         line #6
 159changed         line #7
 160changed         line #8
 161changed         line #9
 162EOF
 163        cat <<EOF >rearranged/text &&
 164rearranged      line #1
 165rearranged      line #0
 166rearranged      line #2
 167rearranged      line #3
 168rearranged      line #4
 169rearranged      line #5
 170rearranged      line #6
 171rearranged      line #7
 172rearranged      line #8
 173rearranged      line #9
 174EOF
 175        cat <<EOF >dst/copy/unchanged/text &&
 176copy  unchanged line #0
 177copy  unchanged line #1
 178copy  unchanged line #2
 179copy  unchanged line #3
 180copy  unchanged line #4
 181copy  unchanged line #5
 182copy  unchanged line #6
 183copy  unchanged line #7
 184copy  unchanged line #8
 185copy  unchanged line #9
 186EOF
 187        cat <<EOF >dst/copy/changed/text &&
 188copy XXXCHANGED line #0
 189copy    changed line #1
 190copy    changed line #2
 191copy    changed line #3
 192copy    changed line #4
 193copy    changed line #5
 194copy    changed line #6
 195copy    changed line #7
 196copy    changed line #8
 197copy    changed line #9
 198EOF
 199        cat <<EOF >dst/copy/rearranged/text &&
 200copy rearranged line #1
 201copy rearranged line #0
 202copy rearranged line #2
 203copy rearranged line #3
 204copy rearranged line #4
 205copy rearranged line #5
 206copy rearranged line #6
 207copy rearranged line #7
 208copy rearranged line #8
 209copy rearranged line #9
 210EOF
 211        cat <<EOF >dst/move/unchanged/text &&
 212move  unchanged line #0
 213move  unchanged line #1
 214move  unchanged line #2
 215move  unchanged line #3
 216move  unchanged line #4
 217move  unchanged line #5
 218move  unchanged line #6
 219move  unchanged line #7
 220move  unchanged line #8
 221move  unchanged line #9
 222EOF
 223        cat <<EOF >dst/move/changed/text &&
 224move XXXCHANGED line #0
 225move    changed line #1
 226move    changed line #2
 227move    changed line #3
 228move    changed line #4
 229move    changed line #5
 230move    changed line #6
 231move    changed line #7
 232move    changed line #8
 233move    changed line #9
 234EOF
 235        cat <<EOF >dst/move/rearranged/text &&
 236move rearranged line #1
 237move rearranged line #0
 238move rearranged line #2
 239move rearranged line #3
 240move rearranged line #4
 241move rearranged line #5
 242move rearranged line #6
 243move rearranged line #7
 244move rearranged line #8
 245move rearranged line #9
 246EOF
 247        git add . &&
 248        git rm -r src/move/unchanged &&
 249        git rm -r src/move/changed &&
 250        git rm -r src/move/rearranged &&
 251        git commit -m "changes"
 252'
 253
 254cat <<EOF >expect_diff_stat
 2551       1       changed/text
 25610      0       dst/copy/changed/text
 25710      0       dst/copy/rearranged/text
 25810      0       dst/copy/unchanged/text
 25910      0       dst/move/changed/text
 26010      0       dst/move/rearranged/text
 26110      0       dst/move/unchanged/text
 2621       1       rearranged/text
 2630       10      src/move/changed/text
 2640       10      src/move/rearranged/text
 2650       10      src/move/unchanged/text
 266EOF
 267
 268cat <<EOF >expect_diff_stat_M
 2691       1       changed/text
 27010      0       dst/copy/changed/text
 27110      0       dst/copy/rearranged/text
 27210      0       dst/copy/unchanged/text
 2731       1       {src => dst}/move/changed/text
 2741       1       {src => dst}/move/rearranged/text
 2750       0       {src => dst}/move/unchanged/text
 2761       1       rearranged/text
 277EOF
 278
 279cat <<EOF >expect_diff_stat_CC
 2801       1       changed/text
 2811       1       {src => dst}/copy/changed/text
 2821       1       {src => dst}/copy/rearranged/text
 2830       0       {src => dst}/copy/unchanged/text
 2841       1       {src => dst}/move/changed/text
 2851       1       {src => dst}/move/rearranged/text
 2860       0       {src => dst}/move/unchanged/text
 2871       1       rearranged/text
 288EOF
 289
 290test_expect_success 'sanity check setup (--numstat)' '
 291        git diff --numstat HEAD^..HEAD >actual_diff_stat &&
 292        test_cmp expect_diff_stat actual_diff_stat &&
 293        git diff --numstat -M HEAD^..HEAD >actual_diff_stat_M &&
 294        test_cmp expect_diff_stat_M actual_diff_stat_M &&
 295        git diff --numstat -C -C HEAD^..HEAD >actual_diff_stat_CC &&
 296        test_cmp expect_diff_stat_CC actual_diff_stat_CC
 297'
 298
 299# changed/text and rearranged/text falls below default 3% threshold
 300cat <<EOF >expect_diff_dirstat
 301  10.8% dst/copy/changed/
 302  10.8% dst/copy/rearranged/
 303  10.8% dst/copy/unchanged/
 304  10.8% dst/move/changed/
 305  10.8% dst/move/rearranged/
 306  10.8% dst/move/unchanged/
 307  10.8% src/move/changed/
 308  10.8% src/move/rearranged/
 309  10.8% src/move/unchanged/
 310EOF
 311
 312# rearranged/text falls below default 3% threshold
 313cat <<EOF >expect_diff_dirstat_M
 314   5.8% changed/
 315  29.3% dst/copy/changed/
 316  29.3% dst/copy/rearranged/
 317  29.3% dst/copy/unchanged/
 318   5.8% dst/move/changed/
 319EOF
 320
 321# rearranged/text falls below default 3% threshold
 322cat <<EOF >expect_diff_dirstat_CC
 323  32.6% changed/
 324  32.6% dst/copy/changed/
 325  32.6% dst/move/changed/
 326EOF
 327
 328test_expect_success 'various ways to misspell --dirstat' '
 329        test_must_fail git show --dirstat10 &&
 330        test_must_fail git show --dirstat10,files &&
 331        test_must_fail git show -X=20 &&
 332        test_must_fail git show -X=20,cumulative
 333'
 334
 335test_expect_success 'vanilla --dirstat' '
 336        git diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 337        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 338        git diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 339        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 340        git diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 341        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 342'
 343
 344test_expect_success 'vanilla -X' '
 345        git diff -X HEAD^..HEAD >actual_diff_dirstat &&
 346        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 347        git diff -X -M HEAD^..HEAD >actual_diff_dirstat_M &&
 348        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 349        git diff -X -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 350        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 351'
 352
 353test_expect_success 'explicit defaults: --dirstat=changes,noncumulative,3' '
 354        git diff --dirstat=changes,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
 355        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 356        git diff --dirstat=changes,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 357        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 358        git diff --dirstat=changes,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 359        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 360'
 361
 362test_expect_success 'explicit defaults: -Xchanges,noncumulative,3' '
 363        git diff -Xchanges,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
 364        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 365        git diff -Xchanges,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 366        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 367        git diff -Xchanges,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 368        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 369'
 370
 371test_expect_success 'later options override earlier options:' '
 372        git diff --dirstat=files,10,cumulative,changes,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
 373        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 374        git diff --dirstat=files,10,cumulative,changes,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 375        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 376        git diff --dirstat=files,10,cumulative,changes,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 377        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 378        git diff --dirstat=files --dirstat=10 --dirstat=cumulative --dirstat=changes --dirstat=noncumulative -X3 HEAD^..HEAD >actual_diff_dirstat &&
 379        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 380        git diff --dirstat=files --dirstat=10 --dirstat=cumulative --dirstat=changes --dirstat=noncumulative -X3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 381        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 382        git diff --dirstat=files --dirstat=10 --dirstat=cumulative --dirstat=changes --dirstat=noncumulative -X3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 383        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 384'
 385
 386test_expect_success 'non-defaults in config overridden by explicit defaults on command line' '
 387        git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
 388        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 389        git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 390        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 391        git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 392        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 393'
 394
 395cat <<EOF >expect_diff_dirstat
 396   2.1% changed/
 397  10.8% dst/copy/changed/
 398  10.8% dst/copy/rearranged/
 399  10.8% dst/copy/unchanged/
 400  10.8% dst/move/changed/
 401  10.8% dst/move/rearranged/
 402  10.8% dst/move/unchanged/
 403   0.0% rearranged/
 404  10.8% src/move/changed/
 405  10.8% src/move/rearranged/
 406  10.8% src/move/unchanged/
 407EOF
 408
 409cat <<EOF >expect_diff_dirstat_M
 410   5.8% changed/
 411  29.3% dst/copy/changed/
 412  29.3% dst/copy/rearranged/
 413  29.3% dst/copy/unchanged/
 414   5.8% dst/move/changed/
 415   0.1% dst/move/rearranged/
 416   0.1% rearranged/
 417EOF
 418
 419cat <<EOF >expect_diff_dirstat_CC
 420  32.6% changed/
 421  32.6% dst/copy/changed/
 422   0.6% dst/copy/rearranged/
 423  32.6% dst/move/changed/
 424   0.6% dst/move/rearranged/
 425   0.6% rearranged/
 426EOF
 427
 428test_expect_success '--dirstat=0' '
 429        git diff --dirstat=0 HEAD^..HEAD >actual_diff_dirstat &&
 430        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 431        git diff --dirstat=0 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 432        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 433        git diff --dirstat=0 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 434        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 435'
 436
 437test_expect_success '-X0' '
 438        git diff -X0 HEAD^..HEAD >actual_diff_dirstat &&
 439        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 440        git diff -X0 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 441        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 442        git diff -X0 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 443        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 444'
 445
 446test_expect_success 'diff.dirstat=0' '
 447        git -c diff.dirstat=0 diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 448        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 449        git -c diff.dirstat=0 diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 450        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 451        git -c diff.dirstat=0 diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 452        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 453'
 454
 455cat <<EOF >expect_diff_dirstat
 456   2.1% changed/
 457  10.8% dst/copy/changed/
 458  10.8% dst/copy/rearranged/
 459  10.8% dst/copy/unchanged/
 460  32.5% dst/copy/
 461  10.8% dst/move/changed/
 462  10.8% dst/move/rearranged/
 463  10.8% dst/move/unchanged/
 464  32.5% dst/move/
 465  65.1% dst/
 466   0.0% rearranged/
 467  10.8% src/move/changed/
 468  10.8% src/move/rearranged/
 469  10.8% src/move/unchanged/
 470  32.5% src/move/
 471EOF
 472
 473cat <<EOF >expect_diff_dirstat_M
 474   5.8% changed/
 475  29.3% dst/copy/changed/
 476  29.3% dst/copy/rearranged/
 477  29.3% dst/copy/unchanged/
 478  88.0% dst/copy/
 479   5.8% dst/move/changed/
 480   0.1% dst/move/rearranged/
 481   5.9% dst/move/
 482  94.0% dst/
 483   0.1% rearranged/
 484EOF
 485
 486cat <<EOF >expect_diff_dirstat_CC
 487  32.6% changed/
 488  32.6% dst/copy/changed/
 489   0.6% dst/copy/rearranged/
 490  33.3% dst/copy/
 491  32.6% dst/move/changed/
 492   0.6% dst/move/rearranged/
 493  33.3% dst/move/
 494  66.6% dst/
 495   0.6% rearranged/
 496EOF
 497
 498test_expect_success '--dirstat=0 --cumulative' '
 499        git diff --dirstat=0 --cumulative HEAD^..HEAD >actual_diff_dirstat &&
 500        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 501        git diff --dirstat=0 --cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 502        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 503        git diff --dirstat=0 --cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 504        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 505'
 506
 507test_expect_success '--dirstat=0,cumulative' '
 508        git diff --dirstat=0,cumulative HEAD^..HEAD >actual_diff_dirstat &&
 509        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 510        git diff --dirstat=0,cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 511        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 512        git diff --dirstat=0,cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 513        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 514'
 515
 516test_expect_success '-X0,cumulative' '
 517        git diff -X0,cumulative HEAD^..HEAD >actual_diff_dirstat &&
 518        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 519        git diff -X0,cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 520        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 521        git diff -X0,cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 522        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 523'
 524
 525test_expect_success 'diff.dirstat=0,cumulative' '
 526        git -c diff.dirstat=0,cumulative diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 527        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 528        git -c diff.dirstat=0,cumulative diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 529        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 530        git -c diff.dirstat=0,cumulative diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 531        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 532'
 533
 534test_expect_success 'diff.dirstat=0 & --dirstat=cumulative' '
 535        git -c diff.dirstat=0 diff --dirstat=cumulative HEAD^..HEAD >actual_diff_dirstat &&
 536        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 537        git -c diff.dirstat=0 diff --dirstat=cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 538        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 539        git -c diff.dirstat=0 diff --dirstat=cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 540        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 541'
 542
 543cat <<EOF >expect_diff_dirstat
 544   9.0% changed/
 545   9.0% dst/copy/changed/
 546   9.0% dst/copy/rearranged/
 547   9.0% dst/copy/unchanged/
 548   9.0% dst/move/changed/
 549   9.0% dst/move/rearranged/
 550   9.0% dst/move/unchanged/
 551   9.0% rearranged/
 552   9.0% src/move/changed/
 553   9.0% src/move/rearranged/
 554   9.0% src/move/unchanged/
 555EOF
 556
 557cat <<EOF >expect_diff_dirstat_M
 558  14.2% changed/
 559  14.2% dst/copy/changed/
 560  14.2% dst/copy/rearranged/
 561  14.2% dst/copy/unchanged/
 562  14.2% dst/move/changed/
 563  14.2% dst/move/rearranged/
 564  14.2% rearranged/
 565EOF
 566
 567cat <<EOF >expect_diff_dirstat_CC
 568  16.6% changed/
 569  16.6% dst/copy/changed/
 570  16.6% dst/copy/rearranged/
 571  16.6% dst/move/changed/
 572  16.6% dst/move/rearranged/
 573  16.6% rearranged/
 574EOF
 575
 576test_expect_success '--dirstat-by-file' '
 577        git diff --dirstat-by-file HEAD^..HEAD >actual_diff_dirstat &&
 578        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 579        git diff --dirstat-by-file -M HEAD^..HEAD >actual_diff_dirstat_M &&
 580        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 581        git diff --dirstat-by-file -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 582        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 583'
 584
 585test_expect_success '--dirstat=files' '
 586        git diff --dirstat=files HEAD^..HEAD >actual_diff_dirstat &&
 587        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 588        git diff --dirstat=files -M HEAD^..HEAD >actual_diff_dirstat_M &&
 589        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 590        git diff --dirstat=files -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 591        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 592'
 593
 594test_expect_success 'diff.dirstat=files' '
 595        git -c diff.dirstat=files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 596        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 597        git -c diff.dirstat=files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 598        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 599        git -c diff.dirstat=files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 600        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 601'
 602
 603cat <<EOF >expect_diff_dirstat
 604  27.2% dst/copy/
 605  27.2% dst/move/
 606  27.2% src/move/
 607EOF
 608
 609cat <<EOF >expect_diff_dirstat_M
 610  14.2% changed/
 611  14.2% dst/copy/changed/
 612  14.2% dst/copy/rearranged/
 613  14.2% dst/copy/unchanged/
 614  14.2% dst/move/changed/
 615  14.2% dst/move/rearranged/
 616  14.2% rearranged/
 617EOF
 618
 619cat <<EOF >expect_diff_dirstat_CC
 620  16.6% changed/
 621  16.6% dst/copy/changed/
 622  16.6% dst/copy/rearranged/
 623  16.6% dst/move/changed/
 624  16.6% dst/move/rearranged/
 625  16.6% rearranged/
 626EOF
 627
 628test_expect_success '--dirstat-by-file=10' '
 629        git diff --dirstat-by-file=10 HEAD^..HEAD >actual_diff_dirstat &&
 630        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 631        git diff --dirstat-by-file=10 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 632        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 633        git diff --dirstat-by-file=10 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 634        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 635'
 636
 637test_expect_success '--dirstat=files,10' '
 638        git diff --dirstat=files,10 HEAD^..HEAD >actual_diff_dirstat &&
 639        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 640        git diff --dirstat=files,10 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 641        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 642        git diff --dirstat=files,10 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 643        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 644'
 645
 646test_expect_success 'diff.dirstat=10,files' '
 647        git -c diff.dirstat=10,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 648        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 649        git -c diff.dirstat=10,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 650        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 651        git -c diff.dirstat=10,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 652        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 653'
 654
 655cat <<EOF >expect_diff_dirstat
 656   9.0% changed/
 657   9.0% dst/copy/changed/
 658   9.0% dst/copy/rearranged/
 659   9.0% dst/copy/unchanged/
 660  27.2% dst/copy/
 661   9.0% dst/move/changed/
 662   9.0% dst/move/rearranged/
 663   9.0% dst/move/unchanged/
 664  27.2% dst/move/
 665  54.5% dst/
 666   9.0% rearranged/
 667   9.0% src/move/changed/
 668   9.0% src/move/rearranged/
 669   9.0% src/move/unchanged/
 670  27.2% src/move/
 671EOF
 672
 673cat <<EOF >expect_diff_dirstat_M
 674  14.2% changed/
 675  14.2% dst/copy/changed/
 676  14.2% dst/copy/rearranged/
 677  14.2% dst/copy/unchanged/
 678  42.8% dst/copy/
 679  14.2% dst/move/changed/
 680  14.2% dst/move/rearranged/
 681  28.5% dst/move/
 682  71.4% dst/
 683  14.2% rearranged/
 684EOF
 685
 686cat <<EOF >expect_diff_dirstat_CC
 687  16.6% changed/
 688  16.6% dst/copy/changed/
 689  16.6% dst/copy/rearranged/
 690  33.3% dst/copy/
 691  16.6% dst/move/changed/
 692  16.6% dst/move/rearranged/
 693  33.3% dst/move/
 694  66.6% dst/
 695  16.6% rearranged/
 696EOF
 697
 698test_expect_success '--dirstat-by-file --cumulative' '
 699        git diff --dirstat-by-file --cumulative HEAD^..HEAD >actual_diff_dirstat &&
 700        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 701        git diff --dirstat-by-file --cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 702        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 703        git diff --dirstat-by-file --cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 704        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 705'
 706
 707test_expect_success '--dirstat=files,cumulative' '
 708        git diff --dirstat=files,cumulative HEAD^..HEAD >actual_diff_dirstat &&
 709        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 710        git diff --dirstat=files,cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 711        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 712        git diff --dirstat=files,cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 713        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 714'
 715
 716test_expect_success 'diff.dirstat=cumulative,files' '
 717        git -c diff.dirstat=cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 718        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 719        git -c diff.dirstat=cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 720        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 721        git -c diff.dirstat=cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 722        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 723'
 724
 725cat <<EOF >expect_diff_dirstat
 726  27.2% dst/copy/
 727  27.2% dst/move/
 728  54.5% dst/
 729  27.2% src/move/
 730EOF
 731
 732cat <<EOF >expect_diff_dirstat_M
 733  14.2% changed/
 734  14.2% dst/copy/changed/
 735  14.2% dst/copy/rearranged/
 736  14.2% dst/copy/unchanged/
 737  42.8% dst/copy/
 738  14.2% dst/move/changed/
 739  14.2% dst/move/rearranged/
 740  28.5% dst/move/
 741  71.4% dst/
 742  14.2% rearranged/
 743EOF
 744
 745cat <<EOF >expect_diff_dirstat_CC
 746  16.6% changed/
 747  16.6% dst/copy/changed/
 748  16.6% dst/copy/rearranged/
 749  33.3% dst/copy/
 750  16.6% dst/move/changed/
 751  16.6% dst/move/rearranged/
 752  33.3% dst/move/
 753  66.6% dst/
 754  16.6% rearranged/
 755EOF
 756
 757test_expect_success '--dirstat=files,cumulative,10' '
 758        git diff --dirstat=files,cumulative,10 HEAD^..HEAD >actual_diff_dirstat &&
 759        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 760        git diff --dirstat=files,cumulative,10 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 761        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 762        git diff --dirstat=files,cumulative,10 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 763        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 764'
 765
 766test_expect_success 'diff.dirstat=10,cumulative,files' '
 767        git -c diff.dirstat=10,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 768        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 769        git -c diff.dirstat=10,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 770        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 771        git -c diff.dirstat=10,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 772        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 773'
 774
 775cat <<EOF >expect_diff_dirstat
 776  27.2% dst/copy/
 777  27.2% dst/move/
 778  54.5% dst/
 779  27.2% src/move/
 780EOF
 781
 782cat <<EOF >expect_diff_dirstat_M
 783  42.8% dst/copy/
 784  28.5% dst/move/
 785  71.4% dst/
 786EOF
 787
 788cat <<EOF >expect_diff_dirstat_CC
 789  33.3% dst/copy/
 790  33.3% dst/move/
 791  66.6% dst/
 792EOF
 793
 794test_expect_success '--dirstat=files,cumulative,16.7' '
 795        git diff --dirstat=files,cumulative,16.7 HEAD^..HEAD >actual_diff_dirstat &&
 796        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 797        git diff --dirstat=files,cumulative,16.7 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 798        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 799        git diff --dirstat=files,cumulative,16.7 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 800        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 801'
 802
 803test_expect_success 'diff.dirstat=16.7,cumulative,files' '
 804        git -c diff.dirstat=16.7,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 805        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 806        git -c diff.dirstat=16.7,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 807        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 808        git -c diff.dirstat=16.7,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 809        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 810'
 811
 812test_expect_success 'diff.dirstat=16.70,cumulative,files' '
 813        git -c diff.dirstat=16.70,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 814        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 815        git -c diff.dirstat=16.70,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 816        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 817        git -c diff.dirstat=16.70,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 818        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 819'
 820
 821test_expect_success '--dirstat=files,cumulative,27.2' '
 822        git diff --dirstat=files,cumulative,27.2 HEAD^..HEAD >actual_diff_dirstat &&
 823        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 824        git diff --dirstat=files,cumulative,27.2 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 825        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 826        git diff --dirstat=files,cumulative,27.2 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 827        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 828'
 829
 830test_expect_success '--dirstat=files,cumulative,27.09' '
 831        git diff --dirstat=files,cumulative,27.09 HEAD^..HEAD >actual_diff_dirstat &&
 832        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 833        git diff --dirstat=files,cumulative,27.09 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 834        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 835        git diff --dirstat=files,cumulative,27.09 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 836        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 837'
 838
 839cat <<EOF >expect_diff_dirstat
 840  10.6% dst/copy/changed/
 841  10.6% dst/copy/rearranged/
 842  10.6% dst/copy/unchanged/
 843  10.6% dst/move/changed/
 844  10.6% dst/move/rearranged/
 845  10.6% dst/move/unchanged/
 846  10.6% src/move/changed/
 847  10.6% src/move/rearranged/
 848  10.6% src/move/unchanged/
 849EOF
 850
 851cat <<EOF >expect_diff_dirstat_M
 852   5.2% changed/
 853  26.3% dst/copy/changed/
 854  26.3% dst/copy/rearranged/
 855  26.3% dst/copy/unchanged/
 856   5.2% dst/move/changed/
 857   5.2% dst/move/rearranged/
 858   5.2% rearranged/
 859EOF
 860
 861cat <<EOF >expect_diff_dirstat_CC
 862  16.6% changed/
 863  16.6% dst/copy/changed/
 864  16.6% dst/copy/rearranged/
 865  16.6% dst/move/changed/
 866  16.6% dst/move/rearranged/
 867  16.6% rearranged/
 868EOF
 869
 870test_expect_success '--dirstat=lines' '
 871        git diff --dirstat=lines HEAD^..HEAD >actual_diff_dirstat &&
 872        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 873        git diff --dirstat=lines -M HEAD^..HEAD >actual_diff_dirstat_M &&
 874        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 875        git diff --dirstat=lines -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 876        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 877'
 878
 879test_expect_success 'diff.dirstat=lines' '
 880        git -c diff.dirstat=lines diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 881        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 882        git -c diff.dirstat=lines diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 883        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 884        git -c diff.dirstat=lines diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 885        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 886'
 887
 888cat <<EOF >expect_diff_dirstat
 889   2.1% changed/
 890  10.6% dst/copy/changed/
 891  10.6% dst/copy/rearranged/
 892  10.6% dst/copy/unchanged/
 893  10.6% dst/move/changed/
 894  10.6% dst/move/rearranged/
 895  10.6% dst/move/unchanged/
 896   2.1% rearranged/
 897  10.6% src/move/changed/
 898  10.6% src/move/rearranged/
 899  10.6% src/move/unchanged/
 900EOF
 901
 902cat <<EOF >expect_diff_dirstat_M
 903   5.2% changed/
 904  26.3% dst/copy/changed/
 905  26.3% dst/copy/rearranged/
 906  26.3% dst/copy/unchanged/
 907   5.2% dst/move/changed/
 908   5.2% dst/move/rearranged/
 909   5.2% rearranged/
 910EOF
 911
 912cat <<EOF >expect_diff_dirstat_CC
 913  16.6% changed/
 914  16.6% dst/copy/changed/
 915  16.6% dst/copy/rearranged/
 916  16.6% dst/move/changed/
 917  16.6% dst/move/rearranged/
 918  16.6% rearranged/
 919EOF
 920
 921test_expect_success '--dirstat=lines,0' '
 922        git diff --dirstat=lines,0 HEAD^..HEAD >actual_diff_dirstat &&
 923        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 924        git diff --dirstat=lines,0 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 925        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 926        git diff --dirstat=lines,0 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 927        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 928'
 929
 930test_expect_success 'diff.dirstat=0,lines' '
 931        git -c diff.dirstat=0,lines diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 932        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 933        git -c diff.dirstat=0,lines diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 934        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 935        git -c diff.dirstat=0,lines diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 936        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 937'
 938
 939test_expect_success '--dirstat=future_param,lines,0 should fail loudly' '
 940        test_must_fail git diff --dirstat=future_param,lines,0 HEAD^..HEAD >actual_diff_dirstat 2>actual_error &&
 941        test_debug "cat actual_error" &&
 942        test_cmp /dev/null actual_diff_dirstat &&
 943        test_i18ngrep -q "future_param" actual_error &&
 944        test_i18ngrep -q "\--dirstat" actual_error
 945'
 946
 947test_expect_success '--dirstat=dummy1,cumulative,2dummy should report both unrecognized parameters' '
 948        test_must_fail git diff --dirstat=dummy1,cumulative,2dummy HEAD^..HEAD >actual_diff_dirstat 2>actual_error &&
 949        test_debug "cat actual_error" &&
 950        test_cmp /dev/null actual_diff_dirstat &&
 951        test_i18ngrep -q "dummy1" actual_error &&
 952        test_i18ngrep -q "2dummy" actual_error &&
 953        test_i18ngrep -q "\--dirstat" actual_error
 954'
 955
 956test_expect_success 'diff.dirstat=future_param,0,lines should warn, but still work' '
 957        git -c diff.dirstat=future_param,0,lines diff --dirstat HEAD^..HEAD >actual_diff_dirstat 2>actual_error &&
 958        test_debug "cat actual_error" &&
 959        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 960        test_i18ngrep -q "future_param" actual_error &&
 961        test_i18ngrep -q "diff\\.dirstat" actual_error &&
 962
 963        git -c diff.dirstat=future_param,0,lines diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M 2>actual_error &&
 964        test_debug "cat actual_error" &&
 965        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 966        test_i18ngrep -q "future_param" actual_error &&
 967        test_i18ngrep -q "diff\\.dirstat" actual_error &&
 968
 969        git -c diff.dirstat=future_param,0,lines diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC 2>actual_error &&
 970        test_debug "cat actual_error" &&
 971        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC &&
 972        test_i18ngrep -q "future_param" actual_error &&
 973        test_i18ngrep -q "diff\\.dirstat" actual_error
 974'
 975
 976test_done