mirror of
https://github.com/git-for-windows/git.git
synced 2026-02-04 03:33:01 -06:00
Fallback to AppData if XDG_CONFIG_HOME is unset
In order to be a better Windows citizenship, Git should save its configuration files on AppData folder. This can enables git configuration files be replicated between machines using the same Microsoft account logon which would reduce the friction of setting up Git on new systems. Therefore, if %APPDATA%\Git\config exists, we use it; otherwise $HOME/.config/git/config is used. Signed-off-by: Ariel Lourenco <ariellourenco@users.noreply.github.com>
This commit is contained in:
parent
12986fe490
commit
0105049958
23
path.c
23
path.c
@ -1640,6 +1640,7 @@ int looks_like_command_line_option(const char *str)
|
||||
char *xdg_config_home_for(const char *subdir, const char *filename)
|
||||
{
|
||||
const char *home, *config_home;
|
||||
char *home_config = NULL;
|
||||
|
||||
assert(subdir);
|
||||
assert(filename);
|
||||
@ -1648,10 +1649,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
|
||||
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
|
||||
|
||||
home = getenv("HOME");
|
||||
if (home)
|
||||
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
|
||||
if (home && *home)
|
||||
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
|
||||
|
||||
return NULL;
|
||||
#ifdef WIN32
|
||||
{
|
||||
const char *appdata = getenv("APPDATA");
|
||||
if (appdata && *appdata) {
|
||||
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
|
||||
if (file_exists(appdata_config)) {
|
||||
if (home_config && file_exists(home_config))
|
||||
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
|
||||
free(home_config);
|
||||
return appdata_config;
|
||||
}
|
||||
free(appdata_config);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return home_config;
|
||||
}
|
||||
|
||||
char *xdg_config_home(const char *filename)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user