From 9f3abfa7775c0c4d8cd3e1f02ea1b001dff306bc Mon Sep 17 00:00:00 2001 From: Carl Johnson Date: Tue, 10 Mar 2020 14:20:32 +0000 Subject: [PATCH] Cleanup files marked for add in unshelved changes (#161) --- python/perforce.py | 2 +- python/test_perforce.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/python/perforce.py b/python/perforce.py index 74f6f50..6af90d9 100644 --- a/python/perforce.py +++ b/python/perforce.py @@ -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) diff --git a/python/test_perforce.py b/python/test_perforce.py index 1b4eb9f..7d92429 100644 --- a/python/test_perforce.py +++ b/python/test_perforce.py @@ -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') @@ -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""" @@ -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')