Re: [PATCH v6 1/1] config: add conditional include
From: Ramsay Jones <hidden>
Date: 2017-02-24 19:48:43
On 24/02/17 13:14, Nguyễn Thái Ngọc Duy wrote: [snip]
quoted hunk ↗ jump to hunk
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted> --- Documentation/config.txt | 61 +++++++++++++++++++++++++++++ config.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++ t/t1305-config-include.sh | 56 +++++++++++++++++++++++++++ 3 files changed, 214 insertions(+)diff --git a/Documentation/config.txt b/Documentation/config.txt index 015346c417..6c0cd2a273 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt@@ -91,6 +91,56 @@ found at the location of the include directive. If the value of the relative to the configuration file in which the include directive was found. See below for examples. +Conditional includes +~~~~~~~~~~~~~~~~~~~~ + +You can include one config file from another conditionally by setting +a `includeIf.<condition>.path` variable to the name of the file to be +included. The variable's value is treated the same way as `include.path`. + +The condition starts with a keyword followed by a colon and some data +whose format and meaning depends on the keyword. Supported keywords +are: + +`gitdir`:: + + The data that follows the keyword `gitdir:` is used as a glob + pattern. If the location of the .git directory match the + pattern, the include condition is met. ++ +The .git location which may be auto-discovered, or come from +`$GIT_DIR` environment variable. If the repository auto discovered via +a .git file (e.g. from submodules, or a linked worktree), the .git +location would be the final location, not where the .git file is. ++ +The pattern can contain standard globbing wildcards and two additional +ones, `**/` and `/**`, that can match multiple path components. Please +refer to linkgit:gitignore[5] for details. For convenience: + + * If the pattern starts with `~/`, `~` will be substituted with the + content of the environment variable `HOME`. + + * If the pattern starts with `./`, it is replaced with the directory + containing the current config file. + + * If the pattern does not start with either `~/`, `./` or `/`, `**/` + will be automatically prepended. For example, the pattern `foo/bar` + becomes `**/foo/bar` and would match `/any/path/to/foo/bar`. + + * If the pattern ends with `/`, `**` will be automatically added. For + example, the pattern `foo/` becomes `foo/**`. In other words, it + matches "foo" and everything inside, recursively. + +`gitdir/i`:: + This is the same as `gitdir` except that matching is done + case-insensitively (e.g. on case-insensitive file sytems) + +A few more notes on matching with `gitdir` and `gitdir/i`: + + * Symlinks in `$GIT_DIR` are not resolved before matching. + + * Note that "../" is not special and will match literally, which is + unlikely what you want. Example ~~~~~~~@@ -119,6 +169,17 @@ Example path = foo ; expand "foo" relative to the current file path = ~/foo ; expand "foo" in your `$HOME` directory + ; include if $GIT_DIR is /path/to/foo/.git + [include-if "gitdir:/path/to/foo/.git"]
s/include-if/includeIf/
+ path = /path/to/foo.inc + + ; include for all repositories inside /path/to/group + [include-if "gitdir:/path/to/group/"]
ditto
+ path = /path/to/foo.inc + + ; include for all repositories inside $HOME/to/group + [include-if "gitdir:~/to/group/"]
ditto ATB, Ramsay Jones