blob: bfcaae390f3ad95584ce9cf78b62cc81c33adf67 [file] [log] [blame]
Junio C Hamano13ab4462005-05-13 22:52:42 -07001#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Test built-in diff output engine.
7
8'
Ævar Arnfjörð Bjarmason16d4bd42021-10-31 00:24:19 +02009
10TEST_PASSES_SANITIZE_LEAK=true
Junio C Hamano13ab4462005-05-13 22:52:42 -070011. ./test-lib.sh
Ævar Arnfjörð Bjarmasonebd73f52021-02-12 14:29:40 +010012. "$TEST_DIRECTORY"/lib-diff.sh
Junio C Hamano13ab4462005-05-13 22:52:42 -070013
14echo >path0 'Line 1
15Line 2
16line 3'
17cat path0 >path1
18chmod +x path1
19
Matthieu Moy8ade9b12013-07-16 10:05:35 +020020test_expect_success 'update-index --add two files with and without +x.' '
21 git update-index --add path0 path1
22'
Junio C Hamano13ab4462005-05-13 22:52:42 -070023
24mv path0 path0-
25sed -e 's/line/Line/' <path0- >path0
26chmod +x path0
27rm -f path1
Matthieu Moy8ade9b12013-07-16 10:05:35 +020028test_expect_success 'git diff-files -p after editing work tree.' '
29 git diff-files -p >actual
30'
Alex Riesene58b97a2006-01-05 12:55:03 +010031
32# that's as far as it comes
Tom Princee0d10e12007-01-28 16:16:53 -080033if [ "$(git config --get core.filemode)" = false ]
Alex Riesene58b97a2006-01-05 12:55:03 +010034then
35 say 'filemode disabled on the filesystem'
36 test_done
37fi
38
Junio C Hamano13ab4462005-05-13 22:52:42 -070039cat >expected <<\EOF
Junio C Hamanob58f23b2005-05-18 09:10:47 -070040diff --git a/path0 b/path0
41old mode 100644
42new mode 100755
Junio C Hamano13ab4462005-05-13 22:52:42 -070043--- a/path0
44+++ b/path0
45@@ -1,3 +1,3 @@
46 Line 1
47 Line 2
48-line 3
49+Line 3
Junio C Hamanob58f23b2005-05-18 09:10:47 -070050diff --git a/path1 b/path1
51deleted file mode 100755
Junio C Hamano13ab4462005-05-13 22:52:42 -070052--- a/path1
53+++ /dev/null
54@@ -1,3 +0,0 @@
55-Line 1
56-Line 2
57-line 3
58EOF
59
Matthieu Moy8ade9b12013-07-16 10:05:35 +020060test_expect_success 'validate git diff-files -p output.' '
61 compare_diff_patch expected actual
62'
Junio C Hamano13ab4462005-05-13 22:52:42 -070063
Matthieu Moyd09cd152013-07-16 10:05:36 +020064test_expect_success 'git diff-files -s after editing work tree' '
65 git diff-files -s >actual 2>err &&
66 test_must_be_empty actual &&
67 test_must_be_empty err
68'
69
70test_expect_success 'git diff-files --no-patch as synonym for -s' '
71 git diff-files --no-patch >actual 2>err &&
72 test_must_be_empty actual &&
73 test_must_be_empty err
74'
75
Matthieu Moy71482d32013-07-16 10:05:37 +020076test_expect_success 'git diff-files --no-patch --patch shows the patch' '
77 git diff-files --no-patch --patch >actual &&
78 compare_diff_patch expected actual
79'
80
81test_expect_success 'git diff-files --no-patch --patch-with-raw shows the patch and raw data' '
82 git diff-files --no-patch --patch-with-raw >actual &&
brian m. carlson8cc5ff82019-08-26 01:43:42 +000083 grep -q "^:100644 100755 .* $ZERO_OID M path0\$" actual &&
Matthieu Moy71482d32013-07-16 10:05:37 +020084 tail -n +4 actual >actual-patch &&
85 compare_diff_patch expected actual-patch
86'
87
88test_expect_success 'git diff-files --patch --no-patch does not show the patch' '
89 git diff-files --patch --no-patch >actual 2>err &&
90 test_must_be_empty actual &&
91 test_must_be_empty err
92'
93
Junio C Hamano13ab4462005-05-13 22:52:42 -070094test_done