mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Some clean-ups.
This commit is contained in:
parent
15d058edf0
commit
eebd561f00
|
@ -7,11 +7,10 @@ from pip.vcs.git import Git
|
|||
|
||||
|
||||
def get_head_sha(script, dest):
|
||||
"""
|
||||
Return the HEAD sha.
|
||||
"""
|
||||
"""Return the HEAD sha."""
|
||||
result = script.run('git', 'rev-parse', 'HEAD', cwd=dest)
|
||||
sha = result.stdout.strip()
|
||||
|
||||
return sha
|
||||
|
||||
|
||||
|
@ -20,15 +19,11 @@ def do_commit(script, dest):
|
|||
'git', 'commit', '-q', '--author', 'pip <pypa-dev@googlegroups.com>',
|
||||
'--allow-empty', '-m', 'test commit', cwd=dest
|
||||
)
|
||||
sha = get_head_sha(script, dest)
|
||||
|
||||
return sha
|
||||
return get_head_sha(script, dest)
|
||||
|
||||
|
||||
def add_commits(script, dest, count):
|
||||
"""
|
||||
Return a list of the commit hashes from oldest to newest.
|
||||
"""
|
||||
"""Return a list of the commit hashes from oldest to newest."""
|
||||
shas = []
|
||||
for index in range(count):
|
||||
sha = do_commit(script, dest)
|
||||
|
@ -46,46 +41,52 @@ def test_get_revision_sha(script):
|
|||
with TempDirectory(kind="testing") as temp:
|
||||
repo_dir = temp.path
|
||||
script.run('git', 'init', cwd=repo_dir)
|
||||
shas = add_commits(script, repo_dir, count=6)
|
||||
shas = add_commits(script, repo_dir, count=3)
|
||||
|
||||
local_branch_sha = shas[0]
|
||||
tag_sha = shas[1]
|
||||
origin_branch_sha = shas[2]
|
||||
upstream_branch_sha = shas[3]
|
||||
ref_sha = shas[4]
|
||||
head_sha = shas[5]
|
||||
tag_sha = shas[0]
|
||||
origin_sha = shas[1]
|
||||
head_sha = shas[2]
|
||||
assert head_sha == shas[-1]
|
||||
|
||||
origin_ref = 'refs/remotes/origin/origin-branch'
|
||||
generic_ref = 'refs/generic-ref'
|
||||
|
||||
script.run(
|
||||
'git', 'branch', 'local-branch', local_branch_sha, cwd=repo_dir
|
||||
'git', 'branch', 'local-branch', head_sha, cwd=repo_dir
|
||||
)
|
||||
script.run('git', 'tag', 'v1.0', tag_sha, cwd=repo_dir)
|
||||
script.run(
|
||||
'git', 'update-ref', 'refs/remotes/origin/origin-branch',
|
||||
origin_branch_sha, cwd=repo_dir
|
||||
)
|
||||
script.run('git', 'update-ref', origin_ref, origin_sha, cwd=repo_dir)
|
||||
script.run(
|
||||
'git', 'update-ref', 'refs/remotes/upstream/upstream-branch',
|
||||
upstream_branch_sha, cwd=repo_dir
|
||||
)
|
||||
script.run(
|
||||
'git', 'update-ref', 'refs/generic-ref', ref_sha, cwd=repo_dir
|
||||
head_sha, cwd=repo_dir
|
||||
)
|
||||
script.run('git', 'update-ref', generic_ref, head_sha, cwd=repo_dir)
|
||||
|
||||
# Test two tags pointing to the same sha.
|
||||
script.run('git', 'tag', 'v2.0', tag_sha, cwd=repo_dir)
|
||||
# Test tags sharing the same suffix as another tag, both before and
|
||||
# after alphabetically.
|
||||
# after the suffix alphabetically.
|
||||
script.run('git', 'tag', 'aaa/v1.0', head_sha, cwd=repo_dir)
|
||||
script.run('git', 'tag', 'zzz/v1.0', head_sha, cwd=repo_dir)
|
||||
|
||||
check_rev(repo_dir, 'local-branch', None)
|
||||
check_rev(repo_dir, 'v1.0', tag_sha)
|
||||
check_rev(repo_dir, 'v2.0', tag_sha)
|
||||
check_rev(repo_dir, 'origin-branch', origin_branch_sha)
|
||||
check_rev(repo_dir, 'upstream-branch', None)
|
||||
check_rev(repo_dir, 'generic-ref', None)
|
||||
# Test passing a valid commit hash.
|
||||
check_rev(repo_dir, tag_sha, None)
|
||||
# Test passing a non-existent name.
|
||||
check_rev(repo_dir, 'does-not-exist', None)
|
||||
check_rev(repo_dir, 'origin-branch', origin_sha)
|
||||
|
||||
ignored_names = [
|
||||
# Local branches should be ignored.
|
||||
'local-branch',
|
||||
# Non-origin remote branches should be ignored.
|
||||
'upstream-branch',
|
||||
# Generic refs should be ignored.
|
||||
'generic-ref',
|
||||
# Fully spelled-out refs should be ignored.
|
||||
origin_ref,
|
||||
generic_ref,
|
||||
# Test passing a valid commit hash.
|
||||
tag_sha,
|
||||
# Test passing a non-existent name.
|
||||
'does-not-exist',
|
||||
]
|
||||
for name in ignored_names:
|
||||
check_rev(repo_dir, name, None)
|
||||
|
|
Loading…
Reference in a new issue