Skip to content

Commit

Permalink
Add function to make a copy of a shelved changelist (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ca-johnson authored Jun 4, 2019
1 parent 7cadf30 commit c09601b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion python/perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,19 @@ def unshelve(self, changelist):
"""Unshelve a pending change"""
self._setup_client()
self.perforce.run_unshelve('-s', changelist)
# Improvement - Write unshelved files to disk to guarantee cleanup (patched.json)

def backup(self, changelist):
"""Make a copy of a shelved change"""
self.revert()
self.unshelve(changelist)
# Make pending CL from default CL
unshelved = self.perforce.fetch_change()
unshelved._description = 'Backup of %s for precommit testing in Buildkite' % changelist
output = self.perforce.save_change(unshelved)
backup_cl = output[0].split()[1] # Change X created with Y open file(s).
self.perforce.run_shelve('-c', backup_cl)
return backup_cl


class SyncProgress(Progress):
"""Log the number of synced files periodically"""
Expand Down
12 changes: 12 additions & 0 deletions python/test_perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,15 @@ def test_unshelve():
repo.sync()
with open(os.path.join(client_root, "file.txt")) as content:
assert content.read() == "Hello World\n", "Unexpected content in workspace file"

def test_backup_shelve():
"""Test making a copy of a shelved changelist"""
with setup_server_and_client() as client_root:
repo = P4Repo(root=client_root)

backup_changelist = repo.backup('3')
assert backup_changelist != '3', "Backup changelist number must be new"
repo.revert()
repo.unshelve(backup_changelist)
with open(os.path.join(client_root, "file.txt")) as content:
assert content.read() == "Goodbye World\n", "Unexpected content in workspace file"

0 comments on commit c09601b

Please sign in to comment.