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' '
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"
43 # Generate these in a function to make it easy to use single quote marks.
45 write_scrub_scripts
() {
46 cat >"$TRASH_DIRECTORY/scrub_k.py" <<-\EOF &&
48 sys.stdout.write(re.sub(r'(?i)\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$', r'$\1$', sys.stdin.read()))
50 cat >"$TRASH_DIRECTORY/scrub_ko.py" <<-\
EOF
52 sys.stdout.write(re.sub(r'(?i)\$(Id|Header):[^$]*\$', r'$\1$', sys.stdin.read()))
56 test_expect_success 'scrub scripts' '
61 # Compare $cli/file to its scrubbed version, should be different.
62 # Compare scrubbed $cli/file to $git/file, should be same.
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" &&
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" &&
82 # Modify far away from keywords. If no RCS lines show up
83 # in the diff, there is no conflict.
85 test_expect_success 'edit far away from RCS lines' '
86 test_when_finished cleanup_git &&
87 git p4 clone --dest="$git" //depot &&
90 git config git-p4.skipSubmitEdit true &&
91 sed -i "s/^line7/line7 edit/" filek &&
92 git commit -m "filek line7 edit" filek &&
99 # Modify near the keywords. This will require RCS scrubbing.
101 test_expect_success 'edit near RCS lines' '
102 test_when_finished cleanup_git &&
103 git p4 clone --dest="$git" //depot &&
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 &&
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 -i "/Revision/d" filek &&
126 git commit -m "filek remove Revision line" filek &&
133 # Scrubbing text+ko files should not alter all keywords, just Id, Header.
135 test_expect_success 'scrub ko files differently' '
136 test_when_finished cleanup_git &&
137 git p4 clone --dest="$git" //depot &&
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 &&
145 scrub_ko_check fileko &&
146 ! scrub_k_check fileko
150 # hack; git p4 submit should do it on its own
151 test_expect_success 'cleanup after failure' '
159 # Do not scrub anything but +k or +ko files. Sneak a change into
160 # the cli file so that submit will get a conflict. Make sure that
161 # scrubbing doesn't make a mess of things.
163 # Assumes that git-p4 exits leaving the p4 file open, with the
164 # conflict-generating patch unapplied.
166 # This might happen only if the git repo is behind the p4 repo at
167 # submit time, and there is a conflict.
169 test_expect_success 'do not scrub plain text' '
170 test_when_finished cleanup_git &&
171 git p4 clone --dest="$git" //depot &&
174 git config git-p4.skipSubmitEdit true &&
175 git config git-p4.attemptRCSCleanup true &&
176 sed -i "s/^line4/line4 edit/" file_text &&
177 git commit -m "file_text line4 edit" file_text &&
181 sed -i "s/^line5/line5 p4 edit/" file_text &&
182 p4 submit -d "file5 p4 edit"
186 # exepct something like:
187 # file_text - file(s
) not opened on this client
188 # but not copious diff output
190 p4
diff file_text
>wc &&
191 test_line_count
= 1 wc
196 # hack; git p4 submit should do it on its own
197 test_expect_success 'cleanup after failure
2' '
211 int main(int argc, const char **argv) {
217 test_expect_success 'add kwfile
' '
222 p4 submit
-d "file 1" &&
223 create_kw_file kwfile1.c
&&
225 p4 submit
-d "Add rcw kw file" kwfile1.c
229 p4_append_to_file () {
231 p4 edit -t ktext "$f" &&
232 echo "/* $(date) */" >>"$f" &&
233 p4 submit -d "appending a line in p4"
236 # Create some files with RCS keywords. If they get modified
237 # elsewhere then the version number gets bumped which then
238 # results in a merge conflict if we touch the RCS kw lines,
239 # even though the change itself would otherwise apply cleanly.
240 test_expect_success 'cope with rcs keyword expansion damage
' '
241 test_when_finished cleanup_git
&&
242 git p4 clone
--dest="$git" //depot
&&
245 git config git-p4.skipSubmitEdit true
&&
246 git config git-p4.attemptRCSCleanup true
&&
247 (cd "$cli" && p4_append_to_file kwfile1.c
) &&
248 old_lines
=$
(wc -l <kwfile1.c
) &&
249 perl
-n -i -e "print unless m/Revision:/" kwfile1.c
&&
250 new_lines
=$
(wc -l <kwfile1.c
) &&
251 test $new_lines = $
(($old_lines - 1)) &&
254 git commit
-m "Zap an RCS kw line" &&
257 git
diff p
4/master
&&
259 echo "try modifying in both" &&
262 echo "line from p4" >>kwfile1.c
&&
263 p4 submit
-d "add a line in p4" kwfile1.c
&&
265 echo "line from git at the top" |
cat - kwfile1.c
>kwfile1.c.new
&&
266 mv kwfile1.c.new kwfile1.c
&&
267 git commit
-m "Add line in git at the top" kwfile1.c
&&
273 test_expect_success 'cope with rcs keyword
file deletion
' '
274 test_when_finished cleanup_git
&&
277 echo "\$Revision\$" >kwdelfile.c
&&
278 p4 add
-t ktext kwdelfile.c
&&
279 p4 submit
-d "Add file to be deleted" &&
283 git p4 clone
--dest="$git" //depot
&&
286 grep Revision kwdelfile.c
&&
287 git
rm -f kwdelfile.c
&&
288 git commit
-m "Delete a file containing RCS keywords" &&
289 git config git-p4.skipSubmitEdit true
&&
290 git config git-p4.attemptRCSCleanup true
&&
296 ! test -f kwdelfile.c
300 # If you add keywords in git of the form $Header$ then everything should
301 # work fine without any special handling.
302 test_expect_success 'Add keywords
in git
which match the default p4 values
' '
303 test_when_finished cleanup_git
&&
304 git p4 clone
--dest="$git" //depot
&&
307 echo "NewKW: \$Revision\$" >>kwfile1.c
&&
309 git commit
-m "Adding RCS keywords in git" &&
310 git config git-p4.skipSubmitEdit true
&&
311 git config git-p4.attemptRCSCleanup true
&&
318 grep "NewKW.*Revision.*[0-9]" kwfile1.c
323 # If you add keywords in git of the form $Header:#1$ then things will fail
324 # unless git-p4 takes steps to scrub the *git* commit.
326 test_expect_failure 'Add keywords
in git
which do not match the default p4 values
' '
327 test_when_finished cleanup_git
&&
328 git p4 clone
--dest="$git" //depot
&&
331 echo "NewKW2: \$Revision:1\$" >>kwfile1.c
&&
333 git commit
-m "Adding RCS keywords in git" &&
334 git config git-p4.skipSubmitEdit true
&&
335 git config git-p4.attemptRCSCleanup true
&&
341 grep "NewKW2.*Revision.*[0-9]" kwfile1.c
346 # Check that the existing merge conflict handling still works.
347 # Modify kwfile1.c in git, and delete in p4. We should be able
348 # to skip the git commit.
350 test_expect_success 'merge conflict handling still works
' '
351 test_when_finished cleanup_git
&&
354 echo "Hello:\$Id\$" >merge2.c
&&
355 echo "World" >>merge2.c
&&
356 p4 add
-t ktext merge2.c
&&
357 p4 submit
-d "add merge test file"
359 git p4 clone
--dest="$git" //depot
&&
362 sed -e "/Hello/d" merge2.c
>merge2.c.tmp
&&
363 mv merge2.c.tmp merge2.c
&&
365 git commit
-m "Modifying merge2.c"
369 p4 delete merge2.c
&&
370 p4 submit
-d "remove merge test file"
375 git config git-p4.skipSubmitEdit true
&&
376 git config git-p4.attemptRCSCleanup true
&&
377 !(echo "s" | git p4 submit
) &&
384 test_expect_success 'kill p4d
' '