Skip to content

Commit 8178776

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 d6f85ec commit 8178776

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
@@ -1443,6 +1443,7 @@ int looks_like_command_line_option(const char *str)
14431443
char *xdg_config_home_for(const char *subdir, const char *filename)
14441444
{
14451445
const char *home, *config_home;
1446+
char *home_config = NULL;
14461447

14471448
assert(subdir);
14481449
assert(filename);
@@ -1451,10 +1452,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
14511452
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
14521453

14531454
home = getenv("HOME");
1454-
if (home)
1455-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1455+
if (home && *home)
1456+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1457+
1458+
#ifdef WIN32
1459+
{
1460+
const char *appdata = getenv("APPDATA");
1461+
if (appdata && *appdata) {
1462+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1463+
if (file_exists(appdata_config)) {
1464+
if (home_config && file_exists(home_config))
1465+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1466+
free(home_config);
1467+
return appdata_config;
1468+
}
1469+
free(appdata_config);
1470+
}
1471+
}
1472+
#endif
14561473

1457-
return NULL;
1474+
return home_config;
14581475
}
14591476

14601477
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)