Skip to content

Commit 5671fbe

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 e97a158 + e376516 commit 5671fbe

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
@@ -1556,6 +1556,7 @@ int looks_like_command_line_option(const char *str)
15561556
char *xdg_config_home_for(const char *subdir, const char *filename)
15571557
{
15581558
const char *home, *config_home;
1559+
char *home_config = NULL;
15591560

15601561
assert(subdir);
15611562
assert(filename);
@@ -1564,10 +1565,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
15641565
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
15651566

15661567
home = getenv("HOME");
1567-
if (home)
1568-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1568+
if (home && *home)
1569+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1570+
1571+
#ifdef WIN32
1572+
{
1573+
const char *appdata = getenv("APPDATA");
1574+
if (appdata && *appdata) {
1575+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1576+
if (file_exists(appdata_config)) {
1577+
if (home_config && file_exists(home_config))
1578+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1579+
free(home_config);
1580+
return appdata_config;
1581+
}
1582+
free(appdata_config);
1583+
}
1584+
}
1585+
#endif
15691586

1570-
return NULL;
1587+
return home_config;
15711588
}
15721589

15731590
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)