Junio C Hamano | 4d2060e | 2005-10-15 16:15:49 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
| 6 | test_description='Pathnames with funny characters. |
| 7 | |
| 8 | This test tries pathnames with funny characters in the working |
| 9 | tree, index, and tree objects. |
| 10 | ' |
| 11 | |
| 12 | . ./test-lib.sh |
| 13 | |
Ramsay Jones | 46d9847 | 2012-09-01 19:08:42 +0100 | [diff] [blame] | 14 | HT=' ' |
| 15 | |
| 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 |
| 22 | fi |
| 23 | |
Junio C Hamano | 4d2060e | 2005-10-15 16:15:49 -0700 | [diff] [blame] | 24 | p0='no-funny' |
Junio C Hamano | 73ab46d | 2005-12-10 18:36:15 -0800 | [diff] [blame] | 25 | p1='tabs ," (dq) and spaces' |
Junio C Hamano | 508c1d1 | 2005-10-17 13:32:14 -0700 | [diff] [blame] | 26 | p2='just space' |
Junio C Hamano | 4d2060e | 2005-10-15 16:15:49 -0700 | [diff] [blame] | 27 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 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 |
Junio C Hamano | 4d2060e | 2005-10-15 16:15:49 -0700 | [diff] [blame] | 34 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 35 | { cat "$p0" >"$p1" || :; } && |
Ramsay Jones | 46d9847 | 2012-09-01 19:08:42 +0100 | [diff] [blame] | 36 | { echo "Foo Bar Baz" >"$p2" || :; } |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 37 | ' |
| 38 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 39 | test_expect_success 'setup: populate index and tree' ' |
| 40 | git update-index --add "$p0" "$p2" && |
| 41 | t0=$(git write-tree) |
| 42 | ' |
Ævar Arnfjörð Bjarmason | e1697cc | 2010-08-11 19:04:10 +0000 | [diff] [blame] | 43 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 44 | test_expect_success 'ls-files prints space in filename verbatim' ' |
| 45 | printf "%s\n" "just space" no-funny >expected && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 46 | git ls-files >current && |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 47 | test_cmp expected current |
Ævar Arnfjörð Bjarmason | e1697cc | 2010-08-11 19:04:10 +0000 | [diff] [blame] | 48 | ' |
| 49 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 50 | test_expect_success 'setup: add funny filename' ' |
| 51 | git update-index --add "$p1" && |
| 52 | t1=$(git write-tree) |
| 53 | ' |
| 54 | |
| 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 |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 61 | git ls-files >current && |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 62 | test_cmp expected current |
Ævar Arnfjörð Bjarmason | e1697cc | 2010-08-11 19:04:10 +0000 | [diff] [blame] | 63 | ' |
| 64 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 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 && |
Jeff King | 94221d2 | 2013-10-28 21:23:03 -0400 | [diff] [blame] | 72 | perl -pe "y/\000/\012/" <ls-files.z >current && |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 73 | test_cmp expected current |
Ævar Arnfjörð Bjarmason | e1697cc | 2010-08-11 19:04:10 +0000 | [diff] [blame] | 74 | ' |
| 75 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 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 |
Ævar Arnfjörð Bjarmason | e1697cc | 2010-08-11 19:04:10 +0000 | [diff] [blame] | 85 | ' |
| 86 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 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 |
Ævar Arnfjörð Bjarmason | e1697cc | 2010-08-11 19:04:10 +0000 | [diff] [blame] | 93 | ' |
| 94 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 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 |
Ævar Arnfjörð Bjarmason | e1697cc | 2010-08-11 19:04:10 +0000 | [diff] [blame] | 101 | ' |
| 102 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 103 | test_expect_success 'diff-index -z does not quote funny filename' ' |
| 104 | cat >expected <<-\EOF && |
| 105 | A |
| 106 | tabs ," (dq) and spaces |
| 107 | EOF |
| 108 | git diff-index -z --name-status $t0 >diff-index.z && |
Jeff King | 94221d2 | 2013-10-28 21:23:03 -0400 | [diff] [blame] | 109 | perl -pe "y/\000/\012/" <diff-index.z >current && |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 110 | test_cmp expected current |
Ævar Arnfjörð Bjarmason | e1697cc | 2010-08-11 19:04:10 +0000 | [diff] [blame] | 111 | ' |
| 112 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 113 | test_expect_success 'diff-tree -z does not quote funny filename' ' |
| 114 | cat >expected <<-\EOF && |
| 115 | A |
| 116 | tabs ," (dq) and spaces |
| 117 | EOF |
| 118 | git diff-tree -z --name-status $t0 $t1 >diff-tree.z && |
Jeff King | 94221d2 | 2013-10-28 21:23:03 -0400 | [diff] [blame] | 119 | perl -pe y/\\000/\\012/ <diff-tree.z >current && |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 120 | test_cmp expected current |
Ævar Arnfjörð Bjarmason | e1697cc | 2010-08-11 19:04:10 +0000 | [diff] [blame] | 121 | ' |
| 122 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 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" |
| 126 | EOF |
| 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 |
| 130 | ' |
Junio C Hamano | 4d2060e | 2005-10-15 16:15:49 -0700 | [diff] [blame] | 131 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 132 | test_expect_success 'setup: remove unfunny index entry' ' |
| 133 | git update-index --force-remove "$p0" |
| 134 | ' |
| 135 | |
| 136 | test_expect_success 'diff-tree -M quotes funny filename' ' |
| 137 | cat >expected <<-\EOF && |
| 138 | RNUM no-funny "tabs\t,\" (dq) and spaces" |
| 139 | EOF |
| 140 | git diff-index -M --name-status $t0 >out && |
| 141 | sed -e "s/^R[0-9]*/RNUM/" <out >current && |
| 142 | test_cmp expected current |
| 143 | ' |
| 144 | |
| 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" |
| 151 | EOF |
| 152 | git diff-index -M -p $t0 >diff && |
| 153 | sed -e "s/index [0-9]*%/index NUM%/" <diff >current && |
| 154 | test_cmp expected current |
| 155 | ' |
| 156 | |
| 157 | test_expect_success 'setup: mode change' ' |
| 158 | chmod +x "$p1" |
| 159 | ' |
| 160 | |
| 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" |
| 169 | EOF |
| 170 | git diff-index -M -p $t0 >diff && |
| 171 | sed -e "s/index [0-9]*%/index NUM%/" <diff >current && |
| 172 | test_cmp expected current |
| 173 | ' |
| 174 | |
| 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(-) |
| 179 | EOF |
| 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 |
| 184 | ' |
| 185 | |
| 186 | test_expect_success 'numstat for rename quotes funny filename' ' |
| 187 | cat >expected <<-\EOF && |
Jonathan Nieder | e7a8ac3 | 2012-03-12 23:58:59 -0500 | [diff] [blame] | 188 | 0 0 "tabs\t,\" (dq) and spaces" |
| 189 | EOF |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 190 | git diff-index -M -p $t0 >diff && |
| 191 | git apply --numstat <diff >current && |
| 192 | test_cmp expected current |
Ævar Arnfjörð Bjarmason | e1697cc | 2010-08-11 19:04:10 +0000 | [diff] [blame] | 193 | ' |
| 194 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 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" |
| 199 | EOF |
| 200 | git diff-index -p $t0 >diff && |
| 201 | git apply --numstat <diff >current && |
| 202 | test_cmp expected current |
| 203 | ' |
Junio C Hamano | 4d2060e | 2005-10-15 16:15:49 -0700 | [diff] [blame] | 204 | |
Jonathan Nieder | ef7db19 | 2012-03-12 23:59:52 -0500 | [diff] [blame] | 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" |
| 209 | EOF |
| 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 |
| 214 | ' |
Junio C Hamano | 4d2060e | 2005-10-15 16:15:49 -0700 | [diff] [blame] | 215 | |
| 216 | test_done |