]> git.ipfire.org Git - thirdparty/git.git/blob - t/t9810-git-p4-rcs.sh
0c2fc3ea1a28268e216a3a93ed12b09f0cf55ef2
[thirdparty/git.git] / t / t9810-git-p4-rcs.sh
1 #!/bin/sh
2
3 test_description='git p4 rcs keywords'
4
5 . ./lib-git-p4.sh
6
7 test_expect_success 'start p4d' '
8 start_p4d
9 '
10
11 #
12 # Make one file with keyword lines at the top, and
13 # enough plain text to be able to test modifications
14 # far away from the keywords.
15 #
16 test_expect_success 'init depot' '
17 (
18 cd "$cli" &&
19 cat <<-\EOF >filek &&
20 $Id$
21 /* $Revision$ */
22 # $Change$
23 line4
24 line5
25 line6
26 line7
27 line8
28 EOF
29 cp filek fileko &&
30 sed -i "s/Revision/Revision: do not scrub me/" fileko
31 cp fileko file_text &&
32 sed -i "s/Id/Id: do not scrub me/" file_text
33 p4 add -t text+k filek &&
34 p4 submit -d "filek" &&
35 p4 add -t text+ko fileko &&
36 p4 submit -d "fileko" &&
37 p4 add -t text file_text &&
38 p4 submit -d "file_text"
39 )
40 '
41
42 #
43 # Generate these in a function to make it easy to use single quote marks.
44 #
45 write_scrub_scripts () {
46 cat >"$TRASH_DIRECTORY/scrub_k.py" <<-\EOF &&
47 import re, sys
48 sys.stdout.write(re.sub(r'(?i)\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$', r'$\1$', sys.stdin.read()))
49 EOF
50 cat >"$TRASH_DIRECTORY/scrub_ko.py" <<-\EOF
51 import re, sys
52 sys.stdout.write(re.sub(r'(?i)\$(Id|Header):[^$]*\$', r'$\1$', sys.stdin.read()))
53 EOF
54 }
55
56 test_expect_success 'scrub scripts' '
57 write_scrub_scripts
58 '
59
60 #
61 # Compare $cli/file to its scrubbed version, should be different.
62 # Compare scrubbed $cli/file to $git/file, should be same.
63 #
64 scrub_k_check () {
65 file="$1" &&
66 scrub="$TRASH_DIRECTORY/$file" &&
67 "$PYTHON_PATH" "$TRASH_DIRECTORY/scrub_k.py" <"$git/$file" >"$scrub" &&
68 ! test_cmp "$cli/$file" "$scrub" &&
69 test_cmp "$git/$file" "$scrub" &&
70 rm "$scrub"
71 }
72 scrub_ko_check () {
73 file="$1" &&
74 scrub="$TRASH_DIRECTORY/$file" &&
75 "$PYTHON_PATH" "$TRASH_DIRECTORY/scrub_ko.py" <"$git/$file" >"$scrub" &&
76 ! test_cmp "$cli/$file" "$scrub" &&
77 test_cmp "$git/$file" "$scrub" &&
78 rm "$scrub"
79 }
80
81 #
82 # Modify far away from keywords. If no RCS lines show up
83 # in the diff, there is no conflict.
84 #
85 test_expect_success 'edit far away from RCS lines' '
86 test_when_finished cleanup_git &&
87 git p4 clone --dest="$git" //depot &&
88 (
89 cd "$git" &&
90 git config git-p4.skipSubmitEdit true &&
91 sed -i "s/^line7/line7 edit/" filek &&
92 git commit -m "filek line7 edit" filek &&
93 git p4 submit &&
94 scrub_k_check filek
95 )
96 '
97
98 #
99 # Modify near the keywords. This will require RCS scrubbing.
100 #
101 test_expect_success 'edit near RCS lines' '
102 test_when_finished cleanup_git &&
103 git p4 clone --dest="$git" //depot &&
104 (
105 cd "$git" &&
106 git config git-p4.skipSubmitEdit true &&
107 git config git-p4.attemptRCSCleanup true &&
108 sed -i "s/^line4/line4 edit/" filek &&
109 git commit -m "filek line4 edit" filek &&
110 git p4 submit &&
111 scrub_k_check filek
112 )
113 '
114
115 #
116 # Modify the keywords themselves. This also will require RCS scrubbing.
117 #
118 test_expect_success 'edit keyword lines' '
119 test_when_finished cleanup_git &&
120 git p4 clone --dest="$git" //depot &&
121 (
122 cd "$git" &&
123 git config git-p4.skipSubmitEdit true &&
124 git config git-p4.attemptRCSCleanup true &&
125 sed -i "/Revision/d" filek &&
126 git commit -m "filek remove Revision line" filek &&
127 git p4 submit &&
128 scrub_k_check filek
129 )
130 '
131
132 #
133 # Scrubbing text+ko files should not alter all keywords, just Id, Header.
134 #
135 test_expect_success 'scrub ko files differently' '
136 test_when_finished cleanup_git &&
137 git p4 clone --dest="$git" //depot &&
138 (
139 cd "$git" &&
140 git config git-p4.skipSubmitEdit true &&
141 git config git-p4.attemptRCSCleanup true &&
142 sed -i "s/^line4/line4 edit/" fileko &&
143 git commit -m "fileko line4 edit" fileko &&
144 git p4 submit &&
145 scrub_ko_check fileko &&
146 ! scrub_k_check fileko
147 )
148 '
149
150 # hack; git p4 submit should do it on its own
151 test_expect_success 'cleanup after failure' '
152 (
153 cd "$cli" &&
154 p4 revert ...
155 )
156 '
157
158 # perl $File:: bug check
159 test_expect_success 'ktext expansion should not expand multi-line $File::' '
160 (
161 cd "$cli" &&
162 cat >lv.pm <<-\EOF
163 my $wanted = sub { my $f = $File::Find::name;
164 if ( -f && $f =~ /foo/ ) {
165 EOF
166 p4 add -t ktext lv.pm &&
167 p4 submit -d "lv.pm"
168 ) &&
169 test_when_finished cleanup_git &&
170 git p4 clone --dest="$git" //depot &&
171 (
172 cd "$git" &&
173 test_cmp "$cli/lv.pm" lv.pm
174 )
175 '
176
177 #
178 # Do not scrub anything but +k or +ko files. Sneak a change into
179 # the cli file so that submit will get a conflict. Make sure that
180 # scrubbing doesn't make a mess of things.
181 #
182 # This might happen only if the git repo is behind the p4 repo at
183 # submit time, and there is a conflict.
184 #
185 test_expect_success 'do not scrub plain text' '
186 test_when_finished cleanup_git &&
187 git p4 clone --dest="$git" //depot &&
188 (
189 cd "$git" &&
190 git config git-p4.skipSubmitEdit true &&
191 git config git-p4.attemptRCSCleanup true &&
192 sed -i "s/^line4/line4 edit/" file_text &&
193 git commit -m "file_text line4 edit" file_text &&
194 (
195 cd "$cli" &&
196 p4 open file_text &&
197 sed -i "s/^line5/line5 p4 edit/" file_text &&
198 p4 submit -d "file5 p4 edit"
199 ) &&
200 echo s | test_expect_code 1 git p4 submit &&
201 (
202 # make sure the file is not left open
203 cd "$cli" &&
204 ! p4 fstat -T action file_text
205 )
206 )
207 '
208
209 # hack; git p4 submit should do it on its own
210 test_expect_success 'cleanup after failure 2' '
211 (
212 cd "$cli" &&
213 p4 revert ...
214 )
215 '
216
217 create_kw_file () {
218 cat <<\EOF >"$1"
219 /* A file
220 Id: $Id$
221 Revision: $Revision$
222 File: $File$
223 */
224 int main(int argc, const char **argv) {
225 return 0;
226 }
227 EOF
228 }
229
230 test_expect_success 'add kwfile' '
231 (
232 cd "$cli" &&
233 echo file1 >file1 &&
234 p4 add file1 &&
235 p4 submit -d "file 1" &&
236 create_kw_file kwfile1.c &&
237 p4 add kwfile1.c &&
238 p4 submit -d "Add rcw kw file" kwfile1.c
239 )
240 '
241
242 p4_append_to_file () {
243 f="$1" &&
244 p4 edit -t ktext "$f" &&
245 echo "/* $(date) */" >>"$f" &&
246 p4 submit -d "appending a line in p4"
247 }
248
249 # Create some files with RCS keywords. If they get modified
250 # elsewhere then the version number gets bumped which then
251 # results in a merge conflict if we touch the RCS kw lines,
252 # even though the change itself would otherwise apply cleanly.
253 test_expect_success 'cope with rcs keyword expansion damage' '
254 test_when_finished cleanup_git &&
255 git p4 clone --dest="$git" //depot &&
256 (
257 cd "$git" &&
258 git config git-p4.skipSubmitEdit true &&
259 git config git-p4.attemptRCSCleanup true &&
260 (cd "$cli" && p4_append_to_file kwfile1.c) &&
261 old_lines=$(wc -l <kwfile1.c) &&
262 "$PERL_PATH" -n -i -e "print unless m/Revision:/" kwfile1.c &&
263 new_lines=$(wc -l <kwfile1.c) &&
264 test $new_lines = $(($old_lines - 1)) &&
265
266 git add kwfile1.c &&
267 git commit -m "Zap an RCS kw line" &&
268 git p4 submit &&
269 git p4 rebase &&
270 git diff p4/master &&
271 git p4 commit &&
272 echo "try modifying in both" &&
273 cd "$cli" &&
274 p4 edit kwfile1.c &&
275 echo "line from p4" >>kwfile1.c &&
276 p4 submit -d "add a line in p4" kwfile1.c &&
277 cd "$git" &&
278 echo "line from git at the top" | cat - kwfile1.c >kwfile1.c.new &&
279 mv kwfile1.c.new kwfile1.c &&
280 git commit -m "Add line in git at the top" kwfile1.c &&
281 git p4 rebase &&
282 git p4 submit
283 )
284 '
285
286 test_expect_success 'cope with rcs keyword file deletion' '
287 test_when_finished cleanup_git &&
288 (
289 cd "$cli" &&
290 echo "\$Revision\$" >kwdelfile.c &&
291 p4 add -t ktext kwdelfile.c &&
292 p4 submit -d "Add file to be deleted" &&
293 cat kwdelfile.c &&
294 grep 1 kwdelfile.c
295 ) &&
296 git p4 clone --dest="$git" //depot &&
297 (
298 cd "$git" &&
299 grep Revision kwdelfile.c &&
300 git rm -f kwdelfile.c &&
301 git commit -m "Delete a file containing RCS keywords" &&
302 git config git-p4.skipSubmitEdit true &&
303 git config git-p4.attemptRCSCleanup true &&
304 git p4 submit
305 ) &&
306 (
307 cd "$cli" &&
308 p4 sync &&
309 ! test -f kwdelfile.c
310 )
311 '
312
313 # If you add keywords in git of the form $Header$ then everything should
314 # work fine without any special handling.
315 test_expect_success 'Add keywords in git which match the default p4 values' '
316 test_when_finished cleanup_git &&
317 git p4 clone --dest="$git" //depot &&
318 (
319 cd "$git" &&
320 echo "NewKW: \$Revision\$" >>kwfile1.c &&
321 git add kwfile1.c &&
322 git commit -m "Adding RCS keywords in git" &&
323 git config git-p4.skipSubmitEdit true &&
324 git config git-p4.attemptRCSCleanup true &&
325 git p4 submit
326 ) &&
327 (
328 cd "$cli" &&
329 p4 sync &&
330 test -f kwfile1.c &&
331 grep "NewKW.*Revision.*[0-9]" kwfile1.c
332
333 )
334 '
335
336 # If you add keywords in git of the form $Header:#1$ then things will fail
337 # unless git-p4 takes steps to scrub the *git* commit.
338 #
339 test_expect_failure 'Add keywords in git which do not match the default p4 values' '
340 test_when_finished cleanup_git &&
341 git p4 clone --dest="$git" //depot &&
342 (
343 cd "$git" &&
344 echo "NewKW2: \$Revision:1\$" >>kwfile1.c &&
345 git add kwfile1.c &&
346 git commit -m "Adding RCS keywords in git" &&
347 git config git-p4.skipSubmitEdit true &&
348 git config git-p4.attemptRCSCleanup true &&
349 git p4 submit
350 ) &&
351 (
352 cd "$cli" &&
353 p4 sync &&
354 grep "NewKW2.*Revision.*[0-9]" kwfile1.c
355
356 )
357 '
358
359 test_expect_success 'kill p4d' '
360 kill_p4d
361 '
362
363 test_done