Skip to content

Commit

Permalink
Attempt revert before saving client (#232)
Browse files Browse the repository at this point in the history
* Attempt revert before saving client

Attempting to avoid the following error which presents if a workspace has open files:

P4.P4Exception: [P4#run] Errors during command execution( "p4 client -i" )	
[Error]: "Client 'bk-p4-bk-95e7e0fc01359405a1a535adf3dbbc8135025a92-c5hk-1-midwinter' has files opened; use -f to force switch."

* Avoid infinite recursion

* catch case where no changes or client exist

* Print exceptions as warnings
  • Loading branch information
improbable-mattchurch authored Apr 9, 2021
1 parent ba0b8a8 commit 1ea0083
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ def _setup_client(self):
# unless overidden, overwrite writeable-but-unopened files
# (e.g. interrupted syncs, artefacts that have been checked-in)
client._options = self.client_options + ' clobber'

# revert changes in client before saving to avoid an error if files are still open in client
try:
self.perforce.run_revert('-w', '//...')
except P4Exception as ex:
# client might not exist yet, or not have any changes in either case that's fine
self.perforce.logger.warning("%s" % ex)
pass

self.perforce.save_client(client)

Expand Down

0 comments on commit 1ea0083

Please sign in to comment.