diff --git a/git_repo/repo.py b/git_repo/repo.py index 11d5702..ca9eadb 100644 --- a/git_repo/repo.py +++ b/git_repo/repo.py @@ -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''' diff --git a/git_repo/services/service.py b/git_repo/services/service.py index c89bbd6..6987271 100644 --- a/git_repo/services/service.py +++ b/git_repo/services/service.py @@ -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 = {} @@ -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)