Sync with maint
[git/debian.git] / t / t3300-funny-names.sh
blob04de03cad0a7466106a125205742b5feea1b1e2f
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Pathnames with funny characters.
8 This test tries pathnames with funny characters in the working
9 tree, index, and tree objects.
12 . ./test-lib.sh
14 HT=' '
16 test_have_prereq MINGW ||
17 echo 2>/dev/null > "Name with an${HT}HT"
18 if ! test -f "Name with an${HT}HT"
19 then
20 # since FAT/NTFS does not allow tabs in filenames, skip this test
21 skip_all='Your filesystem does not allow tabs in filenames'
22 test_done
25 p0='no-funny'
26 p1='tabs ," (dq) and spaces'
27 p2='just space'
29 test_expect_success 'setup' '
30 cat >"$p0" <<-\EOF &&
31 1. A quick brown fox jumps over the lazy cat, oops dog.
32 2. A quick brown fox jumps over the lazy cat, oops dog.
33 3. A quick brown fox jumps over the lazy cat, oops dog.
34 EOF
36 { cat "$p0" >"$p1" || :; } &&
37 { echo "Foo Bar Baz" >"$p2" || :; }
40 test_expect_success 'setup: populate index and tree' '
41 git update-index --add "$p0" "$p2" &&
42 t0=$(git write-tree)
45 test_expect_success 'ls-files prints space in filename verbatim' '
46 printf "%s\n" "just space" no-funny >expected &&
47 git ls-files >current &&
48 test_cmp expected current
51 test_expect_success 'setup: add funny filename' '
52 git update-index --add "$p1" &&
53 t1=$(git write-tree)
56 test_expect_success 'ls-files quotes funny filename' '
57 cat >expected <<-\EOF &&
58 just space
59 no-funny
60 "tabs\t,\" (dq) and spaces"
61 EOF
62 git ls-files >current &&
63 test_cmp expected current
66 test_expect_success 'ls-files -z does not quote funny filename' '
67 cat >expected <<-\EOF &&
68 just space
69 no-funny
70 tabs ," (dq) and spaces
71 EOF
72 git ls-files -z >ls-files.z &&
73 perl -pe "y/\000/\012/" <ls-files.z >current &&
74 test_cmp expected current
77 test_expect_success 'ls-tree quotes funny filename' '
78 cat >expected <<-\EOF &&
79 just space
80 no-funny
81 "tabs\t,\" (dq) and spaces"
82 EOF
83 git ls-tree -r $t1 >ls-tree &&
84 sed -e "s/^[^ ]* //" <ls-tree >current &&
85 test_cmp expected current
88 test_expect_success 'diff-index --name-status quotes funny filename' '
89 cat >expected <<-\EOF &&
90 A "tabs\t,\" (dq) and spaces"
91 EOF
92 git diff-index --name-status $t0 >current &&
93 test_cmp expected current
96 test_expect_success 'diff-tree --name-status quotes funny filename' '
97 cat >expected <<-\EOF &&
98 A "tabs\t,\" (dq) and spaces"
99 EOF
100 git diff-tree --name-status $t0 $t1 >current &&
101 test_cmp expected current
104 test_expect_success 'diff-index -z does not quote funny filename' '
105 cat >expected <<-\EOF &&
107 tabs ," (dq) and spaces
109 git diff-index -z --name-status $t0 >diff-index.z &&
110 perl -pe "y/\000/\012/" <diff-index.z >current &&
111 test_cmp expected current
114 test_expect_success 'diff-tree -z does not quote funny filename' '
115 cat >expected <<-\EOF &&
117 tabs ," (dq) and spaces
119 git diff-tree -z --name-status $t0 $t1 >diff-tree.z &&
120 perl -pe y/\\000/\\012/ <diff-tree.z >current &&
121 test_cmp expected current
124 test_expect_success 'diff-tree --find-copies-harder quotes funny filename' '
125 cat >expected <<-\EOF &&
126 CNUM no-funny "tabs\t,\" (dq) and spaces"
128 git diff-tree -C --find-copies-harder --name-status $t0 $t1 >out &&
129 sed -e "s/^C[0-9]*/CNUM/" <out >current &&
130 test_cmp expected current
133 test_expect_success 'setup: remove unfunny index entry' '
134 git update-index --force-remove "$p0"
137 test_expect_success 'diff-tree -M quotes funny filename' '
138 cat >expected <<-\EOF &&
139 RNUM no-funny "tabs\t,\" (dq) and spaces"
141 git diff-index -M --name-status $t0 >out &&
142 sed -e "s/^R[0-9]*/RNUM/" <out >current &&
143 test_cmp expected current
146 test_expect_success 'diff-index -M -p quotes funny filename' '
147 cat >expected <<-\EOF &&
148 diff --git a/no-funny "b/tabs\t,\" (dq) and spaces"
149 similarity index NUM%
150 rename from no-funny
151 rename to "tabs\t,\" (dq) and spaces"
153 git diff-index -M -p $t0 >diff &&
154 sed -e "s/index [0-9]*%/index NUM%/" <diff >current &&
155 test_cmp expected current
158 test_expect_success 'setup: mode change' '
159 chmod +x "$p1"
162 test_expect_success 'diff-index -M -p with mode change quotes funny filename' '
163 cat >expected <<-\EOF &&
164 diff --git a/no-funny "b/tabs\t,\" (dq) and spaces"
165 old mode 100644
166 new mode 100755
167 similarity index NUM%
168 rename from no-funny
169 rename to "tabs\t,\" (dq) and spaces"
171 git diff-index -M -p $t0 >diff &&
172 sed -e "s/index [0-9]*%/index NUM%/" <diff >current &&
173 test_cmp expected current
176 test_expect_success 'diffstat for rename quotes funny filename' '
177 cat >expected <<-\EOF &&
178 "tabs\t,\" (dq) and spaces"
179 1 file changed, 0 insertions(+), 0 deletions(-)
181 git diff-index -M -p $t0 >diff &&
182 git apply --stat <diff >diffstat &&
183 sed -e "s/|.*//" -e "s/ *\$//" <diffstat >current &&
184 test_i18ncmp expected current
187 test_expect_success 'numstat for rename quotes funny filename' '
188 cat >expected <<-\EOF &&
189 0 0 "tabs\t,\" (dq) and spaces"
191 git diff-index -M -p $t0 >diff &&
192 git apply --numstat <diff >current &&
193 test_cmp expected current
196 test_expect_success 'numstat without -M quotes funny filename' '
197 cat >expected <<-\EOF &&
198 0 3 no-funny
199 3 0 "tabs\t,\" (dq) and spaces"
201 git diff-index -p $t0 >diff &&
202 git apply --numstat <diff >current &&
203 test_cmp expected current
206 test_expect_success 'numstat for non-git rename diff quotes funny filename' '
207 cat >expected <<-\EOF &&
208 0 3 no-funny
209 3 0 "tabs\t,\" (dq) and spaces"
211 git diff-index -p $t0 >git-diff &&
212 sed -ne "/^[-+@]/p" <git-diff >diff &&
213 git apply --numstat <diff >current &&
214 test_cmp expected current
217 test_done