Skip to content

Commit 95e83c7

Browse files
ariellourencoGit for Windows Build Agent
authored andcommitted
Fallback to AppData if XDG_CONFIG_HOME is unset
In order to be a better Windows citizenship, Git should save its configuration files on AppData folder. This can enables git configuration files be replicated between machines using the same Microsoft account logon which would reduce the friction of setting up Git on new systems. Therefore, if %APPDATA%\Git\config exists, we use it; otherwise $HOME/.config/git/config is used. Signed-off-by: Ariel Lourenco <ariellourenco@users.noreply.github.com>
1 parent 1a05e8d commit 95e83c7

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

lib/path.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,7 @@ int looks_like_command_line_option(const char *str)
15451545
char *xdg_config_home_for(const char *subdir, const char *filename)
15461546
{
15471547
const char *home, *config_home;
1548+
char *home_config = NULL;
15481549

15491550
assert(subdir);
15501551
assert(filename);
@@ -1553,10 +1554,26 @@ char *xdg_config_home_for(const char *subdir, const char *filename)
15531554
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
15541555

15551556
home = getenv("HOME");
1556-
if (home)
1557-
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1557+
if (home && *home)
1558+
home_config = mkpathdup("%s/.config/%s/%s", home, subdir, filename);
1559+
1560+
#ifdef WIN32
1561+
{
1562+
const char *appdata = getenv("APPDATA");
1563+
if (appdata && *appdata) {
1564+
char *appdata_config = mkpathdup("%s/Git/%s", appdata, filename);
1565+
if (file_exists(appdata_config)) {
1566+
if (home_config && file_exists(home_config))
1567+
warning("'%s' was ignored because '%s' exists.", home_config, appdata_config);
1568+
free(home_config);
1569+
return appdata_config;
1570+
}
1571+
free(appdata_config);
1572+
}
1573+
}
1574+
#endif
15581575

1559-
return NULL;
1576+
return home_config;
15601577
}
15611578

15621579
char *xdg_config_home(const char *filename)

0 commit comments

Comments
 (0)