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