t / t4047-diff-dirstat.shon commit Merge branch 'pw/rebase-i-internal' (7ba06bc)
   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        git config diff.renames false
 253'
 254
 255cat <<EOF >expect_diff_stat
 2561       1       changed/text
 25710      0       dst/copy/changed/text
 25810      0       dst/copy/rearranged/text
 25910      0       dst/copy/unchanged/text
 26010      0       dst/move/changed/text
 26110      0       dst/move/rearranged/text
 26210      0       dst/move/unchanged/text
 2631       1       rearranged/text
 2640       10      src/move/changed/text
 2650       10      src/move/rearranged/text
 2660       10      src/move/unchanged/text
 267EOF
 268
 269cat <<EOF >expect_diff_stat_M
 2701       1       changed/text
 27110      0       dst/copy/changed/text
 27210      0       dst/copy/rearranged/text
 27310      0       dst/copy/unchanged/text
 2741       1       {src => dst}/move/changed/text
 2751       1       {src => dst}/move/rearranged/text
 2760       0       {src => dst}/move/unchanged/text
 2771       1       rearranged/text
 278EOF
 279
 280cat <<EOF >expect_diff_stat_CC
 2811       1       changed/text
 2821       1       {src => dst}/copy/changed/text
 2831       1       {src => dst}/copy/rearranged/text
 2840       0       {src => dst}/copy/unchanged/text
 2851       1       {src => dst}/move/changed/text
 2861       1       {src => dst}/move/rearranged/text
 2870       0       {src => dst}/move/unchanged/text
 2881       1       rearranged/text
 289EOF
 290
 291test_expect_success 'sanity check setup (--numstat)' '
 292        git diff --numstat HEAD^..HEAD >actual_diff_stat &&
 293        test_cmp expect_diff_stat actual_diff_stat &&
 294        git diff --numstat -M HEAD^..HEAD >actual_diff_stat_M &&
 295        test_cmp expect_diff_stat_M actual_diff_stat_M &&
 296        git diff --numstat -C -C HEAD^..HEAD >actual_diff_stat_CC &&
 297        test_cmp expect_diff_stat_CC actual_diff_stat_CC
 298'
 299
 300# changed/text and rearranged/text falls below default 3% threshold
 301cat <<EOF >expect_diff_dirstat
 302  10.8% dst/copy/changed/
 303  10.8% dst/copy/rearranged/
 304  10.8% dst/copy/unchanged/
 305  10.8% dst/move/changed/
 306  10.8% dst/move/rearranged/
 307  10.8% dst/move/unchanged/
 308  10.8% src/move/changed/
 309  10.8% src/move/rearranged/
 310  10.8% src/move/unchanged/
 311EOF
 312
 313# rearranged/text falls below default 3% threshold
 314cat <<EOF >expect_diff_dirstat_M
 315   5.8% changed/
 316  29.3% dst/copy/changed/
 317  29.3% dst/copy/rearranged/
 318  29.3% dst/copy/unchanged/
 319   5.8% dst/move/changed/
 320EOF
 321
 322# rearranged/text falls below default 3% threshold
 323cat <<EOF >expect_diff_dirstat_CC
 324  32.6% changed/
 325  32.6% dst/copy/changed/
 326  32.6% dst/move/changed/
 327EOF
 328
 329test_expect_success 'various ways to misspell --dirstat' '
 330        test_must_fail git show --dirstat10 &&
 331        test_must_fail git show --dirstat10,files &&
 332        test_must_fail git show -X=20 &&
 333        test_must_fail git show -X=20,cumulative
 334'
 335
 336test_expect_success 'vanilla --dirstat' '
 337        git diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 338        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 339        git diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 340        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 341        git diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 342        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 343'
 344
 345test_expect_success 'vanilla -X' '
 346        git diff -X HEAD^..HEAD >actual_diff_dirstat &&
 347        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 348        git diff -X -M HEAD^..HEAD >actual_diff_dirstat_M &&
 349        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 350        git diff -X -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 351        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 352'
 353
 354test_expect_success 'explicit defaults: --dirstat=changes,noncumulative,3' '
 355        git diff --dirstat=changes,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
 356        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 357        git diff --dirstat=changes,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 358        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 359        git diff --dirstat=changes,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 360        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 361'
 362
 363test_expect_success 'explicit defaults: -Xchanges,noncumulative,3' '
 364        git diff -Xchanges,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
 365        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 366        git diff -Xchanges,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 367        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 368        git diff -Xchanges,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 369        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 370'
 371
 372test_expect_success 'later options override earlier options:' '
 373        git diff --dirstat=files,10,cumulative,changes,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
 374        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 375        git diff --dirstat=files,10,cumulative,changes,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 376        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 377        git diff --dirstat=files,10,cumulative,changes,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 378        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC &&
 379        git diff --dirstat=files --dirstat=10 --dirstat=cumulative --dirstat=changes --dirstat=noncumulative -X3 HEAD^..HEAD >actual_diff_dirstat &&
 380        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 381        git diff --dirstat=files --dirstat=10 --dirstat=cumulative --dirstat=changes --dirstat=noncumulative -X3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 382        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 383        git diff --dirstat=files --dirstat=10 --dirstat=cumulative --dirstat=changes --dirstat=noncumulative -X3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 384        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 385'
 386
 387test_expect_success 'non-defaults in config overridden by explicit defaults on command line' '
 388        git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
 389        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 390        git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 391        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 392        git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 393        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 394'
 395
 396cat <<EOF >expect_diff_dirstat
 397   2.1% changed/
 398  10.8% dst/copy/changed/
 399  10.8% dst/copy/rearranged/
 400  10.8% dst/copy/unchanged/
 401  10.8% dst/move/changed/
 402  10.8% dst/move/rearranged/
 403  10.8% dst/move/unchanged/
 404   0.0% rearranged/
 405  10.8% src/move/changed/
 406  10.8% src/move/rearranged/
 407  10.8% src/move/unchanged/
 408EOF
 409
 410cat <<EOF >expect_diff_dirstat_M
 411   5.8% changed/
 412  29.3% dst/copy/changed/
 413  29.3% dst/copy/rearranged/
 414  29.3% dst/copy/unchanged/
 415   5.8% dst/move/changed/
 416   0.1% dst/move/rearranged/
 417   0.1% rearranged/
 418EOF
 419
 420cat <<EOF >expect_diff_dirstat_CC
 421  32.6% changed/
 422  32.6% dst/copy/changed/
 423   0.6% dst/copy/rearranged/
 424  32.6% dst/move/changed/
 425   0.6% dst/move/rearranged/
 426   0.6% rearranged/
 427EOF
 428
 429test_expect_success '--dirstat=0' '
 430        git diff --dirstat=0 HEAD^..HEAD >actual_diff_dirstat &&
 431        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 432        git diff --dirstat=0 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 433        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 434        git diff --dirstat=0 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 435        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 436'
 437
 438test_expect_success '-X0' '
 439        git diff -X0 HEAD^..HEAD >actual_diff_dirstat &&
 440        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 441        git diff -X0 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 442        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 443        git diff -X0 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 444        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 445'
 446
 447test_expect_success 'diff.dirstat=0' '
 448        git -c diff.dirstat=0 diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 449        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 450        git -c diff.dirstat=0 diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 451        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 452        git -c diff.dirstat=0 diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 453        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 454'
 455
 456cat <<EOF >expect_diff_dirstat
 457   2.1% changed/
 458  10.8% dst/copy/changed/
 459  10.8% dst/copy/rearranged/
 460  10.8% dst/copy/unchanged/
 461  32.5% dst/copy/
 462  10.8% dst/move/changed/
 463  10.8% dst/move/rearranged/
 464  10.8% dst/move/unchanged/
 465  32.5% dst/move/
 466  65.1% dst/
 467   0.0% rearranged/
 468  10.8% src/move/changed/
 469  10.8% src/move/rearranged/
 470  10.8% src/move/unchanged/
 471  32.5% src/move/
 472EOF
 473
 474cat <<EOF >expect_diff_dirstat_M
 475   5.8% changed/
 476  29.3% dst/copy/changed/
 477  29.3% dst/copy/rearranged/
 478  29.3% dst/copy/unchanged/
 479  88.0% dst/copy/
 480   5.8% dst/move/changed/
 481   0.1% dst/move/rearranged/
 482   5.9% dst/move/
 483  94.0% dst/
 484   0.1% rearranged/
 485EOF
 486
 487cat <<EOF >expect_diff_dirstat_CC
 488  32.6% changed/
 489  32.6% dst/copy/changed/
 490   0.6% dst/copy/rearranged/
 491  33.3% dst/copy/
 492  32.6% dst/move/changed/
 493   0.6% dst/move/rearranged/
 494  33.3% dst/move/
 495  66.6% dst/
 496   0.6% rearranged/
 497EOF
 498
 499test_expect_success '--dirstat=0 --cumulative' '
 500        git diff --dirstat=0 --cumulative HEAD^..HEAD >actual_diff_dirstat &&
 501        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 502        git diff --dirstat=0 --cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 503        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 504        git diff --dirstat=0 --cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 505        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 506'
 507
 508test_expect_success '--dirstat=0,cumulative' '
 509        git diff --dirstat=0,cumulative HEAD^..HEAD >actual_diff_dirstat &&
 510        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 511        git diff --dirstat=0,cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 512        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 513        git diff --dirstat=0,cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 514        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 515'
 516
 517test_expect_success '-X0,cumulative' '
 518        git diff -X0,cumulative HEAD^..HEAD >actual_diff_dirstat &&
 519        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 520        git diff -X0,cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 521        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 522        git diff -X0,cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 523        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 524'
 525
 526test_expect_success 'diff.dirstat=0,cumulative' '
 527        git -c diff.dirstat=0,cumulative diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 528        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 529        git -c diff.dirstat=0,cumulative diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 530        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 531        git -c diff.dirstat=0,cumulative diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 532        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 533'
 534
 535test_expect_success 'diff.dirstat=0 & --dirstat=cumulative' '
 536        git -c diff.dirstat=0 diff --dirstat=cumulative HEAD^..HEAD >actual_diff_dirstat &&
 537        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 538        git -c diff.dirstat=0 diff --dirstat=cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 539        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 540        git -c diff.dirstat=0 diff --dirstat=cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 541        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 542'
 543
 544cat <<EOF >expect_diff_dirstat
 545   9.0% changed/
 546   9.0% dst/copy/changed/
 547   9.0% dst/copy/rearranged/
 548   9.0% dst/copy/unchanged/
 549   9.0% dst/move/changed/
 550   9.0% dst/move/rearranged/
 551   9.0% dst/move/unchanged/
 552   9.0% rearranged/
 553   9.0% src/move/changed/
 554   9.0% src/move/rearranged/
 555   9.0% src/move/unchanged/
 556EOF
 557
 558cat <<EOF >expect_diff_dirstat_M
 559  14.2% changed/
 560  14.2% dst/copy/changed/
 561  14.2% dst/copy/rearranged/
 562  14.2% dst/copy/unchanged/
 563  14.2% dst/move/changed/
 564  14.2% dst/move/rearranged/
 565  14.2% rearranged/
 566EOF
 567
 568cat <<EOF >expect_diff_dirstat_CC
 569  16.6% changed/
 570  16.6% dst/copy/changed/
 571  16.6% dst/copy/rearranged/
 572  16.6% dst/move/changed/
 573  16.6% dst/move/rearranged/
 574  16.6% rearranged/
 575EOF
 576
 577test_expect_success '--dirstat-by-file' '
 578        git diff --dirstat-by-file HEAD^..HEAD >actual_diff_dirstat &&
 579        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 580        git diff --dirstat-by-file -M HEAD^..HEAD >actual_diff_dirstat_M &&
 581        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 582        git diff --dirstat-by-file -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 583        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 584'
 585
 586test_expect_success '--dirstat=files' '
 587        git diff --dirstat=files HEAD^..HEAD >actual_diff_dirstat &&
 588        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 589        git diff --dirstat=files -M HEAD^..HEAD >actual_diff_dirstat_M &&
 590        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 591        git diff --dirstat=files -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 592        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 593'
 594
 595test_expect_success 'diff.dirstat=files' '
 596        git -c diff.dirstat=files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 597        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 598        git -c diff.dirstat=files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 599        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 600        git -c diff.dirstat=files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 601        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 602'
 603
 604cat <<EOF >expect_diff_dirstat
 605  27.2% dst/copy/
 606  27.2% dst/move/
 607  27.2% src/move/
 608EOF
 609
 610cat <<EOF >expect_diff_dirstat_M
 611  14.2% changed/
 612  14.2% dst/copy/changed/
 613  14.2% dst/copy/rearranged/
 614  14.2% dst/copy/unchanged/
 615  14.2% dst/move/changed/
 616  14.2% dst/move/rearranged/
 617  14.2% rearranged/
 618EOF
 619
 620cat <<EOF >expect_diff_dirstat_CC
 621  16.6% changed/
 622  16.6% dst/copy/changed/
 623  16.6% dst/copy/rearranged/
 624  16.6% dst/move/changed/
 625  16.6% dst/move/rearranged/
 626  16.6% rearranged/
 627EOF
 628
 629test_expect_success '--dirstat-by-file=10' '
 630        git diff --dirstat-by-file=10 HEAD^..HEAD >actual_diff_dirstat &&
 631        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 632        git diff --dirstat-by-file=10 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 633        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 634        git diff --dirstat-by-file=10 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 635        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 636'
 637
 638test_expect_success '--dirstat=files,10' '
 639        git diff --dirstat=files,10 HEAD^..HEAD >actual_diff_dirstat &&
 640        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 641        git diff --dirstat=files,10 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 642        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 643        git diff --dirstat=files,10 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 644        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 645'
 646
 647test_expect_success 'diff.dirstat=10,files' '
 648        git -c diff.dirstat=10,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 649        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 650        git -c diff.dirstat=10,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 651        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 652        git -c diff.dirstat=10,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 653        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 654'
 655
 656cat <<EOF >expect_diff_dirstat
 657   9.0% changed/
 658   9.0% dst/copy/changed/
 659   9.0% dst/copy/rearranged/
 660   9.0% dst/copy/unchanged/
 661  27.2% dst/copy/
 662   9.0% dst/move/changed/
 663   9.0% dst/move/rearranged/
 664   9.0% dst/move/unchanged/
 665  27.2% dst/move/
 666  54.5% dst/
 667   9.0% rearranged/
 668   9.0% src/move/changed/
 669   9.0% src/move/rearranged/
 670   9.0% src/move/unchanged/
 671  27.2% src/move/
 672EOF
 673
 674cat <<EOF >expect_diff_dirstat_M
 675  14.2% changed/
 676  14.2% dst/copy/changed/
 677  14.2% dst/copy/rearranged/
 678  14.2% dst/copy/unchanged/
 679  42.8% dst/copy/
 680  14.2% dst/move/changed/
 681  14.2% dst/move/rearranged/
 682  28.5% dst/move/
 683  71.4% dst/
 684  14.2% rearranged/
 685EOF
 686
 687cat <<EOF >expect_diff_dirstat_CC
 688  16.6% changed/
 689  16.6% dst/copy/changed/
 690  16.6% dst/copy/rearranged/
 691  33.3% dst/copy/
 692  16.6% dst/move/changed/
 693  16.6% dst/move/rearranged/
 694  33.3% dst/move/
 695  66.6% dst/
 696  16.6% rearranged/
 697EOF
 698
 699test_expect_success '--dirstat-by-file --cumulative' '
 700        git diff --dirstat-by-file --cumulative HEAD^..HEAD >actual_diff_dirstat &&
 701        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 702        git diff --dirstat-by-file --cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 703        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 704        git diff --dirstat-by-file --cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 705        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 706'
 707
 708test_expect_success '--dirstat=files,cumulative' '
 709        git diff --dirstat=files,cumulative HEAD^..HEAD >actual_diff_dirstat &&
 710        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 711        git diff --dirstat=files,cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
 712        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 713        git diff --dirstat=files,cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 714        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 715'
 716
 717test_expect_success 'diff.dirstat=cumulative,files' '
 718        git -c diff.dirstat=cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 719        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 720        git -c diff.dirstat=cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 721        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 722        git -c diff.dirstat=cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 723        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 724'
 725
 726cat <<EOF >expect_diff_dirstat
 727  27.2% dst/copy/
 728  27.2% dst/move/
 729  54.5% dst/
 730  27.2% src/move/
 731EOF
 732
 733cat <<EOF >expect_diff_dirstat_M
 734  14.2% changed/
 735  14.2% dst/copy/changed/
 736  14.2% dst/copy/rearranged/
 737  14.2% dst/copy/unchanged/
 738  42.8% dst/copy/
 739  14.2% dst/move/changed/
 740  14.2% dst/move/rearranged/
 741  28.5% dst/move/
 742  71.4% dst/
 743  14.2% rearranged/
 744EOF
 745
 746cat <<EOF >expect_diff_dirstat_CC
 747  16.6% changed/
 748  16.6% dst/copy/changed/
 749  16.6% dst/copy/rearranged/
 750  33.3% dst/copy/
 751  16.6% dst/move/changed/
 752  16.6% dst/move/rearranged/
 753  33.3% dst/move/
 754  66.6% dst/
 755  16.6% rearranged/
 756EOF
 757
 758test_expect_success '--dirstat=files,cumulative,10' '
 759        git diff --dirstat=files,cumulative,10 HEAD^..HEAD >actual_diff_dirstat &&
 760        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 761        git diff --dirstat=files,cumulative,10 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 762        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 763        git diff --dirstat=files,cumulative,10 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 764        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 765'
 766
 767test_expect_success 'diff.dirstat=10,cumulative,files' '
 768        git -c diff.dirstat=10,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 769        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 770        git -c diff.dirstat=10,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 771        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 772        git -c diff.dirstat=10,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 773        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 774'
 775
 776cat <<EOF >expect_diff_dirstat
 777  27.2% dst/copy/
 778  27.2% dst/move/
 779  54.5% dst/
 780  27.2% src/move/
 781EOF
 782
 783cat <<EOF >expect_diff_dirstat_M
 784  42.8% dst/copy/
 785  28.5% dst/move/
 786  71.4% dst/
 787EOF
 788
 789cat <<EOF >expect_diff_dirstat_CC
 790  33.3% dst/copy/
 791  33.3% dst/move/
 792  66.6% dst/
 793EOF
 794
 795test_expect_success '--dirstat=files,cumulative,16.7' '
 796        git diff --dirstat=files,cumulative,16.7 HEAD^..HEAD >actual_diff_dirstat &&
 797        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 798        git diff --dirstat=files,cumulative,16.7 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 799        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 800        git diff --dirstat=files,cumulative,16.7 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 801        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 802'
 803
 804test_expect_success 'diff.dirstat=16.7,cumulative,files' '
 805        git -c diff.dirstat=16.7,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 806        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 807        git -c diff.dirstat=16.7,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 808        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 809        git -c diff.dirstat=16.7,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 810        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 811'
 812
 813test_expect_success 'diff.dirstat=16.70,cumulative,files' '
 814        git -c diff.dirstat=16.70,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 815        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 816        git -c diff.dirstat=16.70,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 817        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 818        git -c diff.dirstat=16.70,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 819        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 820'
 821
 822test_expect_success '--dirstat=files,cumulative,27.2' '
 823        git diff --dirstat=files,cumulative,27.2 HEAD^..HEAD >actual_diff_dirstat &&
 824        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 825        git diff --dirstat=files,cumulative,27.2 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 826        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 827        git diff --dirstat=files,cumulative,27.2 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 828        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 829'
 830
 831test_expect_success '--dirstat=files,cumulative,27.09' '
 832        git diff --dirstat=files,cumulative,27.09 HEAD^..HEAD >actual_diff_dirstat &&
 833        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 834        git diff --dirstat=files,cumulative,27.09 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 835        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 836        git diff --dirstat=files,cumulative,27.09 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 837        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 838'
 839
 840cat <<EOF >expect_diff_dirstat
 841  10.6% dst/copy/changed/
 842  10.6% dst/copy/rearranged/
 843  10.6% dst/copy/unchanged/
 844  10.6% dst/move/changed/
 845  10.6% dst/move/rearranged/
 846  10.6% dst/move/unchanged/
 847  10.6% src/move/changed/
 848  10.6% src/move/rearranged/
 849  10.6% src/move/unchanged/
 850EOF
 851
 852cat <<EOF >expect_diff_dirstat_M
 853   5.2% changed/
 854  26.3% dst/copy/changed/
 855  26.3% dst/copy/rearranged/
 856  26.3% dst/copy/unchanged/
 857   5.2% dst/move/changed/
 858   5.2% dst/move/rearranged/
 859   5.2% rearranged/
 860EOF
 861
 862cat <<EOF >expect_diff_dirstat_CC
 863  16.6% changed/
 864  16.6% dst/copy/changed/
 865  16.6% dst/copy/rearranged/
 866  16.6% dst/move/changed/
 867  16.6% dst/move/rearranged/
 868  16.6% rearranged/
 869EOF
 870
 871test_expect_success '--dirstat=lines' '
 872        git diff --dirstat=lines HEAD^..HEAD >actual_diff_dirstat &&
 873        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 874        git diff --dirstat=lines -M HEAD^..HEAD >actual_diff_dirstat_M &&
 875        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 876        git diff --dirstat=lines -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 877        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 878'
 879
 880test_expect_success 'diff.dirstat=lines' '
 881        git -c diff.dirstat=lines diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 882        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 883        git -c diff.dirstat=lines diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 884        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 885        git -c diff.dirstat=lines diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 886        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 887'
 888
 889cat <<EOF >expect_diff_dirstat
 890   2.1% changed/
 891  10.6% dst/copy/changed/
 892  10.6% dst/copy/rearranged/
 893  10.6% dst/copy/unchanged/
 894  10.6% dst/move/changed/
 895  10.6% dst/move/rearranged/
 896  10.6% dst/move/unchanged/
 897   2.1% rearranged/
 898  10.6% src/move/changed/
 899  10.6% src/move/rearranged/
 900  10.6% src/move/unchanged/
 901EOF
 902
 903cat <<EOF >expect_diff_dirstat_M
 904   5.2% changed/
 905  26.3% dst/copy/changed/
 906  26.3% dst/copy/rearranged/
 907  26.3% dst/copy/unchanged/
 908   5.2% dst/move/changed/
 909   5.2% dst/move/rearranged/
 910   5.2% rearranged/
 911EOF
 912
 913cat <<EOF >expect_diff_dirstat_CC
 914  16.6% changed/
 915  16.6% dst/copy/changed/
 916  16.6% dst/copy/rearranged/
 917  16.6% dst/move/changed/
 918  16.6% dst/move/rearranged/
 919  16.6% rearranged/
 920EOF
 921
 922test_expect_success '--dirstat=lines,0' '
 923        git diff --dirstat=lines,0 HEAD^..HEAD >actual_diff_dirstat &&
 924        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 925        git diff --dirstat=lines,0 -M HEAD^..HEAD >actual_diff_dirstat_M &&
 926        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 927        git diff --dirstat=lines,0 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 928        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 929'
 930
 931test_expect_success 'diff.dirstat=0,lines' '
 932        git -c diff.dirstat=0,lines diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
 933        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 934        git -c diff.dirstat=0,lines diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
 935        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 936        git -c diff.dirstat=0,lines diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
 937        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
 938'
 939
 940test_expect_success '--dirstat=future_param,lines,0 should fail loudly' '
 941        test_must_fail git diff --dirstat=future_param,lines,0 HEAD^..HEAD >actual_diff_dirstat 2>actual_error &&
 942        test_debug "cat actual_error" &&
 943        test_must_be_empty actual_diff_dirstat &&
 944        test_i18ngrep -q "future_param" actual_error &&
 945        test_i18ngrep -q "\--dirstat" actual_error
 946'
 947
 948test_expect_success '--dirstat=dummy1,cumulative,2dummy should report both unrecognized parameters' '
 949        test_must_fail git diff --dirstat=dummy1,cumulative,2dummy HEAD^..HEAD >actual_diff_dirstat 2>actual_error &&
 950        test_debug "cat actual_error" &&
 951        test_must_be_empty actual_diff_dirstat &&
 952        test_i18ngrep -q "dummy1" actual_error &&
 953        test_i18ngrep -q "2dummy" actual_error &&
 954        test_i18ngrep -q "\--dirstat" actual_error
 955'
 956
 957test_expect_success 'diff.dirstat=future_param,0,lines should warn, but still work' '
 958        git -c diff.dirstat=future_param,0,lines diff --dirstat HEAD^..HEAD >actual_diff_dirstat 2>actual_error &&
 959        test_debug "cat actual_error" &&
 960        test_cmp expect_diff_dirstat actual_diff_dirstat &&
 961        test_i18ngrep -q "future_param" actual_error &&
 962        test_i18ngrep -q "diff\\.dirstat" actual_error &&
 963
 964        git -c diff.dirstat=future_param,0,lines diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M 2>actual_error &&
 965        test_debug "cat actual_error" &&
 966        test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
 967        test_i18ngrep -q "future_param" actual_error &&
 968        test_i18ngrep -q "diff\\.dirstat" actual_error &&
 969
 970        git -c diff.dirstat=future_param,0,lines diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC 2>actual_error &&
 971        test_debug "cat actual_error" &&
 972        test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC &&
 973        test_i18ngrep -q "future_param" actual_error &&
 974        test_i18ngrep -q "diff\\.dirstat" actual_error
 975'
 976
 977test_expect_success '--shortstat --dirstat should output only one dirstat' '
 978        git diff --shortstat --dirstat=changes HEAD^..HEAD >out &&
 979        grep " dst/copy/changed/$" out >actual_diff_shortstat_dirstat_changes &&
 980        test_line_count = 1 actual_diff_shortstat_dirstat_changes &&
 981
 982        git diff --shortstat --dirstat=lines HEAD^..HEAD >out &&
 983        grep " dst/copy/changed/$" out >actual_diff_shortstat_dirstat_lines &&
 984        test_line_count = 1 actual_diff_shortstat_dirstat_lines &&
 985
 986        git diff --shortstat --dirstat=files HEAD^..HEAD >out &&
 987        grep " dst/copy/changed/$" out >actual_diff_shortstat_dirstat_files &&
 988        test_line_count = 1 actual_diff_shortstat_dirstat_files
 989'
 990
 991test_done