Sync with 'master'
[alt-git.git] / t / t4000-diff-format.sh
blob8d50331b8c8e431853bbdf377813ed288007961b
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Test built-in diff output engine.
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.
13 TEST_PASSES_SANITIZE_LEAK=true
14 . ./test-lib.sh
15 . "$TEST_DIRECTORY"/lib-diff.sh
17 echo >path0 'Line 1
18 Line 2
19 line 3'
20 cat path0 >path1
21 chmod +x path1
22 mkdir path2
23 >path2/path3
25 test_expect_success 'update-index --add two files with and without +x.' '
26 git update-index --add path0 path1 path2/path3
29 mv path0 path0-
30 sed -e 's/line/Line/' <path0- >path0
31 chmod +x path0
32 rm -f path1
33 test_expect_success 'git diff-files -p after editing work tree.' '
34 git diff-files -p >actual
37 # that's as far as it comes
38 if [ "$(git config --get core.filemode)" = false ]
39 then
40 say 'filemode disabled on the filesystem'
41 test_done
44 cat >expected <<\EOF
45 diff --git a/path0 b/path0
46 old mode 100644
47 new mode 100755
48 --- a/path0
49 +++ b/path0
50 @@ -1,3 +1,3 @@
51 Line 1
52 Line 2
53 -line 3
54 +Line 3
55 diff --git a/path1 b/path1
56 deleted file mode 100755
57 --- a/path1
58 +++ /dev/null
59 @@ -1,3 +0,0 @@
60 -Line 1
61 -Line 2
62 -line 3
63 EOF
65 test_expect_success 'validate git diff-files -p output.' '
66 compare_diff_patch expected actual
69 test_expect_success 'git diff-files -s after editing work tree' '
70 git diff-files -s >actual 2>err &&
71 test_must_be_empty actual &&
72 test_must_be_empty err
75 test_expect_success 'git diff-files --no-patch as synonym for -s' '
76 git diff-files --no-patch >actual 2>err &&
77 test_must_be_empty actual &&
78 test_must_be_empty err
81 test_expect_success 'git diff-files --no-patch --patch shows the patch' '
82 git diff-files --no-patch --patch >actual &&
83 compare_diff_patch expected actual
86 test_expect_success 'git diff-files --no-patch --patch-with-raw shows the patch and raw data' '
87 git diff-files --no-patch --patch-with-raw >actual &&
88 grep -q "^:100644 100755 .* $ZERO_OID M path0\$" actual &&
89 tail -n +4 actual >actual-patch &&
90 compare_diff_patch expected actual-patch
93 test_expect_success 'git diff-files --patch --no-patch does not show the patch' '
94 git diff-files --patch --no-patch >actual 2>err &&
95 test_must_be_empty actual &&
96 test_must_be_empty err
100 # Smudge path2/path3 so that dirstat has something to show
101 date >path2/path3
103 for format in stat raw numstat shortstat summary \
104 dirstat cumulative dirstat-by-file \
105 patch-with-raw patch-with-stat compact-summary
107 test_expect_success "--no-patch in 'git diff-files --no-patch --$format' is a no-op" '
108 git diff-files --no-patch "--$format" >actual &&
109 git diff-files "--$format" >expect &&
110 test_cmp expect actual
113 test_expect_success "--no-patch clears all previous ones" '
114 git diff-files --$format -s -p >actual &&
115 git diff-files -p >expect &&
116 test_cmp expect actual
119 test_expect_success "--no-patch in 'git diff --no-patch --$format' is a no-op" '
120 git diff --no-patch "--$format" >actual &&
121 git diff "--$format" >expect &&
122 test_cmp expect actual
124 done
126 test_done