Skip to content

Commit 90c0a74

Browse files
committed
config.c: add support for installation-specific config files
If Git is configured to use the absolute '/etc/gitconfig' for system-wide settings, it may still be useful to have installation-specific settings such as 'help.format' (which depends on the installed set of help pages). This is particularly relevant on Windows, where a variety of Git flavors with different feature sets may be installed in parallel. If ETC_GITCONFIG is an absolute path (typically '/etc/gitconfig'), load installation-specific defaults (from '$(prefix)/$(ETC_GITCONFIG)') before loading the system-wide configuration. As installation-specific settings will typically be defined when creating the software package / installer (i.e. *before* git is installed), we don't need an extra 'git config --installation' option. Update the documentation accordingly. This removes '$(prefix)' from most places (which would be meaningless to normal users anyway). Signed-off-by: Karsten Blees <[email protected]>
1 parent 3f7ec02 commit 90c0a74

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

Documentation/git-config.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ See also <<FILES>>.
117117

118118
--system::
119119
For writing options: write to system-wide
120-
`$(prefix)/etc/gitconfig` rather than the repository
120+
`/etc/gitconfig` rather than the repository
121121
`.git/config`.
122122
+
123-
For reading options: read only from system-wide `$(prefix)/etc/gitconfig`
123+
For reading options: read only from system-wide `/etc/gitconfig`
124124
rather than from all available files.
125125
+
126126
See also <<FILES>>.
@@ -221,11 +221,21 @@ See also <<FILES>>.
221221
FILES
222222
-----
223223

224-
If not set explicitly with '--file', there are four files where
224+
If not set explicitly with '--file', there are five files where
225225
'git config' will search for configuration options:
226226

227227
$(prefix)/etc/gitconfig::
228+
Installation-specific configuration file, where '$(prefix)' is the
229+
installation root directory specified via 'make prefix=...'. This allows
230+
software distributions to provide installation-specific default values
231+
(e.g. 'help.format=html' if the installation only includes html pages).
232+
233+
/etc/gitconfig::
228234
System-wide configuration file.
235+
+
236+
If git was built with relative `$(sysconfdir)`, this file will not be
237+
used, and the '--system' option refers to the installation-specific
238+
`$(prefix)/etc/gitconfig` instead.
229239

230240
$XDG_CONFIG_HOME/git/config::
231241
Second user-specific configuration file. If $XDG_CONFIG_HOME is not set
@@ -268,11 +278,11 @@ ENVIRONMENT
268278
GIT_CONFIG::
269279
Take the configuration from the given file instead of .git/config.
270280
Using the "--global" option forces this to ~/.gitconfig. Using the
271-
"--system" option forces this to $(prefix)/etc/gitconfig.
281+
"--system" option forces this to /etc/gitconfig.
272282

273283
GIT_CONFIG_NOSYSTEM::
274-
Whether to skip reading settings from the system-wide
275-
$(prefix)/etc/gitconfig file. See linkgit:git[1] for details.
284+
Whether to skip reading settings from the installation-specific and
285+
system-wide /etc/gitconfig files. See linkgit:git[1] for details.
276286

277287
See also <<FILES>>.
278288

Documentation/git.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,8 @@ for further details.
939939
on the terminal (e.g., when asking for HTTP authentication).
940940

941941
'GIT_CONFIG_NOSYSTEM'::
942-
Whether to skip reading settings from the system-wide
943-
`$(prefix)/etc/gitconfig` file. This environment variable can
942+
Whether to skip reading settings from the installation-specific and
943+
system-wide `/etc/gitconfig` files. This environment variable can
944944
be used along with `$HOME` and `$XDG_CONFIG_HOME` to create a
945945
predictable environment for a picky script, or you can set it
946946
temporarily to avoid using a buggy `/etc/gitconfig` file while

Documentation/gitattributes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ for a single user should be placed in a file specified by the
8484
Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME
8585
is either not set or empty, $HOME/.config/git/attributes is used instead.
8686
Attributes for all users on a system should be placed in the
87-
`$(prefix)/etc/gitattributes` file.
87+
`/etc/gitattributes` file.
8888

8989
Sometimes you would need to override an setting of an attribute
9090
for a path to `Unspecified` state. This can be done by listing

config.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,14 +1147,32 @@ static int git_config_from_blob_ref(config_fn_t fn,
11471147
return git_config_from_blob_sha1(fn, name, sha1, data);
11481148
}
11491149

1150+
static const char *etc_gitconfig = ETC_GITCONFIG;
1151+
11501152
const char *git_etc_gitconfig(void)
11511153
{
11521154
static const char *system_wide;
11531155
if (!system_wide)
1154-
system_wide = system_path(ETC_GITCONFIG);
1156+
system_wide = system_path(etc_gitconfig);
11551157
return system_wide;
11561158
}
11571159

1160+
static const char *git_inst_gitconfig(void)
1161+
{
1162+
static const char *installation_defaults;
1163+
if (!installation_defaults) {
1164+
/*
1165+
* if ETC_GITCONFIG as configured in the Makefile is an absolute path,
1166+
* also load installation-specific defaults (relative to $(prefix))
1167+
*/
1168+
if (is_dir_sep(*etc_gitconfig))
1169+
installation_defaults = system_path(etc_gitconfig + 1);
1170+
else
1171+
installation_defaults = "";
1172+
}
1173+
return *installation_defaults ? installation_defaults : NULL;
1174+
}
1175+
11581176
/*
11591177
* Parse environment variable 'k' as a boolean (in various
11601178
* possible spellings); if missing, use the default value 'def'.
@@ -1205,8 +1223,10 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
12051223

12061224
home_config_paths(&user_config, &xdg_config, "config");
12071225

1208-
if (git_config_system())
1226+
if (git_config_system()) {
1227+
cnt = config_early_helper(fn, git_inst_gitconfig(), data, 0, cnt);
12091228
cnt = config_early_helper(fn, git_etc_gitconfig(), data, 0, cnt);
1229+
}
12101230

12111231
cnt = config_early_helper(fn, xdg_config, data, ACCESS_EACCES_OK, cnt);
12121232
cnt = config_early_helper(fn, user_config, data, ACCESS_EACCES_OK, cnt);

0 commit comments

Comments
 (0)