| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
| 6 | test_description='Test built-in diff output engine. |
| 7 | |
| 8 | We happen to know that all diff plumbing and diff Porcelain share the |
| 9 | same command line parser, so testing one should be sufficient; pick |
| 10 | diff-files as a representative. |
| 11 | ' |
| 12 | |
| 13 | . ./test-lib.sh |
| 14 | . "$TEST_DIRECTORY"/lib-diff.sh |
| 15 | |
| 16 | echo >path0 'Line 1 |
| 17 | Line 2 |
| 18 | line 3' |
| 19 | cat path0 >path1 |
| 20 | chmod +x path1 |
| 21 | mkdir path2 |
| 22 | >path2/path3 |
| 23 | |
| 24 | test_expect_success 'update-index --add two files with and without +x.' ' |
| 25 | git update-index --add path0 path1 path2/path3 |
| 26 | ' |
| 27 | |
| 28 | mv path0 path0- |
| 29 | sed -e 's/line/Line/' <path0- >path0 |
| 30 | chmod +x path0 |
| 31 | rm -f path1 |
| 32 | test_expect_success 'git diff-files -p after editing work tree.' ' |
| 33 | git diff-files -p >actual |
| 34 | ' |
| 35 | |
| 36 | # that's as far as it comes |
| 37 | if [ "$(git config --get core.filemode)" = false ] |
| 38 | then |
| 39 | skip_all='filemode disabled on the filesystem' |
| 40 | test_done |
| 41 | fi |
| 42 | |
| 43 | cat >expected <<\EOF |
| 44 | diff --git a/path0 b/path0 |
| 45 | old mode 100644 |
| 46 | new mode 100755 |
| 47 | --- a/path0 |
| 48 | +++ b/path0 |
| 49 | @@ -1,3 +1,3 @@ |
| 50 | Line 1 |
| 51 | Line 2 |
| 52 | -line 3 |
| 53 | +Line 3 |
| 54 | diff --git a/path1 b/path1 |
| 55 | deleted file mode 100755 |
| 56 | --- a/path1 |
| 57 | +++ /dev/null |
| 58 | @@ -1,3 +0,0 @@ |
| 59 | -Line 1 |
| 60 | -Line 2 |
| 61 | -line 3 |
| 62 | EOF |
| 63 | |
| 64 | test_expect_success 'validate git diff-files -p output.' ' |
| 65 | compare_diff_patch expected actual |
| 66 | ' |
| 67 | |
| 68 | test_expect_success 'git diff-files -s after editing work tree' ' |
| 69 | git diff-files -s >actual 2>err && |
| 70 | test_must_be_empty actual && |
| 71 | test_must_be_empty err |
| 72 | ' |
| 73 | |
| 74 | test_expect_success 'git diff-files --no-patch as synonym for -s' ' |
| 75 | git diff-files --no-patch >actual 2>err && |
| 76 | test_must_be_empty actual && |
| 77 | test_must_be_empty err |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'git diff-files --no-patch --patch shows the patch' ' |
| 81 | git diff-files --no-patch --patch >actual && |
| 82 | compare_diff_patch expected actual |
| 83 | ' |
| 84 | |
| 85 | test_expect_success 'git diff-files --no-patch --patch-with-raw shows the patch and raw data' ' |
| 86 | git diff-files --no-patch --patch-with-raw >actual && |
| 87 | test_grep -q "^:100644 100755 .* $ZERO_OID M path0\$" actual && |
| 88 | tail -n +4 actual >actual-patch && |
| 89 | compare_diff_patch expected actual-patch |
| 90 | ' |
| 91 | |
| 92 | test_expect_success 'git diff-files --patch --no-patch does not show the patch' ' |
| 93 | git diff-files --patch --no-patch >actual 2>err && |
| 94 | test_must_be_empty actual && |
| 95 | test_must_be_empty err |
| 96 | ' |
| 97 | |
| 98 | |
| 99 | # Smudge path2/path3 so that dirstat has something to show |
| 100 | date >path2/path3 |
| 101 | |
| 102 | for format in stat raw numstat shortstat summary \ |
| 103 | dirstat cumulative dirstat-by-file \ |
| 104 | patch-with-raw patch-with-stat compact-summary |
| 105 | do |
| 106 | test_expect_success "--no-patch in 'git diff-files --no-patch --$format' is a no-op" ' |
| 107 | git diff-files --no-patch "--$format" >actual && |
| 108 | git diff-files "--$format" >expect && |
| 109 | test_cmp expect actual |
| 110 | ' |
| 111 | |
| 112 | test_expect_success "--no-patch clears all previous ones" ' |
| 113 | git diff-files --$format -s -p >actual && |
| 114 | git diff-files -p >expect && |
| 115 | test_cmp expect actual |
| 116 | ' |
| 117 | |
| 118 | test_expect_success "--no-patch in 'git diff --no-patch --$format' is a no-op" ' |
| 119 | git diff --no-patch "--$format" >actual && |
| 120 | git diff "--$format" >expect && |
| 121 | test_cmp expect actual |
| 122 | ' |
| 123 | done |
| 124 | |
| 125 | test_done |