Skip to content

Commit

Permalink
🚧 Support for XDG gitconfig path
Browse files Browse the repository at this point in the history
Fixes: #95

Signed-off-by: Guyzmo <guyzmo+github@m0g.net>
  • Loading branch information
guyzmo committed Feb 2, 2017
1 parent 6e87166 commit 54690e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion git_repo/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def set_gist_ref(self, gist):

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

'''Actions'''

Expand Down
12 changes: 11 additions & 1 deletion git_repo/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ class RepositoryService:

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

@classmethod
def get_config_path(cls):
home_dir = os.environ['HOME']
home_conf = os.path.join(home_dir, '.gitconfig')
xdg_conf = os.path.join(home_dir, '.git', 'config')
if not os.path.exists(xdg_conf):
if os.path.exists(home_conf):
return home_conf
return xdg_conf

@classmethod
def get_config(cls, config):
out = {}
Expand Down Expand Up @@ -95,7 +105,7 @@ def get_service(cls, repository, command):
:return: instance for using the service
'''
if not repository:
config = git_config.GitConfigParser(os.path.join(os.environ['HOME'], '.gitconfig'))
config = git_config.GitConfigParser(self.get_config_path())
else:
config = repository.config_reader()
target = cls.command_map.get(command, command)
Expand Down

0 comments on commit 54690e3

Please sign in to comment.