Merge branch 'nd/branch-show-rebase-bisect-state'
[git/jnareb-git.git] / t / t3300-funny-names.sh
blob7480d6e7c2a8d14c5f75875d47eefe96ca9c5010
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 echo 2>/dev/null > "Name with an${HT}HT"
17 if ! test -f "Name with an${HT}HT"
18 then
19 # since FAT/NTFS does not allow tabs in filenames, skip this test
20 skip_all='Your filesystem does not allow tabs in filenames'
21 test_done
24 p0='no-funny'
25 p1='tabs ," (dq) and spaces'
26 p2='just space'
28 test_expect_success 'setup' '
29 cat >"$p0" <<-\EOF &&
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.
33 EOF
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" &&
41 t0=$(git write-tree)
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" &&
52 t1=$(git write-tree)
55 test_expect_success 'ls-files quotes funny filename' '
56 cat >expected <<-\EOF &&
57 just space
58 no-funny
59 "tabs\t,\" (dq) and spaces"
60 EOF
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 &&
67 just space
68 no-funny
69 tabs ," (dq) and spaces
70 EOF
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 &&
78 just space
79 no-funny
80 "tabs\t,\" (dq) and spaces"
81 EOF
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"
90 EOF
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"
98 EOF
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%
149 rename from no-funny
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' '
158 chmod +x "$p1"
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"
164 old mode 100644
165 new mode 100755
166 similarity index NUM%
167 rename from no-funny
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 &&
197 0 3 no-funny
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 &&
207 0 3 no-funny
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
216 test_done