Skip to content

Commit 3e2772d

Browse files
ariellourencoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
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 ff7cab8 commit 3e2772d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

path.c

+20-3
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,7 @@ int looks_like_command_line_option(const char *str)
15731573
char *xdg_config_home_for(const char *subdir, const char *filename)
15741574
{
15751575
const char *home, *config_home;
1576+
char *home_config = NULL;
15761577

15771578
assert(subdir);
15781579
assert(filename);
@@ -1581,10 +1582,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
15811582
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
15821583

15831584
home = getenv("HOME");
1584-
if (home)
1585-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1585+
if (home && *home)
1586+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1587+
1588+
#ifdef WIN32
1589+
{
1590+
const char *appdata = getenv("APPDATA");
1591+
if (appdata && *appdata) {
1592+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1593+
if (file_exists(appdata_config)) {
1594+
if (home_config && file_exists(home_config))
1595+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1596+
free(home_config);
1597+
return appdata_config;
1598+
}
1599+
free(appdata_config);
1600+
}
1601+
}
1602+
#endif
15861603

1587-
return NULL;
1604+
return home_config;
15881605
}
15891606

15901607
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)