Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit b6ad6dc

Browse files
Pete Wyckoffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0f224e5 commit b6ad6dc

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

git-p4.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,7 @@ def applyCommit(self, id):
10381038
filesToAdd = set()
10391039
filesToDelete = set()
10401040
editedFiles = set()
1041+
pureRenameCopy = set()
10411042
filesToChangeExecBit = {}
10421043

10431044
for line in diff:
@@ -1061,10 +1062,13 @@ def applyCommit(self, id):
10611062
elif modifier == "C":
10621063
src, dest = diff['src'], diff['dst']
10631064
p4_integrate(src, dest)
1065+
pureRenameCopy.add(dest)
10641066
if diff['src_sha1'] != diff['dst_sha1']:
10651067
p4_edit(dest)
1068+
pureRenameCopy.discard(dest)
10661069
if isModeExecChanged(diff['src_mode'], diff['dst_mode']):
10671070
p4_edit(dest)
1071+
pureRenameCopy.discard(dest)
10681072
filesToChangeExecBit[dest] = diff['dst_mode']
10691073
os.unlink(dest)
10701074
editedFiles.add(dest)
@@ -1073,6 +1077,8 @@ def applyCommit(self, id):
10731077
p4_integrate(src, dest)
10741078
if diff['src_sha1'] != diff['dst_sha1']:
10751079
p4_edit(dest)
1080+
else:
1081+
pureRenameCopy.add(dest)
10761082
if isModeExecChanged(diff['src_mode'], diff['dst_mode']):
10771083
p4_edit(dest)
10781084
filesToChangeExecBit[dest] = diff['dst_mode']
@@ -1226,6 +1232,12 @@ def applyCommit(self, id):
12261232
# unmarshalled.
12271233
changelist = self.lastP4Changelist()
12281234
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+
12291241
else:
12301242
# skip this patch
12311243
print "Submission cancelled, undoing p4 changes."

t/t9807-git-p4-submit.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ test_expect_success 'submit copy' '
158158
) &&
159159
(
160160
cd "$cli" &&
161-
test_path_is_file file5.ta
161+
test_path_is_file file5.ta &&
162+
test ! -w file5.ta
162163
)
163164
'
164165

@@ -176,7 +177,8 @@ test_expect_success 'submit rename' '
176177
(
177178
cd "$cli" &&
178179
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
180182
)
181183
'
182184

t/t9809-git-p4-client-view.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ test_expect_success 'subdir clone, submit copy' '
349349
) &&
350350
(
351351
cd "$cli" &&
352-
test_path_is_file dir1/file11a
352+
test_path_is_file dir1/file11a &&
353+
test ! -w dir1/file11a
353354
)
354355
'
355356

@@ -368,14 +369,14 @@ test_expect_success 'subdir clone, submit rename' '
368369
(
369370
cd "$cli" &&
370371
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
372374
)
373375
'
374376

375377
test_expect_success 'reinit depot' '
376378
(
377379
cd "$cli" &&
378-
p4 sync -f &&
379380
rm files &&
380381
p4 delete */* &&
381382
p4 submit -d "delete all files" &&

0 commit comments

Comments
 (0)