From 09d70bc9fdeeea40b8a9b45ff81a8a66b5200cc9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 11 2016 18:25:17 +0000 Subject: Rework the get_repo_namespace method in pagure.lib.git --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index d81da8c..5987e64 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -928,17 +928,19 @@ def get_repo_namespace(abspath): ''' Return the name of the git repo based on its path. ''' namespace = None - repo_name = '.'.join( - abspath.rsplit(os.path.sep, 1)[-1].rsplit('.', 1)[:-1]) - if '/forks/' in abspath: - namespace = abspath.split('/forks/', 1)[-1].split('/', 1)[0] - if namespace == repo_name: - namespace = None + short_path = os.path.abspath(abspath).replace( + os.path.abspath(pagure.APP.config['GIT_FOLDER']), + '' + ).strip('/') + + if short_path.startswith('forks/'): + username, projectname = short_path.split('forks/', 1)[1].split('/', 1) else: - namespace = os.path.abspath(abspath.rsplit('/', 1)[0]) - if namespace == os.path.abspath(pagure.APP.config['GIT_FOLDER']): - namespace = None + projectname = short_path + + if '/' in projectname: + namespace = projectname.split('/', 1)[0] return namespace