t / t3300-funny-names.shon commit t3404: rebase -i: demonstrate short SHA-1 collision (66ae9a5)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='Pathnames with funny characters.
   7
   8This test tries pathnames with funny characters in the working
   9tree, index, and tree objects.
  10'
  11
  12. ./test-lib.sh
  13
  14HT='    '
  15
  16echo 2>/dev/null > "Name with an${HT}HT"
  17if ! test -f "Name with an${HT}HT"
  18then
  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
  22fi
  23
  24p0='no-funny'
  25p1='tabs        ," (dq) and spaces'
  26p2='just space'
  27
  28test_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
  34
  35        { cat "$p0" >"$p1" || :; } &&
  36        { echo "Foo Bar Baz" >"$p2" || :; }
  37'
  38
  39test_expect_success 'setup: populate index and tree' '
  40        git update-index --add "$p0" "$p2" &&
  41        t0=$(git write-tree)
  42'
  43
  44test_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
  48'
  49
  50test_expect_success 'setup: add funny filename' '
  51        git update-index --add "$p1" &&
  52        t1=$(git write-tree)
  53'
  54
  55test_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
  63'
  64
  65test_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
  74'
  75
  76test_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
  85'
  86
  87test_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
  93'
  94
  95test_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
 101'
 102
 103test_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 &&
 109        "$PERL_PATH" -pe "y/\000/\012/" <diff-index.z >current &&
 110        test_cmp expected current
 111'
 112
 113test_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 &&
 119        "$PERL_PATH" -pe y/\\000/\\012/ <diff-tree.z >current &&
 120        test_cmp expected current
 121'
 122
 123test_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'
 131
 132test_expect_success 'setup: remove unfunny index entry' '
 133        git update-index --force-remove "$p0"
 134'
 135
 136test_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
 145test_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
 157test_expect_success 'setup: mode change' '
 158        chmod +x "$p1"
 159'
 160
 161test_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
 175test_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
 186test_expect_success 'numstat for rename quotes funny filename' '
 187        cat >expected <<-\EOF &&
 188        0       0       "tabs\t,\" (dq) and spaces"
 189        EOF
 190        git diff-index -M -p $t0 >diff &&
 191        git apply --numstat <diff >current &&
 192        test_cmp expected current
 193'
 194
 195test_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'
 204
 205test_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'
 215
 216test_done