Skip to content

Commit da2c468

Browse files
committed
Merge branch 'Fallback-to-AppData-if-XDG-CONFIG-HOME-is-unset'
This topic branch adds support for a more Windows-native user-wide config file than `XDG_CONFIG_HOME` (or `~/.config/`) will ever be. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 194aecd + b8f18af commit da2c468

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
@@ -1478,6 +1478,7 @@ int looks_like_command_line_option(const char *str)
14781478
char *xdg_config_home_for(const char *subdir, const char *filename)
14791479
{
14801480
const char *home, *config_home;
1481+
char *home_config = NULL;
14811482

14821483
assert(subdir);
14831484
assert(filename);
@@ -1486,10 +1487,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
14861487
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
14871488

14881489
home = getenv("HOME");
1489-
if (home)
1490-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1490+
if (home && *home)
1491+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1492+
1493+
#ifdef WIN32
1494+
{
1495+
const char *appdata = getenv("APPDATA");
1496+
if (appdata && *appdata) {
1497+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1498+
if (file_exists(appdata_config)) {
1499+
if (home_config && file_exists(home_config))
1500+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1501+
free(home_config);
1502+
return appdata_config;
1503+
}
1504+
free(appdata_config);
1505+
}
1506+
}
1507+
#endif
14911508

1492-
return NULL;
1509+
return home_config;
14931510
}
14941511

14951512
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)