Merge "Improve Pegleg repository name parsing"
This commit is contained in:
commit
920068260d
|
@ -376,7 +376,14 @@ 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)
|
||||||
try:
|
try:
|
||||||
return repo_url.split('/')[-1].split('.git')[0]
|
# Support repos that end with or without '.git'
|
||||||
|
if repo_url.endswith('.git'):
|
||||||
|
return repo_url.split('/')[-1].split('.git')[0]
|
||||||
|
else:
|
||||||
|
if repo_url.endswith('/'):
|
||||||
|
return repo_url.split('/')[-2]
|
||||||
|
else:
|
||||||
|
return repo_url.split('/')[-1]
|
||||||
except Exception:
|
except Exception:
|
||||||
raise exceptions.GitConfigException(repo_url=repo_url_or_path)
|
raise exceptions.GitConfigException(repo_url=repo_url_or_path)
|
||||||
|
|
||||||
|
|
|
@ -540,7 +540,18 @@ def test_is_repository_negative():
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
not is_connected(), reason='git clone requires network connectivity.')
|
not is_connected(), reason='git clone requires network connectivity.')
|
||||||
def test_repo_name():
|
def test_repo_name_ending_in_git():
|
||||||
|
url = "http://github.com/openstack/airship-pegleg.git"
|
||||||
|
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_repo_name_not_ending_in_git_and_no_fwd_slash_at_end():
|
||||||
url = "http://github.com/openstack/airship-pegleg"
|
url = "http://github.com/openstack/airship-pegleg"
|
||||||
git_dir = git.git_handler(url, ref="master")
|
git_dir = git.git_handler(url, ref="master")
|
||||||
_validate_git_clone(git_dir)
|
_validate_git_clone(git_dir)
|
||||||
|
@ -549,6 +560,17 @@ def test_repo_name():
|
||||||
expected = "airship-pegleg"
|
expected = "airship-pegleg"
|
||||||
assert name == expected
|
assert name == expected
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
not is_connected(), reason='git clone requires network connectivity.')
|
||||||
|
def test_repo_name_not_ending_in_git_with_fwd_slash_at_end():
|
||||||
|
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(
|
@pytest.mark.skipif(
|
||||||
not is_connected(), reason='git clone requires network connectivity.')
|
not is_connected(), reason='git clone requires network connectivity.')
|
||||||
|
|
Loading…
Reference in New Issue