Skip to content

Commit

Permalink
Apply sync filter to p4print unshelve (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
ca-johnson authored Apr 22, 2020
1 parent 9fdabaf commit f8dcf33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion python/perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,17 @@ def p4print_unshelve(self, changelist):
# Flag these files as modified
self._write_patched(list(depot_to_local.values()))

# Turn sync spec info a prefix to filter out unwanted files
# e.g. //my-depot/dir/... => //my-depot/dir/
sync_prefix = self.sync_paths.rstrip('.')

cmds = []
for depotfile, localfile in depot_to_local.items():
if os.path.isfile(localfile):
os.chmod(localfile, stat.S_IWRITE)
os.unlink(localfile)
cmds.append(('print', '-o', localfile, '%s@=%s' % (depotfile, changelist)))
if depotfile.startswith(sync_prefix):
cmds.append(('print', '-o', localfile, '%s@=%s' % (depotfile, changelist)))

self.run_parallel_cmds(cmds)

Expand Down
6 changes: 6 additions & 0 deletions python/test_perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ def test_p4print_unshelve(server, tmpdir):
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"

# Shelved changes containing files not selected for sync are skipped
repo = P4Repo(root=tmpdir, sync='//depot/fake-dir/...')
repo.sync()
repo.p4print_unshelve('3') # Modify file.txt
assert not os.path.exists(os.path.join(tmpdir, "file.txt"))

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

0 comments on commit f8dcf33

Please sign in to comment.