Teach "git diff" to handle filenames starting with '-'
[debian-git.git] / t / t3300-funny-names.sh
blobccd7063e97bda4c0d186404e90ab256eb2ee5853
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 p0='no-funny'
15 p1='tabs and spaces'
16 p2='just space'
18 cat >"$p0" <<\EOF
19 1. A quick brown fox jumps over the lazy cat, oops dog.
20 2. A quick brown fox jumps over the lazy cat, oops dog.
21 3. A quick brown fox jumps over the lazy cat, oops dog.
22 EOF
24 cat >"$p1" "$p0"
25 echo 'Foo Bar Baz' >"$p2"
27 echo 'just space
28 no-funny' >expected
29 test_expect_success 'git-ls-files no-funny' \
30 'git-update-index --add "$p0" "$p2" &&
31 git-ls-files >current &&
32 diff -u expected current'
34 t0=`git-write-tree`
35 echo "$t0" >t0
37 echo 'just space
38 no-funny
39 "tabs\tand spaces"' >expected
40 test_expect_success 'git-ls-files with-funny' \
41 'git-update-index --add "$p1" &&
42 git-ls-files >current &&
43 diff -u expected current'
45 echo 'just space
46 no-funny
47 tabs and spaces' >expected
48 test_expect_success 'git-ls-files -z with-funny' \
49 'git-ls-files -z | tr \\0 \\012 >current &&
50 diff -u expected current'
52 t1=`git-write-tree`
53 echo "$t1" >t1
55 echo 'just space
56 no-funny
57 "tabs\tand spaces"' >expected
58 test_expect_success 'git-ls-tree with funny' \
59 'git-ls-tree -r $t1 | sed -e "s/^[^ ]* //" >current &&
60 diff -u expected current'
62 echo 'A "tabs\tand spaces"' >expected
63 test_expect_success 'git-diff-index with-funny' \
64 'git-diff-index --name-status $t0 >current &&
65 diff -u expected current'
67 test_expect_success 'git-diff-tree with-funny' \
68 'git-diff-tree --name-status $t0 $t1 >current &&
69 diff -u expected current'
71 echo 'A
72 tabs and spaces' >expected
73 test_expect_success 'git-diff-index -z with-funny' \
74 'git-diff-index -z --name-status $t0 | tr \\0 \\012 >current &&
75 diff -u expected current'
77 test_expect_success 'git-diff-tree -z with-funny' \
78 'git-diff-tree -z --name-status $t0 $t1 | tr \\0 \\012 >current &&
79 diff -u expected current'
81 echo 'CNUM no-funny "tabs\tand spaces"' >expected
82 test_expect_success 'git-diff-tree -C with-funny' \
83 'git-diff-tree -C --find-copies-harder --name-status \
84 $t0 $t1 | sed -e 's/^C[0-9]*/CNUM/' >current &&
85 diff -u expected current'
87 echo 'RNUM no-funny "tabs\tand spaces"' >expected
88 test_expect_success 'git-diff-tree delete with-funny' \
89 'git-update-index --force-remove "$p0" &&
90 git-diff-index -M --name-status \
91 $t0 | sed -e 's/^R[0-9]*/RNUM/' >current &&
92 diff -u expected current'
94 echo 'diff --git a/no-funny "b/tabs\tand spaces"
95 similarity index NUM%
96 rename from no-funny
97 rename to "tabs\tand spaces"' >expected
99 test_expect_success 'git-diff-tree delete with-funny' \
100 'git-diff-index -M -p $t0 |
101 sed -e "s/index [0-9]*%/index NUM%/" >current &&
102 diff -u expected current'
104 chmod +x "$p1"
105 echo 'diff --git a/no-funny "b/tabs\tand spaces"
106 old mode 100644
107 new mode 100755
108 similarity index NUM%
109 rename from no-funny
110 rename to "tabs\tand spaces"' >expected
112 test_expect_success 'git-diff-tree delete with-funny' \
113 'git-diff-index -M -p $t0 |
114 sed -e "s/index [0-9]*%/index NUM%/" >current &&
115 diff -u expected current'
117 echo >expected ' "tabs\tand spaces"
118 1 files changed, 0 insertions(+), 0 deletions(-)'
119 test_expect_success 'git-diff-tree rename with-funny applied' \
120 'git-diff-index -M -p $t0 |
121 git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current &&
122 diff -u expected current'
124 echo >expected ' no-funny
125 "tabs\tand spaces"
126 2 files changed, 3 insertions(+), 3 deletions(-)'
128 test_expect_success 'git-diff-tree delete with-funny applied' \
129 'git-diff-index -p $t0 |
130 git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current &&
131 diff -u expected current'
133 test_expect_success 'git-apply non-git diff' \
134 'git-diff-index -p $t0 |
135 sed -ne "/^[-+@]/p" |
136 git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current &&
137 diff -u expected current'
139 test_done