Skip to content

Commit 30c75ae

Browse files
committed
🚒Fix path to gitconfigg
1 parent f6353ce commit 30c75ae

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

git_repo/services/service.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,32 @@ class RepositoryService:
6969
@staticmethod
7070
def get_config_path():
7171
home_dir = os.environ['HOME']
72-
home_conf = os.path.join(home_dir, '.gitconfig')
73-
xdg_conf = os.path.join(home_dir, '.git', 'config')
74-
if not os.path.exists(xdg_conf):
75-
if os.path.exists(home_conf):
76-
return home_conf
77-
return xdg_conf
72+
try:
73+
from xdg.BaseDirectory import xdg_config_home
74+
except ImportError:
75+
xdg_config_home = os.path.join(home_dir, ".config")
76+
for config in [
77+
os.path.join(home_dir, '.gitconfig'),
78+
os.path.join(xdg_config_home, 'git'),
79+
]:
80+
if os.path.exists(config):
81+
return config
82+
raise ResourceNotFoundError('User\'s Git configuration file not found!')
7883

7984
@staticmethod
80-
def guess_repo_slug(repository, service, resolve_targets=None):
85+
def convert_url_into_slug(url):
86+
if url.endswith('.git'):
87+
url = url[:-4]
88+
# strip http://, https:// and ssh://
89+
if '://' in url:
90+
*_, user, name = url.split('/')
91+
return '/'.join([user, name])
92+
# scp-style URL
93+
elif '@' in url and ':' in url:
94+
return url.split(':')[-1]
95+
96+
@classmethod
97+
def guess_repo_slug(cls, repository, service, resolve_targets=None):
8198
if resolve_targets:
8299
targets = [target.format(service=service.name) for target in resolve_targets]
83100
else:

0 commit comments

Comments
 (0)