Skip to content

Commit

Permalink
Reject exclusive locks and empty shelves (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
ca-johnson authored Aug 1, 2019
1 parent 0d97c0f commit 11f2021
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python/perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions python/test_perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import tempfile
import time
import zipfile
import pytest

from perforce import P4Repo

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 11f2021

Please sign in to comment.