With Git 2.36 (Q2 2022), you will have another option than relying on a local folder: the conditional inclusion mechanism of configuration files using "[includeIf <condition>]
" learns to base its decision on the URL of the remote repository the repository interacts with.
See commit 399b198, commit ed69e11 (18 Jan 2022) by Jonathan Tan (jhowtan
).
(Merged by Junio C Hamano -- gitster
-- in commit 13ce8f9, 09 Feb 2022)
config
: include file if remote URL matches a glob
Signed-off-by: Jonathan Tan
Acked-by: Elijah Newren
This is a feature that supports config file inclusion conditional on whether the repo has a remote with a URL that matches a glob.
Similar to my previous work on remote-suggested hooks, the main motivation is to allow remote repo administrators to provide recommended configs in a way that can be consumed more easily (e.g. through a package installable by a package manager - it could, for example, contain a file to be included conditionally and a post-install script that adds the include directive to the system-wide config file).
In order to do this, Git reruns the config parsing mechanism upon noticing the first URL-conditional include in order to find all remote URLs, and these remote URLs are then used to determine if that first and all subsequent includes are executed.
Remote URLs are not allowed to be configured in any URL-conditionally-included file.
config
now includes in its man page:
hasconfig:remote.*.url:
The data that follows this keyword is taken to
be a pattern with standard globbing wildcards and two
additional ones, **/
and /**
, that can match multiple
components.
The first time this keyword is seen, the rest of
the config files will be scanned for remote URLs (without
applying any values).
If there exists at least one remote URL
that matches this pattern, the include condition is met.
Files included by this option (directly or indirectly) are not allowed
to contain remote URLs.
Note that unlike other includeIf
conditions, resolving this condition
relies on information that is not yet known at the point of reading the
condition.
A typical use case is this option being present as a
system-level or global-level config, and the remote URL being in a
local-level config; hence the need to scan ahead when resolving this
condition.
In order to avoid the chicken-and-egg problem in which
potentially-included files can affect whether such files are potentially
included, Git breaks the cycle by prohibiting these files from affecting
the resolution of these conditions (thus, prohibiting them from
declaring remote URLs).
As for the naming of this keyword, it is for forwards compatibility with
a naming scheme that supports more variable-based include conditions,
but currently Git only supports the exact keyword described above.
config
now includes in its man page:
; include only if a remote with the given URL exists (note
; that such a URL may be provided later in a file or in a
; file read after this file is read, as seen in this example)
[includeIf "hasconfig:remote.*.url:https://example.com/**"]
path = foo.inc
[remote "origin"]
url = https://example.com/git