Skip to content

Commit bf4b3fa

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 50c3d9d commit bf4b3fa

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
@@ -1517,6 +1517,7 @@ int looks_like_command_line_option(const char *str)
15171517
char *xdg_config_home_for(const char *subdir, const char *filename)
15181518
{
15191519
const char *home, *config_home;
1520+
char *home_config = NULL;
15201521

15211522
assert(subdir);
15221523
assert(filename);
@@ -1525,10 +1526,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
15251526
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
15261527

15271528
home = getenv("HOME");
1528-
if (home)
1529-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1529+
if (home && *home)
1530+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1531+
1532+
#ifdef WIN32
1533+
{
1534+
const char *appdata = getenv("APPDATA");
1535+
if (appdata && *appdata) {
1536+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1537+
if (file_exists(appdata_config)) {
1538+
if (home_config && file_exists(home_config))
1539+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1540+
free(home_config);
1541+
return appdata_config;
1542+
}
1543+
free(appdata_config);
1544+
}
1545+
}
1546+
#endif
15301547

1531-
return NULL;
1548+
return home_config;
15321549
}
15331550

15341551
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)