Junio C Hamano | f1af60b | 2007-04-22 17:52:55 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='external diff interface test' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
Junio C Hamano | f1af60b | 2007-04-22 17:52:55 -0700 | [diff] [blame] | 7 | test_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 | |
| 23 | test_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 | |
| 37 | test_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 | |
Junio C Hamano | 61af494 | 2008-11-26 09:58:41 -0800 | [diff] [blame] | 44 | test_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 | |
Junio C Hamano | bd8c1a9 | 2012-07-17 22:08:59 -0700 | [diff] [blame] | 51 | test_expect_success SYMLINKS 'typechange diff' ' |
| 52 | rm -f file && |
| 53 | ln -s elif file && |
| 54 | GIT_EXTERNAL_DIFF=echo git diff | { |
| 55 | read path oldfile oldhex oldmode newfile newhex newmode && |
| 56 | test "z$path" = zfile && |
| 57 | test "z$oldmode" = z100644 && |
| 58 | test "z$newhex" = "z$_z40" && |
| 59 | test "z$newmode" = z120000 && |
| 60 | oh=$(git rev-parse --verify HEAD:file) && |
| 61 | test "z$oh" = "z$oldhex" |
| 62 | } && |
| 63 | GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual && |
| 64 | git diff >expect && |
| 65 | test_cmp expect actual |
| 66 | ' |
| 67 | |
Jeff King | c12f82a | 2012-07-19 07:49:38 -0400 | [diff] [blame] | 68 | test_expect_success 'diff.external' ' |
| 69 | git reset --hard && |
| 70 | echo third >file && |
| 71 | test_config diff.external echo && |
| 72 | git diff | { |
| 73 | read path oldfile oldhex oldmode newfile newhex newmode && |
| 74 | test "z$path" = zfile && |
| 75 | test "z$oldmode" = z100644 && |
| 76 | test "z$newhex" = "z$_z40" && |
| 77 | test "z$newmode" = z100644 && |
| 78 | oh=$(git rev-parse --verify HEAD:file) && |
| 79 | test "z$oh" = "z$oldhex" |
| 80 | } |
| 81 | ' |
| 82 | |
| 83 | test_expect_success 'diff.external should apply only to diff' ' |
| 84 | test_config diff.external echo && |
| 85 | git log -p -1 HEAD | |
| 86 | grep "^diff --git a/file b/file" |
| 87 | ' |
| 88 | |
| 89 | test_expect_success 'diff.external and --no-ext-diff' ' |
| 90 | test_config diff.external echo && |
| 91 | git diff --no-ext-diff | |
| 92 | grep "^diff --git a/file b/file" |
| 93 | ' |
| 94 | |
Junio C Hamano | f1af60b | 2007-04-22 17:52:55 -0700 | [diff] [blame] | 95 | test_expect_success 'diff attribute' ' |
Junio C Hamano | bd8c1a9 | 2012-07-17 22:08:59 -0700 | [diff] [blame] | 96 | git reset --hard && |
| 97 | echo third >file && |
Junio C Hamano | f1af60b | 2007-04-22 17:52:55 -0700 | [diff] [blame] | 98 | |
| 99 | git config diff.parrot.command echo && |
| 100 | |
| 101 | echo >.gitattributes "file diff=parrot" && |
| 102 | |
| 103 | git diff | { |
| 104 | read path oldfile oldhex oldmode newfile newhex newmode && |
| 105 | test "z$path" = zfile && |
| 106 | test "z$oldmode" = z100644 && |
| 107 | test "z$newhex" = "z$_z40" && |
| 108 | test "z$newmode" = z100644 && |
| 109 | oh=$(git rev-parse --verify HEAD:file) && |
| 110 | test "z$oh" = "z$oldhex" |
| 111 | } |
| 112 | |
| 113 | ' |
| 114 | |
| 115 | test_expect_success 'diff attribute should apply only to diff' ' |
| 116 | |
| 117 | git log -p -1 HEAD | |
| 118 | grep "^diff --git a/file b/file" |
| 119 | |
| 120 | ' |
| 121 | |
Junio C Hamano | 61af494 | 2008-11-26 09:58:41 -0800 | [diff] [blame] | 122 | test_expect_success 'diff attribute and --no-ext-diff' ' |
| 123 | |
| 124 | git diff --no-ext-diff | |
| 125 | grep "^diff --git a/file b/file" |
| 126 | |
| 127 | ' |
| 128 | |
Junio C Hamano | f1af60b | 2007-04-22 17:52:55 -0700 | [diff] [blame] | 129 | test_expect_success 'diff attribute' ' |
| 130 | |
| 131 | git config --unset diff.parrot.command && |
| 132 | git config diff.color.command echo && |
| 133 | |
| 134 | echo >.gitattributes "file diff=color" && |
| 135 | |
| 136 | git diff | { |
| 137 | read path oldfile oldhex oldmode newfile newhex newmode && |
| 138 | test "z$path" = zfile && |
| 139 | test "z$oldmode" = z100644 && |
| 140 | test "z$newhex" = "z$_z40" && |
| 141 | test "z$newmode" = z100644 && |
| 142 | oh=$(git rev-parse --verify HEAD:file) && |
| 143 | test "z$oh" = "z$oldhex" |
| 144 | } |
| 145 | |
| 146 | ' |
| 147 | |
| 148 | test_expect_success 'diff attribute should apply only to diff' ' |
| 149 | |
| 150 | git log -p -1 HEAD | |
| 151 | grep "^diff --git a/file b/file" |
| 152 | |
| 153 | ' |
| 154 | |
Junio C Hamano | 61af494 | 2008-11-26 09:58:41 -0800 | [diff] [blame] | 155 | test_expect_success 'diff attribute and --no-ext-diff' ' |
| 156 | |
| 157 | git diff --no-ext-diff | |
| 158 | grep "^diff --git a/file b/file" |
| 159 | |
| 160 | ' |
| 161 | |
Jeff King | c12f82a | 2012-07-19 07:49:38 -0400 | [diff] [blame] | 162 | test_expect_success 'GIT_EXTERNAL_DIFF trumps diff.external' ' |
| 163 | >.gitattributes && |
| 164 | test_config diff.external "echo ext-global" && |
| 165 | GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-env |
| 166 | ' |
| 167 | |
| 168 | test_expect_success 'attributes trump GIT_EXTERNAL_DIFF and diff.external' ' |
| 169 | test_config diff.foo.command "echo ext-attribute" && |
| 170 | test_config diff.external "echo ext-global" && |
| 171 | echo "file diff=foo" >.gitattributes && |
| 172 | GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-attribute |
| 173 | ' |
| 174 | |
Junio C Hamano | 2c3fa66 | 2007-07-07 12:25:11 -0700 | [diff] [blame] | 175 | test_expect_success 'no diff with -diff' ' |
| 176 | echo >.gitattributes "file -diff" && |
| 177 | git diff | grep Binary |
| 178 | ' |
| 179 | |
Junio C Hamano | 7096b64 | 2012-06-12 09:49:59 -0700 | [diff] [blame] | 180 | echo NULZbetweenZwords | "$PERL_PATH" -pe 'y/Z/\000/' > file |
Junio C Hamano | 2c3fa66 | 2007-07-07 12:25:11 -0700 | [diff] [blame] | 181 | |
| 182 | test_expect_success 'force diff with "diff"' ' |
| 183 | echo >.gitattributes "file diff" && |
Jeff King | 53a5b44 | 2008-03-12 17:37:37 -0400 | [diff] [blame] | 184 | git diff >actual && |
Junio C Hamano | bfdbee9 | 2008-08-08 02:26:28 -0700 | [diff] [blame] | 185 | test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual |
Junio C Hamano | 2c3fa66 | 2007-07-07 12:25:11 -0700 | [diff] [blame] | 186 | ' |
| 187 | |
Nazri Ramliy | a8344ab | 2009-02-12 21:36:14 +0800 | [diff] [blame] | 188 | test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' ' |
| 189 | echo anotherfile > file2 && |
| 190 | git add file2 && |
| 191 | git commit -m "added 2nd file" && |
| 192 | echo modified >file2 && |
| 193 | GIT_EXTERNAL_DIFF=echo git diff |
| 194 | ' |
| 195 | |
David Aguilar | 003b33a | 2009-05-31 01:35:52 -0700 | [diff] [blame] | 196 | test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' ' |
| 197 | touch file.ext && |
| 198 | git add file.ext && |
| 199 | echo with extension > file.ext && |
| 200 | GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext && |
| 201 | git update-index --force-remove file.ext && |
| 202 | rm file.ext |
| 203 | ' |
| 204 | |
Johannes Schindelin | 4e218f5 | 2009-03-21 12:42:52 +0100 | [diff] [blame] | 205 | echo "#!$SHELL_PATH" >fake-diff.sh |
| 206 | cat >> fake-diff.sh <<\EOF |
| 207 | cat $2 >> crlfed.txt |
| 208 | EOF |
| 209 | chmod a+x fake-diff.sh |
| 210 | |
| 211 | keep_only_cr () { |
| 212 | tr -dc '\015' |
| 213 | } |
| 214 | |
| 215 | test_expect_success 'external diff with autocrlf = true' ' |
| 216 | git config core.autocrlf true && |
| 217 | GIT_EXTERNAL_DIFF=./fake-diff.sh git diff && |
| 218 | test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c) |
| 219 | ' |
| 220 | |
Junio C Hamano | 150115a | 2009-03-22 15:26:07 -0700 | [diff] [blame] | 221 | test_expect_success 'diff --cached' ' |
| 222 | git add file && |
| 223 | git update-index --assume-unchanged file && |
| 224 | echo second >file && |
| 225 | git diff --cached >actual && |
Jeff King | eaf0551 | 2009-08-09 04:37:52 -0400 | [diff] [blame] | 226 | test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual |
Junio C Hamano | 150115a | 2009-03-22 15:26:07 -0700 | [diff] [blame] | 227 | ' |
| 228 | |
Junio C Hamano | f1af60b | 2007-04-22 17:52:55 -0700 | [diff] [blame] | 229 | test_done |