Skip to content

Commit

Permalink
prefs: honor settings defined in /etc/gitconfig
Browse files Browse the repository at this point in the history
Allow falling back to the values defined in /etc/gitconfig when asking
for "global" non-repo settings.

This fixes the ability to define user.email, user.name, cola.tabwidth,
and similar settings in /etc/gitconfig.

Closes #259

Reported-by: Leho Kraav <leho@kraav.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Jun 4, 2014
1 parent 0c09628 commit 468883d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
22 changes: 21 additions & 1 deletion cola/gitcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ def read_config(self, path):

def _get(self, src, key, default):
self.update()
try:
value = self._get_with_fallback(src, key)
except KeyError:
value = default
return value

def _get_with_fallback(self, src, key):
try:
return src[key]
except KeyError:
Expand All @@ -190,7 +197,9 @@ def _get(self, src, key, default):
try:
return src[key]
except KeyError:
return src.get(key.lower(), default)
pass
# Allow the final KeyError to bubble up
return src[key.lower()]

def get(self, key, default=None):
"""Return the string value for a config key."""
Expand All @@ -202,6 +211,17 @@ def get_user(self, key, default=None):
def get_repo(self, key, default=None):
return self._get(self._repo, key, default)

def get_user_or_system(self, key, default=None):
self.update()
try:
value = self._get_with_fallback(self._user, key)
except KeyError:
try:
value = self._get_with_fallback(self._system, key)
except KeyError:
value = default
return value

def python_to_git(self, value):
if type(value) is bool:
if value:
Expand Down
2 changes: 1 addition & 1 deletion cola/widgets/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def runner():

def update_from_config(self):
if self.source == 'user':
getter = self.config.get_user
getter = self.config.get_user_or_system
else:
getter = self.config.get

Expand Down
5 changes: 5 additions & 0 deletions share/doc/git-cola/relnotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Fixes
* We now use bold fonts instead of SmallCaps to avoid
artifacts on several configurations.

* We now pickup `user.email`, `cola.tabwidth`, and similar settings
when defined in /etc/gitconfig.

https://github.com/git-cola/git-cola/pull/259

* Better support for unicode paths when using inotify.

https://bugzilla.redhat.com/show_bug.cgi?id=1104181
Expand Down

0 comments on commit 468883d

Please sign in to comment.