Skip to content

Commit 391cd2a

Browse files
ariellourencodscho
authored andcommitted
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 <[email protected]>
1 parent c71be29 commit 391cd2a

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

path.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,7 @@ int looks_like_command_line_option(const char *str)
14841484
char *xdg_config_home_for(const char *subdir, const char *filename)
14851485
{
14861486
const char *home, *config_home;
1487+
char *home_config = NULL;
14871488

14881489
assert(subdir);
14891490
assert(filename);
@@ -1492,10 +1493,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
14921493
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
14931494

14941495
home = getenv("HOME");
1495-
if (home)
1496-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1496+
if (home && *home)
1497+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1498+
1499+
#ifdef WIN32
1500+
{
1501+
const char *appdata = getenv("APPDATA");
1502+
if (appdata && *appdata) {
1503+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1504+
if (file_exists(appdata_config)) {
1505+
if (home_config && file_exists(home_config))
1506+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1507+
free(home_config);
1508+
return appdata_config;
1509+
}
1510+
free(appdata_config);
1511+
}
1512+
}
1513+
#endif
14971514

1498-
return NULL;
1515+
return home_config;
14991516
}
15001517

15011518
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)