Re: [PATCH v6 1/1] config: add conditional include
From: Philip Oakley <hidden>
Date: 2017-02-24 22:08:24
From: "Nguyễn Thái Ngọc Duy" <redacted>
quoted hunk ↗ jump to hunk
Sometimes a set of repositories want to share configuration settings among themselves that are distinct from other such sets of repositories. A user may work on two projects, each of which have multiple repositories, and use one user.email for one project while using another for the other. Setting $GIT_DIR/.config works, but if the penalty of forgetting to update $GIT_DIR/.config is high (especially when you end up cloning often), it may not be the best way to go. Having the settings in ~/.gitconfig, which would work for just one set of repositories, would not well in such a situation. Having separate ${HOME}s may add more problems than it solves. Extend the include.path mechanism that lets a config file include another config file, so that the inclusion can be done only when some conditions hold. Then ~/.gitconfig can say "include config-project-A only when working on project-A" for each project A the user works on. In this patch, the only supported grouping is based on $GIT_DIR (in absolute path), so you would need to group repositories by directory, or something like that to take advantage of it. We already have include.path for unconditional includes. This patch goes with includeIf.<condition>.path to make it clearer that a condition is required. The new config has the same backward compatibility approach as include.path: older git versions that don't understand includeIf will simply ignore them. 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 thevalue 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
On first reading I thought this implied you can only have one `includeIf` within the config file. I think it is meant to mean that each `includeIf`could include one other file, and that users can have multiple `includeIf` lines.
+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`. +
-- Philip