Skip to content

Commit 297386b

Browse files
committed
Windows: use %PROGRAMDATA%\Git\config as Windows-wide configuration
Between the libgit2 and the Git for Windows project, there has been a discussion how we could share Git configuration to avoid duplication (or worse: skew). Earlier, libgit2 was nice enough to just re-use Git for Windows' C:\Program Files (x86)\Git\etc\gitconfig but with the upcoming Git for Windows 2.x, there would be more paths to search, as we will have 64-bit and 32-bit versions, and the corresponding config files will be in %PROGRAMFILES%\Git\mingw64\etc and ...\mingw32\etc, respectively. Therefore we came to a consensus to use %PROGRAMDATA%\Git as the location for Git-specific files that are of wider interest than just Git for Windows. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 16685c2 commit 297386b

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

compat/mingw.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,3 +2128,12 @@ void mingw_startup()
21282128
/* initialize Unicode console */
21292129
winansi_init();
21302130
}
2131+
2132+
const char *windows_wide_config(void)
2133+
{
2134+
static struct strbuf windows_wide = STRBUF_INIT;
2135+
if (!windows_wide.len)
2136+
strbuf_addf(&windows_wide,
2137+
"%s\\Git\\config", getenv("PROGRAMDATA"));
2138+
return windows_wide.buf;
2139+
}

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)
359359
int mingw_offset_1st_component(const char *path);
360360
#define offset_1st_component mingw_offset_1st_component
361361
#define PATH_SEP ';'
362+
extern const char *windows_wide_config(void);
363+
#define git_super_config windows_wide_config
362364
#define PRIuMAX "I64u"
363365
#define PRId64 "I64d"
364366

config.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,11 +1185,18 @@ int git_config_system(void)
11851185
int git_config_early(config_fn_t fn, void *data, const char *repo_config)
11861186
{
11871187
int ret = 0, found = 0;
1188+
const char *super_config = git_super_config();
11881189
char *xdg_config = NULL;
11891190
char *user_config = NULL;
11901191

11911192
home_config_paths(&user_config, &xdg_config, "config");
11921193

1194+
if (super_config && git_config_system() &&
1195+
!access(super_config, R_OK)) {
1196+
ret += git_config_from_file(fn, super_config, data);
1197+
found += 1;
1198+
}
1199+
11931200
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) {
11941201
ret += git_config_from_file(fn, git_etc_gitconfig(),
11951202
data);

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ static inline char *git_find_last_dir_sep(const char *path)
301301
#define find_last_dir_sep git_find_last_dir_sep
302302
#endif
303303

304+
#ifndef git_super_gitconfig
305+
#define git_super_gitconfig NULL
306+
#endif
307+
304308
#if defined(__HP_cc) && (__HP_cc >= 61000)
305309
#define NORETURN __attribute__((noreturn))
306310
#define NORETURN_PTR

0 commit comments

Comments
 (0)