Improve Pegleg repository name parsing
If a repository remote ends with `.git` Pegleg is successfully able to return the repository name. The same is not true in Pegleg if the repository name does not end in `.git`. This commit allows Pegleg to support repository names that do and do not end in `.git`. Change-Id: I45fd15790677e003af7be584221903551022b7d7
This commit is contained in:
parent
2ea774a744
commit
6b2712fc7d
|
@ -376,7 +376,14 @@ def repo_name(repo_url_or_path):
|
|||
if config_reader.has_section(section):
|
||||
repo_url = config_reader.get_value(section, option)
|
||||
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:
|
||||
raise exceptions.GitConfigException(repo_url=repo_url_or_path)
|
||||
|
||||
|
|
|
@ -540,7 +540,18 @@ def test_is_repository_negative():
|
|||
|
||||
@pytest.mark.skipif(
|
||||
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"
|
||||
git_dir = git.git_handler(url, ref="master")
|
||||
_validate_git_clone(git_dir)
|
||||
|
@ -549,6 +560,17 @@ def test_repo_name():
|
|||
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_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(
|
||||
not is_connected(), reason='git clone requires network connectivity.')
|
||||
|
|
Loading…
Reference in New Issue