3 test_description='diff --no-index'
7 test_expect_success 'setup' '
19 test_expect_success 'git diff --no-index --exit-code' '
20 git diff --no-index --exit-code a/1 non/git/a &&
21 test_expect_code 1 git diff --no-index --exit-code a/1 a/2
24 test_expect_success 'git diff --no-index directories' '
25 test_expect_code 1 git diff --no-index a b >cnt &&
26 test_line_count = 14 cnt
29 test_expect_success 'git diff --no-index relative path outside repo' '
32 test_expect_code 0 git diff --no-index a ../non/git/a &&
33 test_expect_code 0 git diff --no-index ../non/git/a ../non/git/b
37 test_expect_success 'git diff --no-index with broken index' '
40 echo broken >.git/index &&
41 git diff --no-index a ../non/git/a
45 test_expect_success 'git diff outside repo with broken index' '
48 git diff ../non/git/a ../non/git/b
52 test_expect_success 'git diff --no-index executed outside repo gives correct error message' '
54 GIT_CEILING_DIRECTORIES=$TRASH_DIRECTORY/non &&
55 export GIT_CEILING_DIRECTORIES &&
57 test_must_fail git diff --no-index a 2>actual.err &&
58 test_i18ngrep "usage: git diff --no-index" actual.err
62 test_expect_success 'diff D F and diff F D' '
66 echo non-repo >../non/git/a &&
68 echo sub-repo >sub/a &&
70 test_must_fail git diff --no-index sub/a ../non/git/a >expect &&
71 test_must_fail git diff --no-index sub/a ../non/git/ >actual &&
72 test_cmp expect actual &&
74 test_must_fail git diff --no-index a ../non/git/a >expect &&
75 test_must_fail git diff --no-index a ../non/git/ >actual &&
76 test_cmp expect actual &&
78 test_must_fail git diff --no-index ../non/git/a a >expect &&
79 test_must_fail git diff --no-index ../non/git a >actual &&
80 test_cmp expect actual
84 test_expect_success 'turning a file into a directory' '
90 printf "D\td/sub\nA\te/sub/file\n" >expect &&
91 test_must_fail git diff --no-index --name-status d e >actual &&
92 test_cmp expect actual
96 test_expect_success 'diff from repo subdir shows real paths (explicit)' '
97 echo "diff --git a/../../non/git/a b/../../non/git/b" >expect &&
100 diff --no-index ../../non/git/a ../../non/git/b >actual &&
101 head -n 1 <actual >actual.head &&
102 test_cmp expect actual.head
105 test_expect_success 'diff from repo subdir shows real paths (implicit)' '
106 echo "diff --git a/../../non/git/a b/../../non/git/b" >expect &&
109 diff ../../non/git/a ../../non/git/b >actual &&
110 head -n 1 <actual >actual.head &&
111 test_cmp expect actual.head
114 test_expect_success 'diff --no-index from repo subdir respects config (explicit)' '
115 echo "diff --git ../../non/git/a ../../non/git/b" >expect &&
116 test_config -C repo diff.noprefix true &&
119 diff --no-index ../../non/git/a ../../non/git/b >actual &&
120 head -n 1 <actual >actual.head &&
121 test_cmp expect actual.head
124 test_expect_success 'diff --no-index from repo subdir respects config (implicit)' '
125 echo "diff --git ../../non/git/a ../../non/git/b" >expect &&
126 test_config -C repo diff.noprefix true &&
129 diff ../../non/git/a ../../non/git/b >actual &&
130 head -n 1 <actual >actual.head &&
131 test_cmp expect actual.head
134 test_expect_success 'diff --no-index from repo subdir with absolute paths' '
135 cat <<-EOF >expect &&
136 1 1 $(pwd)/non/git/{a => b}
139 git -C repo/sub diff --numstat \
140 "$(pwd)/non/git/a" "$(pwd)/non/git/b" >actual &&
141 test_cmp expect actual
144 test_expect_success 'diff --no-index allows external diff' '
146 env GIT_EXTERNAL_DIFF="echo external ;:" \
147 git diff --no-index non/git/a non/git/b >actual &&
148 echo external >expect &&
149 test_cmp expect actual
152 test_expect_success 'diff --no-index normalizes mode: no changes' '
155 git diff --no-index x y >out &&
156 test_must_be_empty out
159 test_expect_success POSIXPERM 'diff --no-index normalizes mode: chmod +x' '
161 cat >expected <<-\EOF &&
166 test_expect_code 1 git diff --no-index x y >actual &&
167 test_cmp expected actual
170 test_expect_success POSIXPERM 'diff --no-index normalizes: mode not like git mode' '
173 cat >expected <<-\EOF &&
178 test_expect_code 1 git diff --no-index x y >actual &&
179 test_cmp expected actual
182 test_expect_success POSIXPERM,SYMLINKS 'diff --no-index normalizes: mode not like git mode (symlink)' '
184 X_OID=$(git hash-object --stdin <x) &&
185 Z_OID=$(printf y | git hash-object --stdin) &&
186 cat >expected <<-EOF &&
188 deleted file mode 100644
189 index $X_OID..$ZERO_OID
196 index $ZERO_OID..$Z_OID
201 \ No newline at end of file
203 test_expect_code 1 git -c core.abbrev=no diff --no-index x z >actual &&
204 test_cmp expected actual