Skip to content

Commit 1711bc2

Browse files
author
flexagoon
committed
git_config: prefer XDG config location
Currently, repo ignores the XDG path for the git config file, and creates a new one in the user's home directory. This commit changes the behavior to prefer the XDG path if it exists, which matches git behavior and avoids littering the home directory. Bug: 40012443 Change-Id: Icd3ec6db6b0832f47417bbe98ff9461306b51297 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/448385 Tested-by: lmaor xenix <[email protected]> Reviewed-by: Mike Frysinger <[email protected]>
1 parent db111d3 commit 1711bc2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

git_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ def ForUser(cls):
9090

9191
@staticmethod
9292
def _getUserConfig():
93+
"""Get the user-specific config file.
94+
95+
Prefers the XDG config location if available, with fallback to
96+
~/.gitconfig
97+
98+
This matches git behavior:
99+
https://git-scm.com/docs/git-config#FILES
100+
"""
101+
xdg_config_home = os.getenv(
102+
"XDG_CONFIG_HOME", os.path.expanduser("~/.config")
103+
)
104+
xdg_config_file = os.path.join(xdg_config_home, "git", "config")
105+
if os.path.exists(xdg_config_file):
106+
return xdg_config_file
93107
return os.path.expanduser("~/.gitconfig")
94108

95109
@classmethod

0 commit comments

Comments
 (0)