Skip to content

Commit ed68ed3

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
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 fcf7a4b + 8178776 commit ed68ed3

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
@@ -1482,6 +1482,7 @@ int looks_like_command_line_option(const char *str)
14821482
char *xdg_config_home_for(const char *subdir, const char *filename)
14831483
{
14841484
const char *home, *config_home;
1485+
char *home_config = NULL;
14851486

14861487
assert(subdir);
14871488
assert(filename);
@@ -1490,10 +1491,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
14901491
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
14911492

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

1496-
return NULL;
1513+
return home_config;
14971514
}
14981515

14991516
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)