Skip to content

Commit

Permalink
HEAD is resolved within stream where possible (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanvogel authored and ca-johnson committed Dec 9, 2019
1 parent 2953491 commit 6585c0d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Binary file modified python/fixture/server.zip
Binary file not shown.
7 changes: 6 additions & 1 deletion python/perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def info(self):

def head(self):
"""Get current head revision"""
if self.stream is not None:
stream_head = self.perforce.run_changes([
'-m', '1', '-s', 'submitted', '%s/...' % self.stream])
if stream_head:
return stream_head[0]['change']
return self.perforce.run_counter("maxCommitChange")[0]['value']

def description(self, changelist):
Expand Down Expand Up @@ -253,4 +258,4 @@ def sizeof_fmt(num, suffix='B'):
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Pi', suffix)
return "%.1f%s%s" % (num, 'Pi', suffix)
13 changes: 12 additions & 1 deletion python/test_perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def test_fixture(capsys):
# Returns [metadata, contents]
content = repo.perforce.run_print("//depot/file.txt")[1]
assert content == "Hello World\n"
assert repo.head() == "2", "Unexpected head revision"

shelved_change = repo.perforce.run_describe('-sS', '3')
assert len(shelved_change) > 0, "Shelved changelist was missing"
Expand All @@ -102,6 +101,18 @@ def test_fixture(capsys):
# Make changes to the p4 server then check in the new server.zip
# store_server(repo, 'new_server.zip')

def test_head():
"""Test resolve of HEAD changelist"""
setup_server(from_zip='server.zip')
repo = P4Repo(stream='//stream-depot/main')
assert repo.head() == "2", "Unexpected HEAD revision for stream"

repo = P4Repo()
assert repo.head() == "6", "Unexpected global HEAD revision"

repo = P4Repo(stream='//stream-depot/idontexist')
assert repo.head() == "6", "Non-existent stream should fallback to global HEAD revision"

def test_checkout():
"""Test normal flow of checking out files"""
with setup_server_and_client() as client_root:
Expand Down

0 comments on commit 6585c0d

Please sign in to comment.