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.
16 echo 2>/dev
/null
> "Name with an${HT}HT"
17 if ! test -f "Name with an${HT}HT"
19 # since FAT/NTFS does not allow tabs in filenames, skip this test
20 skip_all
='Your filesystem does not allow tabs in filenames'
25 p1
='tabs ," (dq) and spaces'
28 test_expect_success
'setup' '
30 1. A quick brown fox jumps over the lazy cat, oops dog.
31 2. A quick brown fox jumps over the lazy cat, oops dog.
32 3. A quick brown fox jumps over the lazy cat, oops dog.
35 { cat "$p0" >"$p1" || :; } &&
36 { echo "Foo Bar Baz" >"$p2" || :; }
39 test_expect_success
'setup: populate index and tree' '
40 git update-index --add "$p0" "$p2" &&
44 test_expect_success
'ls-files prints space in filename verbatim' '
45 printf "%s\n" "just space" no-funny >expected &&
46 git ls-files >current &&
47 test_cmp expected current
50 test_expect_success
'setup: add funny filename' '
51 git update-index --add "$p1" &&
55 test_expect_success
'ls-files quotes funny filename' '
56 cat >expected <<-\EOF &&
59 "tabs\t,\" (dq) and spaces"
61 git ls-files >current &&
62 test_cmp expected current
65 test_expect_success
'ls-files -z does not quote funny filename' '
66 cat >expected <<-\EOF &&
69 tabs ," (dq) and spaces
71 git ls-files -z >ls-files.z &&
72 "$PERL_PATH" -pe "y/\000/\012/" <ls-files.z >current &&
73 test_cmp expected current
76 test_expect_success
'ls-tree quotes funny filename' '
77 cat >expected <<-\EOF &&
80 "tabs\t,\" (dq) and spaces"
82 git ls-tree -r $t1 >ls-tree &&
83 sed -e "s/^[^ ]* //" <ls-tree >current &&
84 test_cmp expected current
87 test_expect_success
'diff-index --name-status quotes funny filename' '
88 cat >expected <<-\EOF &&
89 A "tabs\t,\" (dq) and spaces"
91 git diff-index --name-status $t0 >current &&
92 test_cmp expected current
95 test_expect_success
'diff-tree --name-status quotes funny filename' '
96 cat >expected <<-\EOF &&
97 A "tabs\t,\" (dq) and spaces"
99 git diff-tree --name-status $t0 $t1 >current &&
100 test_cmp expected current
103 test_expect_success
'diff-index -z does not quote funny filename' '
104 cat >expected <<-\EOF &&
106 tabs ," (dq) and spaces
108 git diff-index -z --name-status $t0 >diff-index.z &&
109 "$PERL_PATH" -pe "y/\000/\012/" <diff-index.z >current &&
110 test_cmp expected current
113 test_expect_success
'diff-tree -z does not quote funny filename' '
114 cat >expected <<-\EOF &&
116 tabs ," (dq) and spaces
118 git diff-tree -z --name-status $t0 $t1 >diff-tree.z &&
119 "$PERL_PATH" -pe y/\\000/\\012/ <diff-tree.z >current &&
120 test_cmp expected current
123 test_expect_success
'diff-tree --find-copies-harder quotes funny filename' '
124 cat >expected <<-\EOF &&
125 CNUM no-funny "tabs\t,\" (dq) and spaces"
127 git diff-tree -C --find-copies-harder --name-status $t0 $t1 >out &&
128 sed -e "s/^C[0-9]*/CNUM/" <out >current &&
129 test_cmp expected current
132 test_expect_success
'setup: remove unfunny index entry' '
133 git update-index --force-remove "$p0"
136 test_expect_success
'diff-tree -M quotes funny filename' '
137 cat >expected <<-\EOF &&
138 RNUM no-funny "tabs\t,\" (dq) and spaces"
140 git diff-index -M --name-status $t0 >out &&
141 sed -e "s/^R[0-9]*/RNUM/" <out >current &&
142 test_cmp expected current
145 test_expect_success
'diff-index -M -p quotes funny filename' '
146 cat >expected <<-\EOF &&
147 diff --git a/no-funny "b/tabs\t,\" (dq) and spaces"
148 similarity index NUM%
150 rename to "tabs\t,\" (dq) and spaces"
152 git diff-index -M -p $t0 >diff &&
153 sed -e "s/index [0-9]*%/index NUM%/" <diff >current &&
154 test_cmp expected current
157 test_expect_success
'setup: mode change' '
161 test_expect_success
'diff-index -M -p with mode change quotes funny filename' '
162 cat >expected <<-\EOF &&
163 diff --git a/no-funny "b/tabs\t,\" (dq) and spaces"
166 similarity index NUM%
168 rename to "tabs\t,\" (dq) and spaces"
170 git diff-index -M -p $t0 >diff &&
171 sed -e "s/index [0-9]*%/index NUM%/" <diff >current &&
172 test_cmp expected current
175 test_expect_success
'diffstat for rename quotes funny filename' '
176 cat >expected <<-\EOF &&
177 "tabs\t,\" (dq) and spaces"
178 1 file changed, 0 insertions(+), 0 deletions(-)
180 git diff-index -M -p $t0 >diff &&
181 git apply --stat <diff >diffstat &&
182 sed -e "s/|.*//" -e "s/ *\$//" <diffstat >current &&
183 test_i18ncmp expected current
186 test_expect_success
'numstat for rename quotes funny filename' '
187 cat >expected <<-\EOF &&
188 0 0 "tabs\t,\" (dq) and spaces"
190 git diff-index -M -p $t0 >diff &&
191 git apply --numstat <diff >current &&
192 test_cmp expected current
195 test_expect_success
'numstat without -M quotes funny filename' '
196 cat >expected <<-\EOF &&
198 3 0 "tabs\t,\" (dq) and spaces"
200 git diff-index -p $t0 >diff &&
201 git apply --numstat <diff >current &&
202 test_cmp expected current
205 test_expect_success
'numstat for non-git rename diff quotes funny filename' '
206 cat >expected <<-\EOF &&
208 3 0 "tabs\t,\" (dq) and spaces"
210 git diff-index -p $t0 >git-diff &&
211 sed -ne "/^[-+@]/p" <git-diff >diff &&
212 git apply --numstat <diff >current &&
213 test_cmp expected current