t / t4020-diff-external.shon commit difftool: print list of valid tools with '--tool-help' (bf73fc2)
   1#!/bin/sh
   2
   3test_description='external diff interface test'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        test_tick &&
  10        echo initial >file &&
  11        git add file &&
  12        git commit -m initial &&
  13
  14        test_tick &&
  15        echo second >file &&
  16        git add file &&
  17        git commit -m second &&
  18
  19        test_tick &&
  20        echo third >file
  21'
  22
  23test_expect_success 'GIT_EXTERNAL_DIFF environment' '
  24
  25        GIT_EXTERNAL_DIFF=echo git diff | {
  26                read path oldfile oldhex oldmode newfile newhex newmode &&
  27                test "z$path" = zfile &&
  28                test "z$oldmode" = z100644 &&
  29                test "z$newhex" = "z$_z40" &&
  30                test "z$newmode" = z100644 &&
  31                oh=$(git rev-parse --verify HEAD:file) &&
  32                test "z$oh" = "z$oldhex"
  33        }
  34
  35'
  36
  37test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' '
  38
  39        GIT_EXTERNAL_DIFF=echo git log -p -1 HEAD |
  40        grep "^diff --git a/file b/file"
  41
  42'
  43
  44test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
  45
  46        GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |
  47        grep "^diff --git a/file b/file"
  48
  49'
  50
  51test_expect_success 'diff attribute' '
  52
  53        git config diff.parrot.command echo &&
  54
  55        echo >.gitattributes "file diff=parrot" &&
  56
  57        git diff | {
  58                read path oldfile oldhex oldmode newfile newhex newmode &&
  59                test "z$path" = zfile &&
  60                test "z$oldmode" = z100644 &&
  61                test "z$newhex" = "z$_z40" &&
  62                test "z$newmode" = z100644 &&
  63                oh=$(git rev-parse --verify HEAD:file) &&
  64                test "z$oh" = "z$oldhex"
  65        }
  66
  67'
  68
  69test_expect_success 'diff attribute should apply only to diff' '
  70
  71        git log -p -1 HEAD |
  72        grep "^diff --git a/file b/file"
  73
  74'
  75
  76test_expect_success 'diff attribute and --no-ext-diff' '
  77
  78        git diff --no-ext-diff |
  79        grep "^diff --git a/file b/file"
  80
  81'
  82
  83test_expect_success 'diff attribute' '
  84
  85        git config --unset diff.parrot.command &&
  86        git config diff.color.command echo &&
  87
  88        echo >.gitattributes "file diff=color" &&
  89
  90        git diff | {
  91                read path oldfile oldhex oldmode newfile newhex newmode &&
  92                test "z$path" = zfile &&
  93                test "z$oldmode" = z100644 &&
  94                test "z$newhex" = "z$_z40" &&
  95                test "z$newmode" = z100644 &&
  96                oh=$(git rev-parse --verify HEAD:file) &&
  97                test "z$oh" = "z$oldhex"
  98        }
  99
 100'
 101
 102test_expect_success 'diff attribute should apply only to diff' '
 103
 104        git log -p -1 HEAD |
 105        grep "^diff --git a/file b/file"
 106
 107'
 108
 109test_expect_success 'diff attribute and --no-ext-diff' '
 110
 111        git diff --no-ext-diff |
 112        grep "^diff --git a/file b/file"
 113
 114'
 115
 116test_expect_success 'no diff with -diff' '
 117        echo >.gitattributes "file -diff" &&
 118        git diff | grep Binary
 119'
 120
 121echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
 122
 123test_expect_success 'force diff with "diff"' '
 124        echo >.gitattributes "file diff" &&
 125        git diff >actual &&
 126        test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
 127'
 128
 129test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
 130        echo anotherfile > file2 &&
 131        git add file2 &&
 132        git commit -m "added 2nd file" &&
 133        echo modified >file2 &&
 134        GIT_EXTERNAL_DIFF=echo git diff
 135'
 136
 137test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
 138        touch file.ext &&
 139        git add file.ext &&
 140        echo with extension > file.ext &&
 141        GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext &&
 142        git update-index --force-remove file.ext &&
 143        rm file.ext
 144'
 145
 146echo "#!$SHELL_PATH" >fake-diff.sh
 147cat >> fake-diff.sh <<\EOF
 148cat $2 >> crlfed.txt
 149EOF
 150chmod a+x fake-diff.sh
 151
 152keep_only_cr () {
 153        tr -dc '\015'
 154}
 155
 156test_expect_success 'external diff with autocrlf = true' '
 157        git config core.autocrlf true &&
 158        GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
 159        test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
 160'
 161
 162test_expect_success 'diff --cached' '
 163        git add file &&
 164        git update-index --assume-unchanged file &&
 165        echo second >file &&
 166        git diff --cached >actual &&
 167        test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
 168'
 169
 170test_done