Skip to content

Commit 672e11b

Browse files
ariellourencoGit for Windows Build Agent
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 dca8a1c commit 672e11b

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
@@ -1640,6 +1640,7 @@ int looks_like_command_line_option(const char *str)
16401640
char *xdg_config_home_for(const char *subdir, const char *filename)
16411641
{
16421642
const char *home, *config_home;
1643+
char *home_config = NULL;
16431644

16441645
assert(subdir);
16451646
assert(filename);
@@ -1648,10 +1649,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
16481649
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
16491650

16501651
home = getenv("HOME");
1651-
if (home)
1652-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1652+
if (home && *home)
1653+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1654+
1655+
#ifdef WIN32
1656+
{
1657+
const char *appdata = getenv("APPDATA");
1658+
if (appdata && *appdata) {
1659+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1660+
if (file_exists(appdata_config)) {
1661+
if (home_config && file_exists(home_config))
1662+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1663+
free(home_config);
1664+
return appdata_config;
1665+
}
1666+
free(appdata_config);
1667+
}
1668+
}
1669+
#endif
16531670

1654-
return NULL;
1671+
return home_config;
16551672
}
16561673

16571674
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)