Skip to content

Commit a049827

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 e6a7b1d + 54cabab commit a049827

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
@@ -1583,6 +1583,7 @@ int looks_like_command_line_option(const char *str)
15831583
char *xdg_config_home_for(const char *subdir, const char *filename)
15841584
{
15851585
const char *home, *config_home;
1586+
char *home_config = NULL;
15861587

15871588
assert(subdir);
15881589
assert(filename);
@@ -1591,10 +1592,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
15911592
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
15921593

15931594
home = getenv("HOME");
1594-
if (home)
1595-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1595+
if (home && *home)
1596+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1597+
1598+
#ifdef WIN32
1599+
{
1600+
const char *appdata = getenv("APPDATA");
1601+
if (appdata && *appdata) {
1602+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1603+
if (file_exists(appdata_config)) {
1604+
if (home_config && file_exists(home_config))
1605+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1606+
free(home_config);
1607+
return appdata_config;
1608+
}
1609+
free(appdata_config);
1610+
}
1611+
}
1612+
#endif
15961613

1597-
return NULL;
1614+
return home_config;
15981615
}
15991616

16001617
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)