Skip to content

Commit

Permalink
Fix problem with changing filetype to +l when dealing with commit server
Browse files Browse the repository at this point in the history
  • Loading branch information
rcowham committed Jun 19, 2024
1 parent ae56fb9 commit a480427
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
11 changes: 10 additions & 1 deletion P4Transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,16 @@ def fixFileTypes(self, fileRevs, openedFiles):
if localFile and len(localFile) > 0 and localFile in revDict:
chRev = revDict[localFile]
if chRev.type != ofile['type']:
self.p4cmd('reopen', '-t', chRev.type, ofile['depotFile'])
# Can't just do a reopen to +l if working with a commit/edge environment
if '+' in chRev.type and 'l' in chRev.type.split('+')[1]:
result = self.p4cmd('reopen', '-t', chRev.type, ofile['depotFile'])
if "can't change +l type with reopen; use revert -k and then edit -t to change type." in str(result):
self.logger.warning(f"Issue identified with file {ofile['depotFile']} suggesting to use 'revert -k' and type change.")
self.p4cmd('revert', '-k', ofile['depotFile'])
self.p4cmd('add', '-t', chRev.type, ofile['depotFile'])
self.p4cmd('edit', '-t', chRev.type, ofile['depotFile'])
else:
self.p4cmd('reopen', '-t', chRev.type, ofile['depotFile'])

def replicateChange(self, fileRevs, specialMoveRevs, srcFileLogs, change, sourcePort):
"""This is the heart of it all. Replicate all changes according to their description"""
Expand Down
61 changes: 61 additions & 0 deletions test/TestP4Transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,67 @@ def testFileTypes(self):
lines = content.split("\n")
self.assertEqual(lines[0], '$Id: //depot/import/inside_file2#1 $')

def testFileTypesPlusL(self):
"File types are transferred appropriately even when exclusive locked"
self.setupTransfer()

inside = localDirectory(self.source.client_root, "inside")
inside_file1 = os.path.join(inside, "inside_file1")
create_file(inside_file1, "Test content")
self.source.p4cmd('add', '-tbinary', inside_file1)
self.source.p4cmd('submit', '-d', "inside_file1 added")

self.run_P4Transfer()
self.assertCounters(1, 1)

filelog = self.target.p4.run_filelog('//depot/import/inside_file1')
self.assertEqual(filelog[0].revisions[0].type, 'binary')

self.source.p4cmd('edit', '-t+l', inside_file1)
append_to_file(inside_file1, "More content")
self.source.p4cmd('submit', '-d', "Type changed")

self.run_P4Transfer()
self.assertCounters(2, 2)

filelog = self.target.p4.run_filelog('//depot/import/inside_file1')
self.assertTrue(filelog[0].revisions[0].type in ['binary+l'])

def testFileTypesPlusLCommit(self):
"File types are transferred appropriately even when exclusive locked on a commit-server"
self.setupTransfer()

# Change target to a commit server
self.target.p4cmd('serverid', 'mycommit')
svr = self.target.p4.fetch_server('mycommit')
svr['Services'] = 'commit-server'
self.target.p4.save_server(svr)

inside = localDirectory(self.source.client_root, "inside")
inside_file1 = os.path.join(inside, "inside_file1")
inside_file2 = os.path.join(inside, "inside_file2")
create_file(inside_file1, "Test content")
self.source.p4cmd('add', '-ttext', inside_file1)
self.source.p4cmd('submit', '-d', "inside_file1 added")

self.run_P4Transfer()
self.assertCounters(1, 1)

filelog = self.target.p4.run_filelog('//depot/import/inside_file1')
self.assertEqual(filelog[0].revisions[0].type, 'text')

self.source.p4cmd('edit', inside_file1)
self.source.p4cmd('move', inside_file1, inside_file2)
self.source.p4cmd('reopen', '-tbinary+l', inside_file2)
# append_to_file(inside_file1, "More content")
self.source.p4cmd('submit', '-d', "Type changed")

self.run_P4Transfer()
self.assertCounters(2, 2)

filelog = self.target.p4.run_filelog('//depot/import/inside_file2')
self.assertEqual(filelog[0].revisions[0].type, 'binary+l')

def testFileTypeIntegrations(self):
"File types are integrated appropriately"
self.setupTransfer()
Expand Down

0 comments on commit a480427

Please sign in to comment.