Skip to content

Commit 4361fd2

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 49c00f8 commit 4361fd2

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
@@ -1544,6 +1544,7 @@ int looks_like_command_line_option(const char *str)
15441544
char *xdg_config_home_for(const char *subdir, const char *filename)
15451545
{
15461546
const char *home, *config_home;
1547+
char *home_config = NULL;
15471548

15481549
assert(subdir);
15491550
assert(filename);
@@ -1552,10 +1553,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
15521553
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
15531554

15541555
home = getenv("HOME");
1555-
if (home)
1556-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1556+
if (home && *home)
1557+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1558+
1559+
#ifdef WIN32
1560+
{
1561+
const char *appdata = getenv("APPDATA");
1562+
if (appdata && *appdata) {
1563+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1564+
if (file_exists(appdata_config)) {
1565+
if (home_config && file_exists(home_config))
1566+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1567+
free(home_config);
1568+
return appdata_config;
1569+
}
1570+
free(appdata_config);
1571+
}
1572+
}
1573+
#endif
15571574

1558-
return NULL;
1575+
return home_config;
15591576
}
15601577

15611578
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)