3 test_description
='git p4 rcs keywords'
5 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success
'start p4d' '
15 # Make one file with keyword lines at the top, and
16 # enough plain text to be able to test modifications
17 # far away from the keywords.
19 test_expect_success
'init depot' '
32 sed "s/Revision/Revision: do not scrub me/" <filek >fileko &&
33 sed "s/Id/Id: do not scrub me/" <fileko >file_text &&
34 p4 add -t text+k filek &&
35 p4 submit -d "filek" &&
36 p4 add -t text+ko fileko &&
37 p4 submit -d "fileko" &&
38 printf "$CP1252" >fileko_cp1252 &&
39 p4 add -t text+ko fileko_cp1252 &&
40 p4 submit -d "fileko_cp1252" &&
41 p4 add -t text file_text &&
42 p4 submit -d "file_text"
47 # Generate these in a function to make it easy to use single quote marks.
49 write_scrub_scripts
() {
50 cat >"$TRASH_DIRECTORY/scrub_k.py" <<-\EOF &&
52 sys.stdout.write(re.sub(r'(?i)\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$', r'$\1$', sys.stdin.read()))
54 cat >"$TRASH_DIRECTORY/scrub_ko.py" <<-\
EOF
56 sys.stdout.write(re.sub(r'(?i)\$(Id|Header):[^$]*\$', r'$\1$', sys.stdin.read()))
60 test_expect_success 'scrub scripts' '
65 # Compare $cli/file to its scrubbed version, should be different.
66 # Compare scrubbed $cli/file to $git/file, should be same.
70 scrub="$TRASH_DIRECTORY/$file" &&
71 "$PYTHON_PATH" "$TRASH_DIRECTORY/scrub_k.py" <"$git/$file" >"$scrub" &&
72 ! test_cmp "$cli/$file" "$scrub" &&
73 test_cmp "$git/$file" "$scrub" &&
78 scrub="$TRASH_DIRECTORY/$file" &&
79 "$PYTHON_PATH" "$TRASH_DIRECTORY/scrub_ko.py" <"$git/$file" >"$scrub" &&
80 ! test_cmp "$cli/$file" "$scrub" &&
81 test_cmp "$git/$file" "$scrub" &&
86 # Modify far away from keywords. If no RCS lines show up
87 # in the diff, there is no conflict.
89 test_expect_success 'edit far away from RCS lines' '
90 test_when_finished cleanup_git &&
91 git p4 clone --dest="$git" //depot &&
94 git config git-p4.skipSubmitEdit true &&
95 sed "s/^line7/line7 edit/" <filek >filek.tmp &&
96 mv -f filek.tmp filek &&
97 git commit -m "filek line7 edit" filek &&
104 # Modify near the keywords. This will require RCS scrubbing.
106 test_expect_success 'edit near RCS lines' '
107 test_when_finished cleanup_git &&
108 git p4 clone --dest="$git" //depot &&
111 git config git-p4.skipSubmitEdit true &&
112 git config git-p4.attemptRCSCleanup true &&
113 sed "s/^line4/line4 edit/" <filek >filek.tmp &&
114 mv -f filek.tmp filek &&
115 git commit -m "filek line4 edit" filek &&
122 # Modify the keywords themselves. This also will require RCS scrubbing.
124 test_expect_success 'edit keyword lines' '
125 test_when_finished cleanup_git &&
126 git p4 clone --dest="$git" //depot &&
129 git config git-p4.skipSubmitEdit true &&
130 git config git-p4.attemptRCSCleanup true &&
131 sed "/Revision/d" <filek >filek.tmp &&
132 mv -f filek.tmp filek &&
133 git commit -m "filek remove Revision line" filek &&
140 # Scrubbing text+ko files should not alter all keywords, just Id, Header.
142 test_expect_success 'scrub ko files differently' '
143 test_when_finished cleanup_git &&
144 git p4 clone --dest="$git" //depot &&
147 git config git-p4.skipSubmitEdit true &&
148 git config git-p4.attemptRCSCleanup true &&
149 sed "s/^line4/line4 edit/" <fileko >fileko.tmp &&
150 mv -f fileko.tmp fileko &&
151 git commit -m "fileko line4 edit" fileko &&
153 scrub_ko_check fileko &&
154 ! scrub_k_check fileko
158 # hack; git p4 submit should do it on its own
159 test_expect_success 'cleanup after failure' '
166 # perl $File:: bug check
167 test_expect_success 'ktext expansion should not expand multi-line $File::' '
170 cat >lv.pm <<-\EOF &&
171 my $wanted = sub { my $f = $File::Find::name;
172 if ( -f && $f =~ /foo/ ) {
174 p4 add -t ktext lv.pm &&
177 test_when_finished cleanup_git &&
178 git p4 clone --dest="$git" //depot &&
181 test_cmp "$cli/lv.pm" lv.pm
186 # Do not scrub anything but +k or +ko files. Sneak a change into
187 # the cli file so that submit will get a conflict. Make sure that
188 # scrubbing doesn't make a mess of things.
190 # This might happen only if the git repo is behind the p4 repo at
191 # submit time, and there is a conflict.
193 test_expect_success 'do not scrub plain text' '
194 test_when_finished cleanup_git &&
195 git p4 clone --dest="$git" //depot &&
198 git config git-p4.skipSubmitEdit true &&
199 git config git-p4.attemptRCSCleanup true &&
200 sed "s/^line4/line4 edit/" <file_text >file_text.tmp &&
201 mv -f file_text.tmp file_text &&
202 git commit -m "file_text line4 edit" file_text &&
206 sed "s/^line5/line5 p4 edit/" <file_text >file_text.tmp &&
207 mv -f file_text.tmp file_text &&
208 p4 submit -d "file5 p4 edit"
210 echo s | test_expect_code 1 git p4 submit &&
212 # make sure the file is not left open
214 ! p4 fstat -T action file_text
219 # hack; git p4 submit should do it on its own
220 test_expect_success 'cleanup after failure 2' '
234 int main(int argc, const char **argv) {
240 test_expect_success 'add kwfile' '
245 p4 submit -d "file 1" &&
246 create_kw_file kwfile1.c &&
248 p4 submit -d "Add rcw kw file" kwfile1.c
252 p4_append_to_file () {
254 p4 edit -t ktext "$f" &&
255 echo "/* $(date) */" >>"$f" &&
256 p4 submit -d "appending a line in p4"
259 # Create some files with RCS keywords. If they get modified
260 # elsewhere then the version number gets bumped which then
261 # results in a merge conflict if we touch the RCS kw lines,
262 # even though the change itself would otherwise apply cleanly.
263 test_expect_success 'cope with rcs keyword expansion damage' '
264 test_when_finished cleanup_git &&
265 git p4 clone --dest="$git" //depot &&
268 git config git-p4.skipSubmitEdit true &&
269 git config git-p4.attemptRCSCleanup true &&
270 (cd "$cli" && p4_append_to_file kwfile1.c) &&
271 old_lines=$(wc -l <kwfile1.c) &&
272 perl -n -i -e "print unless m/Revision:/" kwfile1.c &&
273 new_lines=$(wc -l <kwfile1.c) &&
274 test $new_lines = $(($old_lines - 1)) &&
277 git commit
-m "Zap an RCS kw line" &&
280 git
diff p
4/master
&&
282 echo "try modifying in both" &&
285 echo "line from p4" >>kwfile1.c
&&
286 p4 submit
-d "add a line in p4" kwfile1.c
&&
288 echo "line from git at the top" |
cat - kwfile1.c
>kwfile1.c.new
&&
289 mv kwfile1.c.new kwfile1.c
&&
290 git commit
-m "Add line in git at the top" kwfile1.c
&&
296 test_expect_success 'cope with rcs keyword
file deletion
' '
297 test_when_finished cleanup_git
&&
300 echo "\$Revision\$" >kwdelfile.c
&&
301 p4 add
-t ktext kwdelfile.c
&&
302 p4 submit
-d "Add file to be deleted" &&
305 git p4 clone
--dest="$git" //depot
&&
308 grep Revision kwdelfile.c
&&
309 git
rm -f kwdelfile.c
&&
310 git commit
-m "Delete a file containing RCS keywords" &&
311 git config git-p4.skipSubmitEdit true
&&
312 git config git-p4.attemptRCSCleanup true
&&
318 ! test -f kwdelfile.c
322 # If you add keywords in git of the form $Header$ then everything should
323 # work fine without any special handling.
324 test_expect_success 'Add keywords
in git
which match the default p4 values
' '
325 test_when_finished cleanup_git
&&
326 git p4 clone
--dest="$git" //depot
&&
329 echo "NewKW: \$Revision\$" >>kwfile1.c
&&
331 git commit
-m "Adding RCS keywords in git" &&
332 git config git-p4.skipSubmitEdit true
&&
333 git config git-p4.attemptRCSCleanup true
&&
340 grep "NewKW.*Revision.*[0-9]" kwfile1.c
345 # If you add keywords in git of the form $Header:#1$ then things will fail
346 # unless git-p4 takes steps to scrub the *git* commit.
348 test_expect_failure 'Add keywords
in git
which do not match the default p4 values
' '
349 test_when_finished cleanup_git
&&
350 git p4 clone
--dest="$git" //depot
&&
353 echo "NewKW2: \$Revision:1\$" >>kwfile1.c
&&
355 git commit
-m "Adding RCS keywords in git" &&
356 git config git-p4.skipSubmitEdit true
&&
357 git config git-p4.attemptRCSCleanup true
&&
363 grep "NewKW2.*Revision.*[0-9]" kwfile1.c
368 test_expect_success 'check cp1252 smart quote are preserved through RCS keyword processing
' '
369 test_when_finished cleanup_git
&&
370 git p4 clone
--dest="$git" //depot
&&
373 printf "$CP1252" >expect
&&
374 test_cmp_bin expect fileko_cp1252