]>
Commit | Line | Data |
---|---|---|
f3999e03 BP |
1 | #!/bin/sh |
2 | ||
3 | test_description='diff --no-index' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup' ' | |
8 | mkdir a && | |
9 | mkdir b && | |
10 | echo 1 >a/1 && | |
546e0fd9 JK |
11 | echo 2 >a/2 && |
12 | git init repo && | |
13 | echo 1 >repo/a && | |
14 | mkdir -p non/git && | |
15 | echo 1 >non/git/a && | |
16 | echo 1 >non/git/b | |
f3999e03 BP |
17 | ' |
18 | ||
19 | test_expect_success 'git diff --no-index directories' ' | |
c21fc9d0 JK |
20 | test_expect_code 1 git diff --no-index a b >cnt && |
21 | test_line_count = 14 cnt | |
f3999e03 BP |
22 | ' |
23 | ||
546e0fd9 JK |
24 | test_expect_success 'git diff --no-index relative path outside repo' ' |
25 | ( | |
26 | cd repo && | |
27 | test_expect_code 0 git diff --no-index a ../non/git/a && | |
28 | test_expect_code 0 git diff --no-index ../non/git/a ../non/git/b | |
29 | ) | |
30 | ' | |
31 | ||
6df5762d TG |
32 | test_expect_success 'git diff --no-index with broken index' ' |
33 | ( | |
34 | cd repo && | |
35 | echo broken >.git/index && | |
36 | git diff --no-index a ../non/git/a | |
37 | ) | |
38 | ' | |
39 | ||
40 | test_expect_success 'git diff outside repo with broken index' ' | |
41 | ( | |
42 | cd repo && | |
43 | git diff ../non/git/a ../non/git/b | |
44 | ) | |
45 | ' | |
46 | ||
8a19dfa1 TG |
47 | test_expect_success 'git diff --no-index executed outside repo gives correct error message' ' |
48 | ( | |
49 | GIT_CEILING_DIRECTORIES=$TRASH_DIRECTORY/non && | |
50 | export GIT_CEILING_DIRECTORIES && | |
51 | cd non/git && | |
52 | test_must_fail git diff --no-index a 2>actual.err && | |
16bb3d71 | 53 | test_i18ngrep "usage: git diff --no-index" actual.err |
8a19dfa1 TG |
54 | ) |
55 | ' | |
56 | ||
c9e1f2c7 JH |
57 | test_expect_success 'diff D F and diff F D' ' |
58 | ( | |
59 | cd repo && | |
60 | echo in-repo >a && | |
61 | echo non-repo >../non/git/a && | |
62 | mkdir sub && | |
63 | echo sub-repo >sub/a && | |
64 | ||
65 | test_must_fail git diff --no-index sub/a ../non/git/a >expect && | |
66 | test_must_fail git diff --no-index sub/a ../non/git/ >actual && | |
67 | test_cmp expect actual && | |
68 | ||
69 | test_must_fail git diff --no-index a ../non/git/a >expect && | |
70 | test_must_fail git diff --no-index a ../non/git/ >actual && | |
71 | test_cmp expect actual && | |
72 | ||
73 | test_must_fail git diff --no-index ../non/git/a a >expect && | |
74 | test_must_fail git diff --no-index ../non/git a >actual && | |
75 | test_cmp expect actual | |
76 | ) | |
77 | ' | |
78 | ||
06151739 JH |
79 | test_expect_success 'turning a file into a directory' ' |
80 | ( | |
81 | cd non/git && | |
82 | mkdir d e e/sub && | |
83 | echo 1 >d/sub && | |
84 | echo 2 >e/sub/file && | |
85 | printf "D\td/sub\nA\te/sub/file\n" >expect && | |
86 | test_must_fail git diff --no-index --name-status d e >actual && | |
87 | test_cmp expect actual | |
88 | ) | |
89 | ' | |
90 | ||
7d8930d9 JK |
91 | test_expect_success 'diff from repo subdir shows real paths (explicit)' ' |
92 | echo "diff --git a/../../non/git/a b/../../non/git/b" >expect && | |
93 | test_expect_code 1 \ | |
94 | git -C repo/sub \ | |
95 | diff --no-index ../../non/git/a ../../non/git/b >actual && | |
96 | head -n 1 <actual >actual.head && | |
97 | test_cmp expect actual.head | |
98 | ' | |
99 | ||
100 | test_expect_success 'diff from repo subdir shows real paths (implicit)' ' | |
101 | echo "diff --git a/../../non/git/a b/../../non/git/b" >expect && | |
102 | test_expect_code 1 \ | |
103 | git -C repo/sub \ | |
104 | diff ../../non/git/a ../../non/git/b >actual && | |
105 | head -n 1 <actual >actual.head && | |
106 | test_cmp expect actual.head | |
107 | ' | |
108 | ||
28a4e580 JK |
109 | test_expect_success 'diff --no-index from repo subdir respects config (explicit)' ' |
110 | echo "diff --git ../../non/git/a ../../non/git/b" >expect && | |
111 | test_config -C repo diff.noprefix true && | |
112 | test_expect_code 1 \ | |
113 | git -C repo/sub \ | |
114 | diff --no-index ../../non/git/a ../../non/git/b >actual && | |
115 | head -n 1 <actual >actual.head && | |
116 | test_cmp expect actual.head | |
117 | ' | |
118 | ||
119 | test_expect_success 'diff --no-index from repo subdir respects config (implicit)' ' | |
120 | echo "diff --git ../../non/git/a ../../non/git/b" >expect && | |
121 | test_config -C repo diff.noprefix true && | |
122 | test_expect_code 1 \ | |
123 | git -C repo/sub \ | |
124 | diff ../../non/git/a ../../non/git/b >actual && | |
125 | head -n 1 <actual >actual.head && | |
126 | test_cmp expect actual.head | |
127 | ' | |
128 | ||
ffd04e92 JS |
129 | test_expect_success 'diff --no-index from repo subdir with absolute paths' ' |
130 | cat <<-EOF >expect && | |
131 | 1 1 $(pwd)/non/git/{a => b} | |
132 | EOF | |
133 | test_expect_code 1 \ | |
134 | git -C repo/sub diff --numstat \ | |
135 | "$(pwd)/non/git/a" "$(pwd)/non/git/b" >actual && | |
136 | test_cmp expect actual | |
137 | ' | |
138 | ||
287ab28b JK |
139 | test_expect_success 'diff --no-index allows external diff' ' |
140 | test_expect_code 1 \ | |
141 | env GIT_EXTERNAL_DIFF="echo external ;:" \ | |
142 | git diff --no-index non/git/a non/git/b >actual && | |
143 | echo external >expect && | |
144 | test_cmp expect actual | |
145 | ' | |
146 | ||
f3999e03 | 147 | test_done |