]> git.ipfire.org Git - thirdparty/git.git/blob - t/t9101-git-svn-props.sh
clone: allow "--bare" with "-o"
[thirdparty/git.git] / t / t9101-git-svn-props.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Eric Wong
4 #
5
6 test_description='git svn property tests'
7
8 TEST_FAILS_SANITIZE_LEAK=true
9 . ./lib-git-svn.sh
10
11 mkdir import
12
13 a_crlf=
14 a_lf=
15 a_cr=
16 a_ne_crlf=
17 a_ne_lf=
18 a_ne_cr=
19 a_empty=
20 a_empty_lf=
21 a_empty_cr=
22 a_empty_crlf=
23
24 cd import
25 cat >> kw.c <<\EOF
26 /* Somebody prematurely put a keyword into this file */
27 /* $Id$ */
28 EOF
29
30 printf "Hello\r\nWorld\r\n" > crlf
31 a_crlf=$(git hash-object -w crlf)
32 printf "Hello\rWorld\r" > cr
33 a_cr=$(git hash-object -w cr)
34 printf "Hello\nWorld\n" > lf
35 a_lf=$(git hash-object -w lf)
36
37 printf "Hello\r\nWorld" > ne_crlf
38 a_ne_crlf=$(git hash-object -w ne_crlf)
39 printf "Hello\nWorld" > ne_lf
40 a_ne_lf=$(git hash-object -w ne_lf)
41 printf "Hello\rWorld" > ne_cr
42 a_ne_cr=$(git hash-object -w ne_cr)
43
44 touch empty
45 a_empty=$(git hash-object -w empty)
46 printf "\n" > empty_lf
47 a_empty_lf=$(git hash-object -w empty_lf)
48 printf "\r" > empty_cr
49 a_empty_cr=$(git hash-object -w empty_cr)
50 printf "\r\n" > empty_crlf
51 a_empty_crlf=$(git hash-object -w empty_crlf)
52
53 svn_cmd import --no-auto-props -m 'import for git svn' . "$svnrepo" >/dev/null
54 cd ..
55
56 rm -rf import
57 test_expect_success 'checkout working copy from svn' 'svn co "$svnrepo" test_wc'
58 test_expect_success 'setup some commits to svn' '
59 (
60 cd test_wc &&
61 echo Greetings >> kw.c &&
62 poke kw.c &&
63 svn_cmd commit -m "Not yet an Id" &&
64 echo Hello world >> kw.c &&
65 poke kw.c &&
66 svn_cmd commit -m "Modified file, but still not yet an Id" &&
67 svn_cmd propset svn:keywords Id kw.c &&
68 poke kw.c &&
69 svn_cmd commit -m "Propset Id"
70 )
71 '
72
73 test_expect_success 'initialize git svn' 'git svn init "$svnrepo"'
74 test_expect_success 'fetch revisions from svn' 'git svn fetch'
75
76 name='test svn:keywords ignoring'
77 test_expect_success "$name" \
78 'git checkout -b mybranch remotes/git-svn &&
79 echo Hi again >> kw.c &&
80 git commit -a -m "test keywords ignoring" &&
81 git svn set-tree remotes/git-svn..mybranch &&
82 git pull . remotes/git-svn'
83
84 expect='/* $Id$ */'
85 got="$(sed -ne 2p kw.c)"
86 test_expect_success 'raw $Id$ found in kw.c' "test '$expect' = '$got'"
87
88 test_expect_success "propset CR on crlf files" '
89 (
90 cd test_wc &&
91 svn_cmd propset svn:eol-style CR empty &&
92 svn_cmd propset svn:eol-style CR crlf &&
93 svn_cmd propset svn:eol-style CR ne_crlf &&
94 svn_cmd commit -m "propset CR on crlf files"
95 )
96 '
97
98 test_expect_success 'fetch and pull latest from svn and checkout a new wc' \
99 'git svn fetch &&
100 git pull . remotes/git-svn &&
101 svn_cmd co "$svnrepo" new_wc'
102
103 for i in crlf ne_crlf lf ne_lf cr ne_cr empty_cr empty_lf empty empty_crlf
104 do
105 test_expect_success "Comparing $i" "cmp $i new_wc/$i"
106 done
107
108
109 cd test_wc
110 printf '$Id$\rHello\rWorld\r' > cr
111 printf '$Id$\rHello\rWorld' > ne_cr
112 a_cr=$(printf '$Id$\r\nHello\r\nWorld\r\n' | git hash-object --stdin)
113 a_ne_cr=$(printf '$Id$\r\nHello\r\nWorld' | git hash-object --stdin)
114 test_expect_success 'Set CRLF on cr files' \
115 'svn_cmd propset svn:eol-style CRLF cr &&
116 svn_cmd propset svn:eol-style CRLF ne_cr &&
117 svn_cmd propset svn:keywords Id cr &&
118 svn_cmd propset svn:keywords Id ne_cr &&
119 svn_cmd commit -m "propset CRLF on cr files"'
120 cd ..
121 test_expect_success 'fetch and pull latest from svn' \
122 'git svn fetch && git pull . remotes/git-svn'
123
124 b_cr="$(git hash-object cr)"
125 b_ne_cr="$(git hash-object ne_cr)"
126
127 test_expect_success 'CRLF + $Id$' "test '$a_cr' = '$b_cr'"
128 test_expect_success 'CRLF + $Id$ (no newline)' "test '$a_ne_cr' = '$b_ne_cr'"
129
130 cat > show-ignore.expect <<\EOF
131
132 # /
133 /no-such-file*
134
135 # /deeply/
136 /deeply/no-such-file*
137
138 # /deeply/nested/
139 /deeply/nested/no-such-file*
140
141 # /deeply/nested/directory/
142 /deeply/nested/directory/no-such-file*
143 EOF
144
145 test_expect_success 'test show-ignore' "
146 (
147 cd test_wc &&
148 mkdir -p deeply/nested/directory &&
149 touch deeply/nested/directory/.keep &&
150 svn_cmd add deeply &&
151 svn_cmd up &&
152 svn_cmd propset -R svn:ignore '
153 no-such-file*
154 ' . &&
155 svn_cmd commit -m 'propset svn:ignore'
156 ) &&
157 git svn show-ignore > show-ignore.got &&
158 cmp show-ignore.expect show-ignore.got
159 "
160
161 cat >create-ignore.expect <<\EOF
162 /no-such-file*
163 EOF
164
165 expectoid=$(git hash-object create-ignore.expect)
166
167 cat >create-ignore-index.expect <<EOF
168 100644 $expectoid 0 .gitignore
169 100644 $expectoid 0 deeply/.gitignore
170 100644 $expectoid 0 deeply/nested/.gitignore
171 100644 $expectoid 0 deeply/nested/directory/.gitignore
172 EOF
173
174 test_expect_success 'test create-ignore' "
175 git svn fetch && git pull . remotes/git-svn &&
176 git svn create-ignore &&
177 cmp ./.gitignore create-ignore.expect &&
178 cmp ./deeply/.gitignore create-ignore.expect &&
179 cmp ./deeply/nested/.gitignore create-ignore.expect &&
180 cmp ./deeply/nested/directory/.gitignore create-ignore.expect &&
181 git ls-files -s >ls_files_result &&
182 grep gitignore ls_files_result | cmp - create-ignore-index.expect
183 "
184
185 cat >prop.expect <<\EOF
186
187 no-such-file*
188
189 EOF
190 cat >prop2.expect <<\EOF
191 8
192 EOF
193
194 # This test can be improved: since all the svn:ignore contain the same
195 # pattern, it can pass even though the propget did not execute on the
196 # right directory.
197 test_expect_success 'test propget' '
198 test_propget () {
199 git svn propget $1 $2 >actual &&
200 cmp $3 actual
201 } &&
202 test_propget svn:ignore . prop.expect &&
203 cd deeply &&
204 test_propget svn:ignore . ../prop.expect &&
205 test_propget svn:entry:committed-rev nested/directory/.keep \
206 ../prop2.expect &&
207 test_propget svn:ignore .. ../prop.expect &&
208 test_propget svn:ignore nested/ ../prop.expect &&
209 test_propget svn:ignore ./nested ../prop.expect &&
210 test_propget svn:ignore .././deeply/nested ../prop.expect
211 '
212
213 cat >prop.expect <<\EOF
214 Properties on '.':
215 svn:entry:committed-date
216 svn:entry:committed-rev
217 svn:entry:last-author
218 svn:entry:uuid
219 svn:ignore
220 EOF
221 cat >prop2.expect <<\EOF
222 Properties on 'nested/directory/.keep':
223 svn:entry:committed-date
224 svn:entry:committed-rev
225 svn:entry:last-author
226 svn:entry:uuid
227 EOF
228
229 test_expect_success 'test proplist' "
230 git svn proplist . >actual &&
231 cmp prop.expect actual &&
232
233 git svn proplist nested/directory/.keep >actual &&
234 cmp prop2.expect actual
235 "
236
237 test_done