Skip to content

Commit f971d21

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 fddc419 + 4f2a17a commit f971d21

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
@@ -1480,6 +1480,7 @@ int looks_like_command_line_option(const char *str)
14801480
char *xdg_config_home_for(const char *subdir, const char *filename)
14811481
{
14821482
const char *home, *config_home;
1483+
char *home_config = NULL;
14831484

14841485
assert(subdir);
14851486
assert(filename);
@@ -1488,10 +1489,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
14881489
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
14891490

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

1494-
return NULL;
1511+
return home_config;
14951512
}
14961513

14971514
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)