Merge http://www.kernel.org/pub/scm/gitk/gitk
[git.git] / t / t3300-funny-names.sh
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 # since FAT/NTFS does not allow tabs in filenames, skip this test
13 test "$(uname -o 2>/dev/null)" = Cygwin && exit 0
14
15 . ./test-lib.sh
16
17 p0='no-funny'
18 p1='tabs        and spaces'
19 p2='just space'
20
21 cat >"$p0" <<\EOF
22 1. A quick brown fox jumps over the lazy cat, oops dog.
23 2. A quick brown fox jumps over the lazy cat, oops dog.
24 3. A quick brown fox jumps over the lazy cat, oops dog.
25 EOF
26
27 cat >"$p1" "$p0"
28 echo 'Foo Bar Baz' >"$p2"
29
30 echo 'just space
31 no-funny' >expected
32 test_expect_success 'git-ls-files no-funny' \
33         'git-update-index --add "$p0" "$p2" &&
34         git-ls-files >current &&
35         diff -u expected current'
36
37 t0=`git-write-tree`
38 echo "$t0" >t0
39
40 echo 'just space
41 no-funny
42 "tabs\tand spaces"' >expected
43 test_expect_success 'git-ls-files with-funny' \
44         'git-update-index --add "$p1" &&
45         git-ls-files >current &&
46         diff -u expected current'
47
48 echo 'just space
49 no-funny
50 tabs    and spaces' >expected
51 test_expect_success 'git-ls-files -z with-funny' \
52         'git-ls-files -z | tr \\0 \\012 >current &&
53         diff -u expected current'
54
55 t1=`git-write-tree`
56 echo "$t1" >t1
57
58 echo 'just space
59 no-funny
60 "tabs\tand spaces"' >expected
61 test_expect_success 'git-ls-tree with funny' \
62         'git-ls-tree -r $t1 | sed -e "s/^[^     ]*      //" >current &&
63          diff -u expected current'
64
65 echo 'A "tabs\tand spaces"' >expected
66 test_expect_success 'git-diff-index with-funny' \
67         'git-diff-index --name-status $t0 >current &&
68         diff -u expected current'
69
70 test_expect_success 'git-diff-tree with-funny' \
71         'git-diff-tree --name-status $t0 $t1 >current &&
72         diff -u expected current'
73
74 echo 'A
75 tabs    and spaces' >expected
76 test_expect_success 'git-diff-index -z with-funny' \
77         'git-diff-index -z --name-status $t0 | tr \\0 \\012 >current &&
78         diff -u expected current'
79
80 test_expect_success 'git-diff-tree -z with-funny' \
81         'git-diff-tree -z --name-status $t0 $t1 | tr \\0 \\012 >current &&
82         diff -u expected current'
83
84 echo 'CNUM      no-funny        "tabs\tand spaces"' >expected
85 test_expect_success 'git-diff-tree -C with-funny' \
86         'git-diff-tree -C --find-copies-harder --name-status \
87                 $t0 $t1 | sed -e 's/^C[0-9]*/CNUM/' >current &&
88         diff -u expected current'
89
90 echo 'RNUM      no-funny        "tabs\tand spaces"' >expected
91 test_expect_success 'git-diff-tree delete with-funny' \
92         'git-update-index --force-remove "$p0" &&
93         git-diff-index -M --name-status \
94                 $t0 | sed -e 's/^R[0-9]*/RNUM/' >current &&
95         diff -u expected current'
96
97 echo 'diff --git a/no-funny "b/tabs\tand spaces"
98 similarity index NUM%
99 rename from no-funny
100 rename to "tabs\tand spaces"' >expected
101
102 test_expect_success 'git-diff-tree delete with-funny' \
103         'git-diff-index -M -p $t0 |
104          sed -e "s/index [0-9]*%/index NUM%/" >current &&
105          diff -u expected current'
106
107 chmod +x "$p1"
108 echo 'diff --git a/no-funny "b/tabs\tand spaces"
109 old mode 100644
110 new mode 100755
111 similarity index NUM%
112 rename from no-funny
113 rename to "tabs\tand spaces"' >expected
114
115 test_expect_success 'git-diff-tree delete with-funny' \
116         'git-diff-index -M -p $t0 |
117          sed -e "s/index [0-9]*%/index NUM%/" >current &&
118          diff -u expected current'
119
120 echo >expected ' "tabs\tand spaces"
121  1 files changed, 0 insertions(+), 0 deletions(-)'
122 test_expect_success 'git-diff-tree rename with-funny applied' \
123         'git-diff-index -M -p $t0 |
124          git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current &&
125          diff -u expected current'
126
127 echo >expected ' no-funny
128  "tabs\tand spaces"
129  2 files changed, 3 insertions(+), 3 deletions(-)'
130
131 test_expect_success 'git-diff-tree delete with-funny applied' \
132         'git-diff-index -p $t0 |
133          git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current &&
134          diff -u expected current'
135
136 test_expect_success 'git-apply non-git diff' \
137         'git-diff-index -p $t0 |
138          sed -ne "/^[-+@]/p" |
139          git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current &&
140          diff -u expected current'
141
142 test_done