From 11f20216dc100ae5b02acf3085cec9256263005f Mon Sep 17 00:00:00 2001 From: Carl Johnson Date: Wed, 31 Jul 2019 23:24:40 -0700 Subject: [PATCH] Reject exclusive locks and empty shelves (#103) --- python/perforce.py | 16 ++++++++++++++++ python/test_perforce.py | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/python/perforce.py b/python/perforce.py index 10dc14f..454f4c0 100644 --- a/python/perforce.py +++ b/python/perforce.py @@ -149,6 +149,22 @@ def revert(self): def unshelve(self, changelist): """Unshelve a pending change""" self._setup_client() + + changeinfo = self.perforce.run_describe('-S', changelist) + if not changeinfo: + raise Exception('Changelist %s does not contain any shelved files.' % changelist) + changeinfo = changeinfo[0] + + # Reject exclusive lock files for now + modifiers = [filetype.split('+')[1] + for filetype in changeinfo['type'] + if '+' in filetype] + if any('l' in modifier for modifier in modifiers): + raise Exception( + 'You cannot run a presubmit test with exclusive lock files (+l) at this time\n' + 'See https://github.com/ca-johnson/perforce-buildkite-plugin/issues/102 for latest status\n') + + self.perforce.run_unshelve('-s', changelist) def backup(self, changelist): diff --git a/python/test_perforce.py b/python/test_perforce.py index d9e8269..f7315ed 100644 --- a/python/test_perforce.py +++ b/python/test_perforce.py @@ -11,6 +11,7 @@ import tempfile import time import zipfile +import pytest from perforce import P4Repo @@ -169,6 +170,9 @@ def test_unshelve(): with open(os.path.join(client_root, "file.txt")) as content: assert content.read() == "Goodbye World\n", "Unexpected content in workspace file" + with pytest.raises(Exception, match=r'Changelist 4 does not contain any shelved files.'): + repo.unshelve('4') + # Unshelved changes are removed in following syncs repo.sync() with open(os.path.join(client_root, "file.txt")) as content: