Git fork
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Test built-in diff output engine.
7
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.
11'
12
13. ./test-lib.sh
14. "$TEST_DIRECTORY"/lib-diff.sh
15
16echo >path0 'Line 1
17Line 2
18line 3'
19cat path0 >path1
20chmod +x path1
21mkdir path2
22>path2/path3
23
24test_expect_success 'update-index --add two files with and without +x.' '
25 git update-index --add path0 path1 path2/path3
26'
27
28mv path0 path0-
29sed -e 's/line/Line/' <path0- >path0
30chmod +x path0
31rm -f path1
32test_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
37if [ "$(git config --get core.filemode)" = false ]
38then
39 skip_all='filemode disabled on the filesystem'
40 test_done
41fi
42
43cat >expected <<\EOF
44diff --git a/path0 b/path0
45old mode 100644
46new 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
54diff --git a/path1 b/path1
55deleted file mode 100755
56--- a/path1
57+++ /dev/null
58@@ -1,3 +0,0 @@
59-Line 1
60-Line 2
61-line 3
62EOF
63
64test_expect_success 'validate git diff-files -p output.' '
65 compare_diff_patch expected actual
66'
67
68test_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
74test_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
80test_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
85test_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 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
92test_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
100date >path2/path3
101
102for format in stat raw numstat shortstat summary \
103 dirstat cumulative dirstat-by-file \
104 patch-with-raw patch-with-stat compact-summary
105do
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 '
123done
124
125test_done