git: Increase test coverage for missing functions
This patch set increases test coverage for some missing git functions and adds some additional edge case/exception handling logic to those functions. Change-Id: I54348599ea959691254c678bc836025cf8df8722
This commit is contained in:
parent
deddf0df1d
commit
799d302c2a
@ -313,7 +313,9 @@ def is_repository(path, *args, **kwargs):
|
|||||||
:param str path: Directory path to check.
|
:param str path: Directory path to check.
|
||||||
:returns: True if ``path`` is a repo, else False.
|
:returns: True if ``path`` is a repo, else False.
|
||||||
:rtype: boolean
|
:rtype: boolean
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Repo(path, *args, **kwargs).git_dir
|
Repo(path, *args, **kwargs).git_dir
|
||||||
return True
|
return True
|
||||||
@ -333,6 +335,9 @@ def is_equal(first_repo, other_repo):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not is_repository(first_repo) or not is_repository(other_repo):
|
||||||
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Compare whether the first reference from each repository is the
|
# Compare whether the first reference from each repository is the
|
||||||
# same: by doing so we know the repositories are the same.
|
# same: by doing so we know the repositories are the same.
|
||||||
@ -356,6 +361,9 @@ def repo_name(repo_url_or_path):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not is_repository(repo_url_or_path):
|
||||||
|
raise exceptions.GitConfigException(repo_url=repo_url_or_path)
|
||||||
|
|
||||||
repo = Repo(repo_url_or_path, search_parent_directories=True)
|
repo = Repo(repo_url_or_path, search_parent_directories=True)
|
||||||
config_reader = repo.config_reader()
|
config_reader = repo.config_reader()
|
||||||
section = 'remote "origin"'
|
section = 'remote "origin"'
|
||||||
@ -363,7 +371,10 @@ def repo_name(repo_url_or_path):
|
|||||||
|
|
||||||
if config_reader.has_section(section):
|
if config_reader.has_section(section):
|
||||||
repo_url = config_reader.get_value(section, option)
|
repo_url = config_reader.get_value(section, option)
|
||||||
return repo_url.split('/')[-1].split('.git')[0]
|
try:
|
||||||
|
return repo_url.split('/')[-1].split('.git')[0]
|
||||||
|
except Exception:
|
||||||
|
raise exceptions.GitConfigException(repo_url=repo_url_or_path)
|
||||||
|
|
||||||
raise exceptions.GitConfigException(repo_url=repo_url_or_path)
|
raise exceptions.GitConfigException(repo_url=repo_url_or_path)
|
||||||
|
|
||||||
|
@ -536,3 +536,33 @@ def test_is_repository():
|
|||||||
|
|
||||||
def test_is_repository_negative():
|
def test_is_repository_negative():
|
||||||
assert not git.is_repository(tempfile.mkdtemp())
|
assert not git.is_repository(tempfile.mkdtemp())
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
not is_connected(), reason='git clone requires network connectivity.')
|
||||||
|
def test_repo_name():
|
||||||
|
url = "http://github.com/openstack/airship-pegleg"
|
||||||
|
git_dir = git.git_handler(url, ref="master")
|
||||||
|
_validate_git_clone(git_dir)
|
||||||
|
|
||||||
|
name = git.repo_name(git_dir)
|
||||||
|
expected = "airship-pegleg"
|
||||||
|
assert name == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
not is_connected(), reason='git clone requires network connectivity.')
|
||||||
|
def test_is_equal():
|
||||||
|
"""Tests whether 2 repositories are equal => reference same remote repo."""
|
||||||
|
|
||||||
|
url = "http://github.com/openstack/airship-pegleg"
|
||||||
|
git_dir1 = git.git_handler(url, ref="master")
|
||||||
|
_validate_git_clone(git_dir1)
|
||||||
|
|
||||||
|
# Re-clone the same repo using a different ref.
|
||||||
|
url = "http://github.com/openstack/airship-pegleg"
|
||||||
|
git_dir2 = git.git_handler(url, ref="refs/changes/40/604640/4")
|
||||||
|
_validate_git_clone(git_dir2)
|
||||||
|
|
||||||
|
# Check whether both repos are equal.
|
||||||
|
assert git.is_equal(git_dir1, git_dir2)
|
||||||
|
Loading…
Reference in New Issue
Block a user