Skip to content

Commit 1ef07d3

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 cbf2f34 + 672e11b commit 1ef07d3

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
@@ -1679,6 +1679,7 @@ int looks_like_command_line_option(const char *str)
16791679
char *xdg_config_home_for(const char *subdir, const char *filename)
16801680
{
16811681
const char *home, *config_home;
1682+
char *home_config = NULL;
16821683

16831684
assert(subdir);
16841685
assert(filename);
@@ -1687,10 +1688,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
16871688
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
16881689

16891690
home = getenv("HOME");
1690-
if (home)
1691-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1691+
if (home && *home)
1692+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1693+
1694+
#ifdef WIN32
1695+
{
1696+
const char *appdata = getenv("APPDATA");
1697+
if (appdata && *appdata) {
1698+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1699+
if (file_exists(appdata_config)) {
1700+
if (home_config && file_exists(home_config))
1701+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1702+
free(home_config);
1703+
return appdata_config;
1704+
}
1705+
free(appdata_config);
1706+
}
1707+
}
1708+
#endif
16921709

1693-
return NULL;
1710+
return home_config;
16941711
}
16951712

16961713
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)