Skip to content

Commit

Permalink
Fallback to AppData if XDG_CONFIG_HOME is unset (git-for-windows#5030)
Browse files Browse the repository at this point in the history
  • Loading branch information
dscho authored Jul 4, 2024
2 parents 02e091b + a4a94c2 commit 15e18f2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions path.c
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ int looks_like_command_line_option(const char *str)
char *xdg_config_home_for(const char *subdir, const char *filename)
{
const char *home, *config_home;
char *home_config = NULL;

assert(subdir);
assert(filename);
Expand All @@ -1581,10 +1582,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
return mkpathdup("%s/%s/%s", config_home, subdir, filename);

home = getenv("HOME");
if (home)
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
if (home && *home)
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);

#ifdef WIN32
{
const char *appdata = getenv("APPDATA");
if (appdata && *appdata) {
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
if (file_exists(appdata_config)) {
if (home_config && file_exists(home_config))
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
free(home_config);
return appdata_config;
}
free(appdata_config);
}
}
#endif

return NULL;
return home_config;
}

char *xdg_config_home(const char *filename)
Expand Down

0 comments on commit 15e18f2

Please sign in to comment.