Skip to content

Commit a060345

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 88bffce + 36ffa8c commit a060345

File tree

7 files changed

+43
-7
lines changed

7 files changed

+43
-7
lines changed

Documentation/config.txt

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

1214
The configuration variables are used by both the Git plumbing
1315
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
@@ -272,8 +272,16 @@ FILES
272272
If not set explicitly with `--file`, there are four files where
273273
'git config' will search for configuration options:
274274

275+
$PROGRAMDATA/Git/config::
276+
(Windows-only) System-wide configuration file shared with other Git
277+
implementations. Typically `$PROGRAMDATA` points to `C:\ProgramData`.
278+
275279
$(prefix)/etc/gitconfig::
276280
System-wide configuration file.
281+
(Windows-only) This file contains only the settings which are
282+
specific for this installation of Git for Windows and which should
283+
not be shared with other Git implementations like JGit, libgit2.
284+
`--system` will select this file.
277285

278286
$XDG_CONFIG_HOME/git/config::
279287
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
@@ -566,7 +566,8 @@ for further details.
566566

567567
`GIT_CONFIG_NOSYSTEM`::
568568
Whether to skip reading settings from the system-wide
569-
`$(prefix)/etc/gitconfig` file. This environment variable can
569+
`$(prefix)/etc/gitconfig` file (and on Windows, also from the
570+
`%PROGRAMDATA%\Git\config` file). This environment variable can
570571
be used along with `$HOME` and `$XDG_CONFIG_HOME` to create a
571572
predictable environment for a picky script, or you can set it
572573
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
@@ -2540,3 +2540,17 @@ int uname(struct utsname *buf)
25402540
"%u", (v >> 16) & 0x7fff);
25412541
return 0;
25422542
}
2543+
2544+
const char *program_data_config(void)
2545+
{
2546+
static struct strbuf path = STRBUF_INIT;
2547+
static unsigned initialized;
2548+
2549+
if (!initialized) {
2550+
const char *env = mingw_getenv("PROGRAMDATA");
2551+
if (env)
2552+
strbuf_addf(&path, "%s/Git/config", env);
2553+
initialized = 1;
2554+
}
2555+
return *path.buf ? path.buf : NULL;
2556+
}

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ static inline void convert_slashes(char *path)
445445
#define PATH_SEP ';'
446446
extern char *mingw_query_user_email(void);
447447
#define query_user_email mingw_query_user_email
448+
extern const char *program_data_config(void);
449+
#define git_program_data_config program_data_config
448450
#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
449451
#define PRIuMAX "I64u"
450452
#define PRId64 "I64d"

config.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,11 +1676,16 @@ static int do_git_config_sequence(const struct config_options *opts,
16761676
repo_config = NULL;
16771677

16781678
current_parsing_scope = CONFIG_SCOPE_SYSTEM;
1679-
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK,
1680-
opts->system_gently ?
1681-
ACCESS_EACCES_OK : 0))
1682-
ret += git_config_from_file(fn, git_etc_gitconfig(),
1683-
data);
1679+
if (git_config_system()) {
1680+
int flags = opts->system_gently ? ACCESS_EACCES_OK : 0;
1681+
const char *program_data = git_program_data_config();
1682+
const char *etc = git_etc_gitconfig();
1683+
1684+
if (program_data && !access_or_die(program_data, R_OK, flags))
1685+
ret += git_config_from_file(fn, program_data, data);
1686+
if (!access_or_die(etc, R_OK, flags))
1687+
ret += git_config_from_file(fn, etc, data);
1688+
}
16841689

16851690
current_parsing_scope = CONFIG_SCOPE_GLOBAL;
16861691
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
@@ -421,6 +421,10 @@ static inline char *git_find_last_dir_sep(const char *path)
421421
#endif
422422
#endif
423423

424+
#ifndef git_program_data_config
425+
#define git_program_data_config() NULL
426+
#endif
427+
424428
#if defined(__HP_cc) && (__HP_cc >= 61000)
425429
#define NORETURN __attribute__((noreturn))
426430
#define NORETURN_PTR

0 commit comments

Comments
 (0)