Skip to content

Commit 0012b2d

Browse files
committed
Merge branch 'program-data-config'
This branch introduces support for reading the "Windows-wide" Git configuration from `%PROGRAMDATA%\Git\config`. As these settings are intended to be shared between *all* Git-related software, that config file takes an even lower precedence than `$(prefix)/etc/gitconfig`. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 4d517b7 + 1b99d0e commit 0012b2d

File tree

7 files changed

+43
-5
lines changed

7 files changed

+43
-5
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

Documentation/git-config.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,16 @@ FILES
263263
If not set explicitly with `--file`, there are four files where
264264
'git config' will search for configuration options:
265265

266+
$PROGRAMDATA/Git/config::
267+
(Windows-only) System-wide configuration file shared with other Git
268+
implementations. Typically `$PROGRAMDATA` points to `C:\ProgramData`.
269+
266270
$(prefix)/etc/gitconfig::
267271
System-wide configuration file.
272+
(Windows-only) This file contains only the settings which are
273+
specific for this installation of Git for Windows and which should
274+
not be shared with other Git implementations like JGit, libgit2.
275+
`--system` will select this file.
268276

269277
$XDG_CONFIG_HOME/git/config::
270278
Second user-specific configuration file. If $XDG_CONFIG_HOME is not set

Documentation/git.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@ for further details.
567567

568568
`GIT_CONFIG_NOSYSTEM`::
569569
Whether to skip reading settings from the system-wide
570-
`$(prefix)/etc/gitconfig` file. This environment variable can
570+
`$(prefix)/etc/gitconfig` file (and on Windows, also from the
571+
`%PROGRAMDATA%\Git\config` file). This environment variable can
571572
be used along with `$HOME` and `$XDG_CONFIG_HOME` to create a
572573
predictable environment for a picky script, or you can set it
573574
temporarily to avoid using a buggy `/etc/gitconfig` file while

compat/mingw.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,3 +2963,17 @@ int uname(struct utsname *buf)
29632963
"%u", (v >> 16) & 0x7fff);
29642964
return 0;
29652965
}
2966+
2967+
const char *program_data_config(void)
2968+
{
2969+
static struct strbuf path = STRBUF_INIT;
2970+
static unsigned initialized;
2971+
2972+
if (!initialized) {
2973+
const char *env = mingw_getenv("PROGRAMDATA");
2974+
if (env)
2975+
strbuf_addf(&path, "%s/Git/config", env);
2976+
initialized = 1;
2977+
}
2978+
return *path.buf ? path.buf : NULL;
2979+
}

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ int mingw_offset_1st_component(const char *path);
468468
#define PATH_SEP ';'
469469
extern char *mingw_query_user_email(void);
470470
#define query_user_email mingw_query_user_email
471+
extern const char *program_data_config(void);
472+
#define git_program_data_config program_data_config
471473
#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
472474
#define PRIuMAX "I64u"
473475
#define PRId64 "I64d"

config.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,9 +1672,16 @@ static int do_git_config_sequence(const struct config_options *opts,
16721672
repo_config = NULL;
16731673

16741674
current_parsing_scope = CONFIG_SCOPE_SYSTEM;
1675-
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0))
1676-
ret += git_config_from_file(fn, git_etc_gitconfig(),
1677-
data);
1675+
if (git_config_system()) {
1676+
if (git_program_data_config() &&
1677+
!access_or_die(git_program_data_config(), R_OK, 0))
1678+
ret += git_config_from_file(fn,
1679+
git_program_data_config(),
1680+
data);
1681+
if (!access_or_die(git_etc_gitconfig(), R_OK, 0))
1682+
ret += git_config_from_file(fn, git_etc_gitconfig(),
1683+
data);
1684+
}
16781685

16791686
current_parsing_scope = CONFIG_SCOPE_GLOBAL;
16801687
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ static inline char *git_find_last_dir_sep(const char *path)
396396
#define query_user_email() NULL
397397
#endif
398398

399+
#ifndef git_program_data_config
400+
#define git_program_data_config() NULL
401+
#endif
402+
399403
#if defined(__HP_cc) && (__HP_cc >= 61000)
400404
#define NORETURN __attribute__((noreturn))
401405
#define NORETURN_PTR

0 commit comments

Comments
 (0)