Skip to content

Commit cc9730b

Browse files
committed
Merge pull request #104 from dscho/super-config
Add support for %PROGRAMDATA%\Git\config Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 2120bb9 + 669fe4d commit cc9730b

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

Documentation/config.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ the Git commands' behavior. The `.git/config` file in each repository
66
is used to store the configuration for that repository, and
77
`$HOME/.gitconfig` is used to store a per-user configuration as
88
fallback values for the `.git/config` file. The file `/etc/gitconfig`
9-
can be used to store a system-wide default configuration.
9+
can be used to store a system-wide default configuration. On Windows,
10+
configuration can also be stored in `C:\ProgramData\Git\config`; This
11+
file will be used also by libgit2-based software.
1012

1113
The configuration variables are used by both the Git plumbing
1214
and the porcelains. The variables are divided into sections, wherein

compat/mingw.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,3 +2378,12 @@ void mingw_startup()
23782378
/* init length of current directory for handle_long_path */
23792379
current_directory_len = GetCurrentDirectoryW(0, NULL);
23802380
}
2381+
2382+
const char *windows_wide_config(void)
2383+
{
2384+
static struct strbuf windows_wide = STRBUF_INIT;
2385+
if (!windows_wide.len)
2386+
strbuf_addf(&windows_wide,
2387+
"%s\\Git\\config", getenv("PROGRAMDATA"));
2388+
return windows_wide.buf;
2389+
}

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)
392392
int mingw_offset_1st_component(const char *path);
393393
#define offset_1st_component mingw_offset_1st_component
394394
#define PATH_SEP ';'
395+
extern const char *windows_wide_config(void);
396+
#define git_super_config windows_wide_config
395397
#ifndef __MINGW64_VERSION_MAJOR
396398
#define PRIuMAX "I64u"
397399
#define PRId64 "I64d"

config.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,11 +1204,18 @@ int git_config_system(void)
12041204
int git_config_early(config_fn_t fn, void *data, const char *repo_config)
12051205
{
12061206
int ret = 0, found = 0;
1207+
const char *super_config = git_super_config();
12071208
char *xdg_config = NULL;
12081209
char *user_config = NULL;
12091210

12101211
home_config_paths(&user_config, &xdg_config, "config");
12111212

1213+
if (super_config && git_config_system() &&
1214+
!access(super_config, R_OK)) {
1215+
ret += git_config_from_file(fn, super_config, data);
1216+
found += 1;
1217+
}
1218+
12121219
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) {
12131220
ret += git_config_from_file(fn, git_etc_gitconfig(),
12141221
data);

git-compat-util.h

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

310+
#ifndef git_super_gitconfig
311+
#define git_super_gitconfig NULL
312+
#endif
313+
310314
#if defined(__HP_cc) && (__HP_cc >= 61000)
311315
#define NORETURN __attribute__((noreturn))
312316
#define NORETURN_PTR

0 commit comments

Comments
 (0)