Skip to content

Commit 0e68b1e

Browse files
committed
🚧 Support for XDG gitconfig path
Fixes: #95 Signed-off-by: Guyzmo <[email protected]>
1 parent 43999e6 commit 0e68b1e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

git_repo/repo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def set_gist_ref(self, gist):
276276

277277
@store_parameter('--config')
278278
def store_gitconfig(self, val):
279-
self.config = val or os.path.join(os.environ['HOME'], '.gitconfig')
279+
self.config = val or RepositoryService.get_config_path()
280280

281281
'''Actions'''
282282

git_repo/services/service.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ class RepositoryService:
6161

6262
config_options = ['type', 'token', 'alias', 'fqdn']
6363

64+
@classmethod
65+
def get_config_path(cls):
66+
home_dir = os.environ['HOME']
67+
home_conf = os.path.join(home_dir, '.gitconfig')
68+
xdg_conf = os.path.join(home_dir, '.git', 'config')
69+
if not os.path.exists(xdg_conf):
70+
if os.path.exists(home_conf):
71+
return home_conf
72+
return xdg_conf
73+
6474
@classmethod
6575
def get_config(cls, config):
6676
out = {}
@@ -95,7 +105,7 @@ def get_service(cls, repository, command):
95105
:return: instance for using the service
96106
'''
97107
if not repository:
98-
config = git_config.GitConfigParser(os.path.join(os.environ['HOME'], '.gitconfig'))
108+
config = git_config.GitConfigParser(self.get_config_path())
99109
else:
100110
config = repository.config_reader()
101111
target = cls.command_map.get(command, command)

0 commit comments

Comments
 (0)