summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflexagoon <25misha52@gmail.com>2025-01-23 16:05:47 +0300
committerlmaor xenix <25misha52@gmail.com>2025-01-23 23:47:06 -0800
commit1711bc23c0ab6ff4a51bf948c703c81073dd3475 (patch)
tree5c9a51399240d38e01268e2a0c0f90cc59603f7d
parentdb111d392407797e170355e1c0ec98e71d4a8278 (diff)
downloadgit-repo-1711bc23c0ab6ff4a51bf948c703c81073dd3475.tar.gz
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 <25misha52@gmail.com> Reviewed-by: Mike Frysinger <vapier@google.com>
-rw-r--r--git_config.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/git_config.py b/git_config.py
index 68016fff..14c4c11a 100644
--- a/git_config.py
+++ b/git_config.py
@@ -90,6 +90,20 @@ class GitConfig:
90 90
91 @staticmethod 91 @staticmethod
92 def _getUserConfig(): 92 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
93 return os.path.expanduser("~/.gitconfig") 107 return os.path.expanduser("~/.gitconfig")
94 108
95 @classmethod 109 @classmethod