3 test_description
='git p4 rcs keywords'
9 test_expect_success
'start p4d' '
14 # Make one file with keyword lines at the top, and
15 # enough plain text to be able to test modifications
16 # far away from the keywords.
18 test_expect_success
'init depot' '
31 sed "s/Revision/Revision: do not scrub me/" <filek >fileko &&
32 sed "s/Id/Id: do not scrub me/" <fileko >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 printf "$CP1252" >fileko_cp1252 &&
38 p4 add -t text+ko fileko_cp1252 &&
39 p4 submit -d "fileko_cp1252" &&
40 p4 add -t text file_text &&
41 p4 submit -d "file_text"
46 # Generate these in a function to make it easy to use single quote marks.
48 write_scrub_scripts
() {
49 cat >"$TRASH_DIRECTORY/scrub_k.py" <<-\EOF &&
51 sys.stdout.write(re.sub(r'(?i)\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$', r'$\1$', sys.stdin.read()))
53 cat >"$TRASH_DIRECTORY/scrub_ko.py" <<-\
EOF
55 sys.stdout.write(re.sub(r'(?i)\$(Id|Header):[^$]*\$', r'$\1$', sys.stdin.read()))
59 test_expect_success 'scrub scripts' '
64 # Compare $cli/file to its scrubbed version, should be different.
65 # Compare scrubbed $cli/file to $git/file, should be same.
69 scrub="$TRASH_DIRECTORY/$file" &&
70 "$PYTHON_PATH" "$TRASH_DIRECTORY/scrub_k.py" <"$git/$file" >"$scrub" &&
71 ! test_cmp "$cli/$file" "$scrub" &&
72 test_cmp "$git/$file" "$scrub" &&
77 scrub="$TRASH_DIRECTORY/$file" &&
78 "$PYTHON_PATH" "$TRASH_DIRECTORY/scrub_ko.py" <"$git/$file" >"$scrub" &&
79 ! test_cmp "$cli/$file" "$scrub" &&
80 test_cmp "$git/$file" "$scrub" &&
85 # Modify far away from keywords. If no RCS lines show up
86 # in the diff, there is no conflict.
88 test_expect_success 'edit far away from RCS lines' '
89 test_when_finished cleanup_git &&
90 git p4 clone --dest="$git" //depot &&
93 git config git-p4.skipSubmitEdit true &&
94 sed "s/^line7/line7 edit/" <filek >filek.tmp &&
95 mv -f filek.tmp filek &&
96 git commit -m "filek line7 edit" filek &&
103 # Modify near the keywords. This will require RCS scrubbing.
105 test_expect_success 'edit near RCS lines' '
106 test_when_finished cleanup_git &&
107 git p4 clone --dest="$git" //depot &&
110 git config git-p4.skipSubmitEdit true &&
111 git config git-p4.attemptRCSCleanup true &&
112 sed "s/^line4/line4 edit/" <filek >filek.tmp &&
113 mv -f filek.tmp filek &&
114 git commit -m "filek line4 edit" filek &&
121 # Modify the keywords themselves. This also will require RCS scrubbing.
123 test_expect_success 'edit keyword lines' '
124 test_when_finished cleanup_git &&
125 git p4 clone --dest="$git" //depot &&
128 git config git-p4.skipSubmitEdit true &&
129 git config git-p4.attemptRCSCleanup true &&
130 sed "/Revision/d" <filek >filek.tmp &&
131 mv -f filek.tmp filek &&
132 git commit -m "filek remove Revision line" filek &&
139 # Scrubbing text+ko files should not alter all keywords, just Id, Header.
141 test_expect_success 'scrub ko files differently' '
142 test_when_finished cleanup_git &&
143 git p4 clone --dest="$git" //depot &&
146 git config git-p4.skipSubmitEdit true &&
147 git config git-p4.attemptRCSCleanup true &&
148 sed "s/^line4/line4 edit/" <fileko >fileko.tmp &&
149 mv -f fileko.tmp fileko &&
150 git commit -m "fileko line4 edit" fileko &&
152 scrub_ko_check fileko &&
153 ! scrub_k_check fileko
157 # hack; git p4 submit should do it on its own
158 test_expect_success 'cleanup after failure' '
165 # perl $File:: bug check
166 test_expect_success 'ktext expansion should not expand multi-line $File::' '
169 cat >lv.pm <<-\EOF &&
170 my $wanted = sub { my $f = $File::Find::name;
171 if ( -f && $f =~ /foo/ ) {
173 p4 add -t ktext lv.pm &&
176 test_when_finished cleanup_git &&
177 git p4 clone --dest="$git" //depot &&
180 test_cmp "$cli/lv.pm" lv.pm
185 # Do not scrub anything but +k or +ko files. Sneak a change into
186 # the cli file so that submit will get a conflict. Make sure that
187 # scrubbing doesn't make a mess of things.
189 # This might happen only if the git repo is behind the p4 repo at
190 # submit time, and there is a conflict.
192 test_expect_success 'do not scrub plain text' '
193 test_when_finished cleanup_git &&
194 git p4 clone --dest="$git" //depot &&
197 git config git-p4.skipSubmitEdit true &&
198 git config git-p4.attemptRCSCleanup true &&
199 sed "s/^line4/line4 edit/" <file_text >file_text.tmp &&
200 mv -f file_text.tmp file_text &&
201 git commit -m "file_text line4 edit" file_text &&
205 sed "s/^line5/line5 p4 edit/" <file_text >file_text.tmp &&
206 mv -f file_text.tmp file_text &&
207 p4 submit -d "file5 p4 edit"
209 echo s | test_expect_code 1 git p4 submit &&
211 # make sure the file is not left open
213 ! p4 fstat -T action file_text
218 # hack; git p4 submit should do it on its own
219 test_expect_success 'cleanup after failure 2' '
233 int main(int argc, const char **argv) {
239 test_expect_success 'add kwfile' '
244 p4 submit -d "file 1" &&
245 create_kw_file kwfile1.c &&
247 p4 submit -d "Add rcw kw file" kwfile1.c
251 p4_append_to_file () {
253 p4 edit -t ktext "$f" &&
254 echo "/* $(date) */" >>"$f" &&
255 p4 submit -d "appending a line in p4"
258 # Create some files with RCS keywords. If they get modified
259 # elsewhere then the version number gets bumped which then
260 # results in a merge conflict if we touch the RCS kw lines,
261 # even though the change itself would otherwise apply cleanly.
262 test_expect_success 'cope with rcs keyword expansion damage' '
263 test_when_finished cleanup_git &&
264 git p4 clone --dest="$git" //depot &&
267 git config git-p4.skipSubmitEdit true &&
268 git config git-p4.attemptRCSCleanup true &&
269 (cd "$cli" && p4_append_to_file kwfile1.c) &&
270 old_lines=$(wc -l <kwfile1.c) &&
271 perl -n -i -e "print unless m/Revision:/" kwfile1.c &&
272 new_lines=$(wc -l <kwfile1.c) &&
273 test $new_lines = $(($old_lines - 1)) &&
276 git commit
-m "Zap an RCS kw line" &&
279 git
diff p
4/master
&&
281 echo "try modifying in both" &&
284 echo "line from p4" >>kwfile1.c
&&
285 p4 submit
-d "add a line in p4" kwfile1.c
&&
287 echo "line from git at the top" |
cat - kwfile1.c
>kwfile1.c.new
&&
288 mv kwfile1.c.new kwfile1.c
&&
289 git commit
-m "Add line in git at the top" kwfile1.c
&&
295 test_expect_success 'cope with rcs keyword
file deletion
' '
296 test_when_finished cleanup_git
&&
299 echo "\$Revision\$" >kwdelfile.c
&&
300 p4 add
-t ktext kwdelfile.c
&&
301 p4 submit
-d "Add file to be deleted" &&
304 git p4 clone
--dest="$git" //depot
&&
307 grep Revision kwdelfile.c
&&
308 git
rm -f kwdelfile.c
&&
309 git commit
-m "Delete a file containing RCS keywords" &&
310 git config git-p4.skipSubmitEdit true
&&
311 git config git-p4.attemptRCSCleanup true
&&
317 ! test -f kwdelfile.c
321 # If you add keywords in git of the form $Header$ then everything should
322 # work fine without any special handling.
323 test_expect_success 'Add keywords
in git
which match the default p4 values
' '
324 test_when_finished cleanup_git
&&
325 git p4 clone
--dest="$git" //depot
&&
328 echo "NewKW: \$Revision\$" >>kwfile1.c
&&
330 git commit
-m "Adding RCS keywords in git" &&
331 git config git-p4.skipSubmitEdit true
&&
332 git config git-p4.attemptRCSCleanup true
&&
339 grep "NewKW.*Revision.*[0-9]" kwfile1.c
344 # If you add keywords in git of the form $Header:#1$ then things will fail
345 # unless git-p4 takes steps to scrub the *git* commit.
347 test_expect_failure 'Add keywords
in git
which do not match the default p4 values
' '
348 test_when_finished cleanup_git
&&
349 git p4 clone
--dest="$git" //depot
&&
352 echo "NewKW2: \$Revision:1\$" >>kwfile1.c
&&
354 git commit
-m "Adding RCS keywords in git" &&
355 git config git-p4.skipSubmitEdit true
&&
356 git config git-p4.attemptRCSCleanup true
&&
362 grep "NewKW2.*Revision.*[0-9]" kwfile1.c
367 test_expect_success 'check cp1252 smart quote are preserved through RCS keyword processing
' '
368 test_when_finished cleanup_git
&&
369 git p4 clone
--dest="$git" //depot
&&
372 printf "$CP1252" >expect
&&
373 test_cmp_bin expect fileko_cp1252