Skip to content

Commit

Permalink
Cleanup files marked for add in unshelved changes (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
ca-johnson authored Mar 10, 2020
1 parent 19d482e commit 9f3abfa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def sync(self, revision=None):
def revert(self):
"""Revert any pending changes in the workspace"""
self._setup_client()
self.perforce.run_revert('//...')
self.perforce.run_revert('-w', '//...')
patched = self._read_patched()
if patched:
self.perforce.run_clean(patched)
Expand Down
15 changes: 13 additions & 2 deletions python/test_perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,18 @@ def test_unshelve(server, tmpdir):
with open(os.path.join(tmpdir, "file.txt")) as content:
assert content.read() == "Hello World\n", "Unexpected content in workspace file"

repo.unshelve('3')
repo.unshelve('3') # Modify a file
with open(os.path.join(tmpdir, "file.txt")) as content:
assert content.read() == "Goodbye World\n", "Unexpected content in workspace file"
repo.sync()

repo.unshelve('4') # Delete a file
assert not os.path.exists(os.path.join(tmpdir, "file.txt"))
repo.sync()

repo.unshelve('5') # Add a file
assert os.path.exists(os.path.join(tmpdir, "newfile.txt"))
repo.sync()

with pytest.raises(Exception, match=r'Changelist 999 does not contain any shelved files.'):
repo.unshelve('999')
Expand All @@ -245,6 +254,8 @@ def test_unshelve(server, tmpdir):
repo.sync()
with open(os.path.join(tmpdir, "file.txt")) as content:
assert content.read() == "Hello World\n", "Unexpected content in workspace file"
assert not os.path.exists(os.path.join(tmpdir, "newfile.txt")), "File unshelved for add was not deleted"


def test_p4print_unshelve(server, tmpdir):
"""Test unshelving a pending changelist by p4printing content into a file"""
Expand Down Expand Up @@ -272,7 +283,7 @@ def test_p4print_unshelve(server, tmpdir):
repo.sync()
with open(os.path.join(tmpdir, "file.txt")) as content:
assert content.read() == "Hello World\n", "Unexpected content in workspace file"
assert not os.path.exists(os.path.join(tmpdir, "newfile.txt"))
assert not os.path.exists(os.path.join(tmpdir, "newfile.txt")), "File unshelved for add was not deleted"

# Shelved changes containing files not mapped into this workspace do not throw an exception
repo = P4Repo(root=tmpdir, stream='//stream-depot/main')
Expand Down

0 comments on commit 9f3abfa

Please sign in to comment.