Skip to content

Commit 4f2a17a

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 f4bfac4 commit 4f2a17a

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
@@ -1441,6 +1441,7 @@ int looks_like_command_line_option(const char *str)
14411441
char *xdg_config_home_for(const char *subdir, const char *filename)
14421442
{
14431443
const char *home, *config_home;
1444+
char *home_config = NULL;
14441445

14451446
assert(subdir);
14461447
assert(filename);
@@ -1449,10 +1450,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
14491450
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
14501451

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

1455-
return NULL;
1472+
return home_config;
14561473
}
14571474

14581475
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)