3 test_description='git p4 rcs keywords'
7 test_expect_success 'start p4d' '
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.
16 test_expect_success 'init depot' '
29 sed "s/Revision/Revision: do not scrub me/" <filek >fileko &&
30 sed "s/Id/Id: do not scrub me/" <fileko >file_text &&
31 p4 add -t text+k filek &&
32 p4 submit -d "filek" &&
33 p4 add -t text+ko fileko &&
34 p4 submit -d "fileko" &&
35 p4 add -t text file_text &&
36 p4 submit -d "file_text"
41 # Generate these in a function to make it easy to use single quote marks.
43 write_scrub_scripts () {
44 cat >"$TRASH_DIRECTORY/scrub_k.py" <<-\EOF &&
46 sys.stdout.write(re.sub(r'(?i)\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$', r'$\1$', sys.stdin.read()))
48 cat >"$TRASH_DIRECTORY/scrub_ko.py" <<-\EOF
50 sys.stdout.write(re.sub(r'(?i)\$(Id|Header):[^$]*\$', r'$\1$', sys.stdin.read()))
54 test_expect_success 'scrub scripts' '
59 # Compare $cli/file to its scrubbed version, should be different.
60 # Compare scrubbed $cli/file to $git/file, should be same.
64 scrub="$TRASH_DIRECTORY/$file" &&
65 "$PYTHON_PATH" "$TRASH_DIRECTORY/scrub_k.py" <"$git/$file" >"$scrub" &&
66 ! test_cmp "$cli/$file" "$scrub" &&
67 test_cmp "$git/$file" "$scrub" &&
72 scrub="$TRASH_DIRECTORY/$file" &&
73 "$PYTHON_PATH" "$TRASH_DIRECTORY/scrub_ko.py" <"$git/$file" >"$scrub" &&
74 ! test_cmp "$cli/$file" "$scrub" &&
75 test_cmp "$git/$file" "$scrub" &&
80 # Modify far away from keywords. If no RCS lines show up
81 # in the diff, there is no conflict.
83 test_expect_success 'edit far away from RCS lines' '
84 test_when_finished cleanup_git &&
85 git p4 clone --dest="$git" //depot &&
88 git config git-p4.skipSubmitEdit true &&
89 sed "s/^line7/line7 edit/" <filek >filek.tmp &&
90 mv -f filek.tmp filek &&
91 git commit -m "filek line7 edit" filek &&
98 # Modify near the keywords. This will require RCS scrubbing.
100 test_expect_success 'edit near RCS lines' '
101 test_when_finished cleanup_git &&
102 git p4 clone --dest="$git" //depot &&
105 git config git-p4.skipSubmitEdit true &&
106 git config git-p4.attemptRCSCleanup true &&
107 sed "s/^line4/line4 edit/" <filek >filek.tmp &&
108 mv -f filek.tmp filek &&
109 git commit -m "filek line4 edit" filek &&
116 # Modify the keywords themselves. This also will require RCS scrubbing.
118 test_expect_success 'edit keyword lines' '
119 test_when_finished cleanup_git &&
120 git p4 clone --dest="$git" //depot &&
123 git config git-p4.skipSubmitEdit true &&
124 git config git-p4.attemptRCSCleanup true &&
125 sed "/Revision/d" <filek >filek.tmp &&
126 mv -f filek.tmp filek &&
127 git commit -m "filek remove Revision line" filek &&
134 # Scrubbing text+ko files should not alter all keywords, just Id, Header.
136 test_expect_success 'scrub ko files differently' '
137 test_when_finished cleanup_git &&
138 git p4 clone --dest="$git" //depot &&
141 git config git-p4.skipSubmitEdit true &&
142 git config git-p4.attemptRCSCleanup true &&
143 sed "s/^line4/line4 edit/" <fileko >fileko.tmp &&
144 mv -f fileko.tmp fileko &&
145 git commit -m "fileko line4 edit" fileko &&
147 scrub_ko_check fileko &&
148 ! scrub_k_check fileko
152 # hack; git p4 submit should do it on its own
153 test_expect_success 'cleanup after failure' '
160 # perl $File:: bug check
161 test_expect_success 'ktext expansion should not expand multi-line $File::' '
164 cat >lv.pm <<-\EOF &&
165 my $wanted = sub { my $f = $File::Find::name;
166 if ( -f && $f =~ /foo/ ) {
168 p4 add -t ktext lv.pm &&
171 test_when_finished cleanup_git &&
172 git p4 clone --dest="$git" //depot &&
175 test_cmp "$cli/lv.pm" lv.pm
180 # Do not scrub anything but +k or +ko files. Sneak a change into
181 # the cli file so that submit will get a conflict. Make sure that
182 # scrubbing doesn't make a mess of things.
184 # This might happen only if the git repo is behind the p4 repo at
185 # submit time, and there is a conflict.
187 test_expect_success 'do not scrub plain text' '
188 test_when_finished cleanup_git &&
189 git p4 clone --dest="$git" //depot &&
192 git config git-p4.skipSubmitEdit true &&
193 git config git-p4.attemptRCSCleanup true &&
194 sed "s/^line4/line4 edit/" <file_text >file_text.tmp &&
195 mv -f file_text.tmp file_text &&
196 git commit -m "file_text line4 edit" file_text &&
200 sed "s/^line5/line5 p4 edit/" <file_text >file_text.tmp &&
201 mv -f file_text.tmp file_text &&
202 p4 submit -d "file5 p4 edit"
204 echo s | test_expect_code 1 git p4 submit &&
206 # make sure the file is not left open
208 ! p4 fstat -T action file_text
213 # hack; git p4 submit should do it on its own
214 test_expect_success 'cleanup after failure 2' '
228 int main(int argc, const char **argv) {
234 test_expect_success 'add kwfile' '
239 p4 submit -d "file 1" &&
240 create_kw_file kwfile1.c &&
242 p4 submit -d "Add rcw kw file" kwfile1.c
246 p4_append_to_file () {
248 p4 edit -t ktext "$f" &&
249 echo "/* $(date) */" >>"$f" &&
250 p4 submit -d "appending a line in p4"
253 # Create some files with RCS keywords. If they get modified
254 # elsewhere then the version number gets bumped which then
255 # results in a merge conflict if we touch the RCS kw lines,
256 # even though the change itself would otherwise apply cleanly.
257 test_expect_success 'cope with rcs keyword expansion damage' '
258 test_when_finished cleanup_git &&
259 git p4 clone --dest="$git" //depot &&
262 git config git-p4.skipSubmitEdit true &&
263 git config git-p4.attemptRCSCleanup true &&
264 (cd "$cli" && p4_append_to_file kwfile1.c) &&
265 old_lines=$(wc -l <kwfile1.c) &&
266 perl -n -i -e "print unless m/Revision:/" kwfile1.c &&
267 new_lines=$(wc -l <kwfile1.c) &&
268 test $new_lines = $(($old_lines - 1)) &&
271 git commit -m "Zap an RCS kw line" &&
274 git diff p4/master &&
276 echo "try modifying in both" &&
279 echo "line from p4" >>kwfile1.c &&
280 p4 submit -d "add a line in p4" kwfile1.c &&
282 echo "line from git at the top" | cat - kwfile1.c >kwfile1.c.new &&
283 mv kwfile1.c.new kwfile1.c &&
284 git commit -m "Add line in git at the top" kwfile1.c &&
290 test_expect_success 'cope with rcs keyword file deletion' '
291 test_when_finished cleanup_git &&
294 echo "\$Revision\$" >kwdelfile.c &&
295 p4 add -t ktext kwdelfile.c &&
296 p4 submit -d "Add file to be deleted" &&
299 git p4 clone --dest="$git" //depot &&
302 grep Revision kwdelfile.c &&
303 git rm -f kwdelfile.c &&
304 git commit -m "Delete a file containing RCS keywords" &&
305 git config git-p4.skipSubmitEdit true &&
306 git config git-p4.attemptRCSCleanup true &&
312 ! test -f kwdelfile.c
316 # If you add keywords in git of the form $Header$ then everything should
317 # work fine without any special handling.
318 test_expect_success 'Add keywords in git which match the default p4 values' '
319 test_when_finished cleanup_git &&
320 git p4 clone --dest="$git" //depot &&
323 echo "NewKW: \$Revision\$" >>kwfile1.c &&
325 git commit -m "Adding RCS keywords in git" &&
326 git config git-p4.skipSubmitEdit true &&
327 git config git-p4.attemptRCSCleanup true &&
334 grep "NewKW.*Revision.*[0-9]" kwfile1.c
339 # If you add keywords in git of the form $Header:#1$ then things will fail
340 # unless git-p4 takes steps to scrub the *git* commit.
342 test_expect_failure 'Add keywords in git which do not match the default p4 values' '
343 test_when_finished cleanup_git &&
344 git p4 clone --dest="$git" //depot &&
347 echo "NewKW2: \$Revision:1\$" >>kwfile1.c &&
349 git commit -m "Adding RCS keywords in git" &&
350 git config git-p4.skipSubmitEdit true &&
351 git config git-p4.attemptRCSCleanup true &&
357 grep "NewKW2.*Revision.*[0-9]" kwfile1.c