Skip to content

Commit 0ccadc5

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
Fallback to AppData if XDG_CONFIG_HOME is unset (#5030)
#316
2 parents ec46080 + e0f7be2 commit 0ccadc5

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
@@ -1523,6 +1523,7 @@ int looks_like_command_line_option(const char *str)
15231523
char *xdg_config_home_for(const char *subdir, const char *filename)
15241524
{
15251525
const char *home, *config_home;
1526+
char *home_config = NULL;
15261527

15271528
assert(subdir);
15281529
assert(filename);
@@ -1531,10 +1532,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
15311532
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
15321533

15331534
home = getenv("HOME");
1534-
if (home)
1535-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1535+
if (home && *home)
1536+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1537+
1538+
#ifdef WIN32
1539+
{
1540+
const char *appdata = getenv("APPDATA");
1541+
if (appdata && *appdata) {
1542+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1543+
if (file_exists(appdata_config)) {
1544+
if (home_config && file_exists(home_config))
1545+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1546+
free(home_config);
1547+
return appdata_config;
1548+
}
1549+
free(appdata_config);
1550+
}
1551+
}
1552+
#endif
15361553

1537-
return NULL;
1554+
return home_config;
15381555
}
15391556

15401557
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)