From 1ea008369bda944880a36a6a8ac02a8a04f5c6be Mon Sep 17 00:00:00 2001 From: Matt Church Date: Fri, 9 Apr 2021 08:09:44 -0600 Subject: [PATCH] Attempt revert before saving client (#232) * 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 --- python/perforce.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python/perforce.py b/python/perforce.py index 45b22f0f..0bf1f2d0 100644 --- a/python/perforce.py +++ b/python/perforce.py @@ -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)