diff --git a/pegleg/engine/util/git.py b/pegleg/engine/util/git.py index 7dbbf8ed..ef5ad87c 100644 --- a/pegleg/engine/util/git.py +++ b/pegleg/engine/util/git.py @@ -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) diff --git a/tests/unit/engine/util/test_git.py b/tests/unit/engine/util/test_git.py index a4da2f9a..9086b95b 100644 --- a/tests/unit/engine/util/test_git.py +++ b/tests/unit/engine/util/test_git.py @@ -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.')