git p4: fix writable file after rename or copy

The way rename works is with a "p4 integrate", optionally followed by a "p4 edit" if the change is not a 100% rename. Contents are generated by applying a patch, not doing a file system rename. Copy is similar. In this case, p4 does not fix the permissions back to read-only. Make sure this happens by calling "p4 sync -f". Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Apr 29, 2012 at 20:57 UTC b6ad6dcc3b0629d525abc9fe0882e1b0eb969e17
3 files changed +20 -5
git-p4.py
+12
@@ -1038,6 +1038,7 @@ class P4Submit(Command, P4UserMap):
1038 filesToAdd = set()
1039 filesToDelete = set()
1040 editedFiles = set()
1041 + pureRenameCopy = set()
1042 filesToChangeExecBit = {}
1043
1044 for line in diff:
@@ -1061,10 +1062,13 @@ class P4Submit(Command, P4UserMap):
1062 elif modifier == "C":
1063 src, dest = diff['src'], diff['dst']
1064 p4_integrate(src, dest)
1065 + pureRenameCopy.add(dest)
1066 if diff['src_sha1'] != diff['dst_sha1']:
1067 p4_edit(dest)
1068 + pureRenameCopy.discard(dest)
1069 if isModeExecChanged(diff['src_mode'], diff['dst_mode']):
1070 p4_edit(dest)
1071 + pureRenameCopy.discard(dest)
1072 filesToChangeExecBit[dest] = diff['dst_mode']
1073 os.unlink(dest)
1074 editedFiles.add(dest)
@@ -1073,6 +1077,8 @@ class P4Submit(Command, P4UserMap):
1077 p4_integrate(src, dest)
1078 if diff['src_sha1'] != diff['dst_sha1']:
1079 p4_edit(dest)
1080 + else:
1081 + pureRenameCopy.add(dest)
1082 if isModeExecChanged(diff['src_mode'], diff['dst_mode']):
1083 p4_edit(dest)
1084 filesToChangeExecBit[dest] = diff['dst_mode']
@@ -1226,6 +1232,12 @@ class P4Submit(Command, P4UserMap):
1232 # unmarshalled.
1233 changelist = self.lastP4Changelist()
1234 self.modifyChangelistUser(changelist, p4User)
1235 +
1236 + # The rename/copy happened by applying a patch that created a
1237 + # new file. This leaves it writable, which confuses p4.
1238 + for f in pureRenameCopy:
1239 + p4_sync(f, "-f")
1240 +
1241 else:
1242 # skip this patch
1243 print "Submission cancelled, undoing p4 changes."
t/t9807-git-p4-submit.sh
+4 -2
@@ -158,7 +158,8 @@ test_expect_success 'submit copy' '
158 ) &&
159 (
160 cd "$cli" &&
161 - test_path_is_file file5.ta
161 + test_path_is_file file5.ta &&
162 + test ! -w file5.ta
163 )
164 '
165
@@ -176,7 +177,8 @@ test_expect_success 'submit rename' '
177 (
178 cd "$cli" &&
179 test_path_is_missing file6.t &&
179 - test_path_is_file file6.ta
180 + test_path_is_file file6.ta &&
181 + test ! -w file6.ta
182 )
183 '
184
t/t9809-git-p4-client-view.sh
+4 -3
@@ -349,7 +349,8 @@ test_expect_success 'subdir clone, submit copy' '
349 ) &&
350 (
351 cd "$cli" &&
352 - test_path_is_file dir1/file11a
352 + test_path_is_file dir1/file11a &&
353 + test ! -w dir1/file11a
354 )
355 '
356
@@ -368,14 +369,14 @@ test_expect_success 'subdir clone, submit rename' '
369 (
370 cd "$cli" &&
371 test_path_is_missing dir1/file13 &&
371 - test_path_is_file dir1/file13a
372 + test_path_is_file dir1/file13a &&
373 + test ! -w dir1/file13a
374 )
375 '
376
377 test_expect_success 'reinit depot' '
378 (
379 cd "$cli" &&
378 - p4 sync -f &&
380 rm files &&
381 p4 delete */* &&
382 p4 submit -d "delete all files" &&