]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4000-diff-format.sh
The third batch
[thirdparty/git.git] / t / t4000-diff-format.sh
CommitLineData
13ab4462
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Test built-in diff output engine.
7
9d484b92
JH
8We happen to know that all diff plumbing and diff Porcelain share the
9same command line parser, so testing one should be sufficient; pick
10diff-files as a representative.
13ab4462 11'
16d4bd4f
ÆAB
12
13TEST_PASSES_SANITIZE_LEAK=true
13ab4462 14. ./test-lib.sh
ebd73f50 15. "$TEST_DIRECTORY"/lib-diff.sh
13ab4462
JH
16
17echo >path0 'Line 1
18Line 2
19line 3'
20cat path0 >path1
21chmod +x path1
9d484b92
JH
22mkdir path2
23>path2/path3
13ab4462 24
8ade9b14 25test_expect_success 'update-index --add two files with and without +x.' '
9d484b92 26 git update-index --add path0 path1 path2/path3
8ade9b14 27'
13ab4462
JH
28
29mv path0 path0-
30sed -e 's/line/Line/' <path0- >path0
31chmod +x path0
32rm -f path1
8ade9b14
MM
33test_expect_success 'git diff-files -p after editing work tree.' '
34 git diff-files -p >actual
35'
e58b97af
AR
36
37# that's as far as it comes
e0d10e1c 38if [ "$(git config --get core.filemode)" = false ]
e58b97af
AR
39then
40 say 'filemode disabled on the filesystem'
41 test_done
42fi
43
13ab4462 44cat >expected <<\EOF
b58f23b3
JH
45diff --git a/path0 b/path0
46old mode 100644
47new mode 100755
13ab4462
JH
48--- a/path0
49+++ b/path0
50@@ -1,3 +1,3 @@
51 Line 1
52 Line 2
53-line 3
54+Line 3
b58f23b3
JH
55diff --git a/path1 b/path1
56deleted file mode 100755
13ab4462
JH
57--- a/path1
58+++ /dev/null
59@@ -1,3 +0,0 @@
60-Line 1
61-Line 2
62-line 3
63EOF
64
8ade9b14
MM
65test_expect_success 'validate git diff-files -p output.' '
66 compare_diff_patch expected actual
67'
13ab4462 68
d09cd15d
MM
69test_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
73'
74
75test_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
79'
80
71482d38
MM
81test_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
84'
85
86test_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 &&
8cc5ff83 88 grep -q "^:100644 100755 .* $ZERO_OID M path0\$" actual &&
71482d38
MM
89 tail -n +4 actual >actual-patch &&
90 compare_diff_patch expected actual-patch
91'
92
93test_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
97'
98
9d484b92
JH
99
100# Smudge path2/path3 so that dirstat has something to show
101date >path2/path3
102
103for format in stat raw numstat shortstat summary \
104 dirstat cumulative dirstat-by-file \
105 patch-with-raw patch-with-stat compact-summary
106do
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
111 '
112
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
117 '
118
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
123 '
124done
125
13ab4462 126test_done