Skip to content

config: allow disabling config includes#2139

Open
derrickstolee wants to merge 3 commits into
gitgitgadget:masterfrom
derrickstolee:config-include-override
Open

config: allow disabling config includes#2139
derrickstolee wants to merge 3 commits into
gitgitgadget:masterfrom
derrickstolee:config-include-override

Conversation

@derrickstolee
Copy link
Copy Markdown

@derrickstolee derrickstolee commented Jun 4, 2026

This series introduces a new way to ignore config include directives via two mechanisms:

  • GIT_CONFIG_INCLUDES=0 in the environment.
  • git --no-includes ... in the command line.

My motivation is from a tricky situation where users want to do the risky thing and include a repo-tracked file for sharing aliases and other recommended config. They are then struggling in a later build step that is running Git commands (under a tool we don't control and can't change) that then cause filesystem accesses outside of the build system's sandbox.

While git config has a --no-includes option, that doesn't impact the behavior of other Git commands. We build upon that existing logic for disabling includes, though.

Having had recent luck recommending GIT_ADVICE=0 when running Git commands from third-party tools, I thought that a similar environment variable to disable this functionality would be helpful, too.

One thing I do worry about is whether or not this would cause a significant break in behavior, or if this is a relatively safe thing to allow.

The three patches are organized as follows:

  1. Patch 1 has a small typo fix in the config documentation that messes with the format of the bulleted list. I include it here because I add to that list in patch 2.
  2. Patch 2 adds the environment variable and tests it via 'git config' and the use of a Git alias.
  3. Patch 3 adds the '--no-includes' option at the top level.

Thanks,
-Stolee

cc: gitster@pobox.com
cc: Patrick Steinhardt ps@pks.im

The bulletted list about environment variables is missing a '+' between
some paragraphs that belong to the same bullet item. Without it, the
bulletted list is rendered as two separate lists with "See also FILES."
as a normal paragraph between them. Adding '+' unifies the lists.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
@derrickstolee derrickstolee force-pushed the config-include-override branch from ad6549d to 31d173f Compare June 4, 2026 21:05
@derrickstolee derrickstolee changed the title Allow disabling config includes config: allow disabling config includes Jun 4, 2026
The config keys 'include.path' and 'includeIf.*' allow users to specify
config stored in a location outside of the typical list of config files
(system, global, local, etc.). For example, users who accept the risk
can specify helpful aliases via a file checked into the repo by pointing
'include.path' to the position of that file in the working directory.
This is dangerous, but people do it.

What becomes tricky is that this modifies all Git behavior, including
operations that are intended to be limited in activity or sandboxed in
some way. These include directives can provide surprising changes to
behavior, especially when expecting a specific list of allowed file
accesses. This could lead to failed builds, for instance.

To allow for these user-desired features when they are running commands,
add a new GIT_CONFIG_INCLUDES environment variable that disables these
redirections of config when set to zero. This variable can be set by
automation, such as build tooling, to avoid these strange behaviors.
This could be considered a recommended option for tools executing Git
commands, the same as GIT_ADVICE=0.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
@derrickstolee derrickstolee force-pushed the config-include-override branch from 31d173f to daa9564 Compare June 4, 2026 21:15
@derrickstolee derrickstolee marked this pull request as ready for review June 4, 2026 21:15
The previous change added a GIT_CONFIG_INCLUDES=0 override in the
environment, similar to GIT_ADVICE=0. Follow the same model as
--no-advice to add a --no-includes option to the top-level Git options.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
@derrickstolee derrickstolee force-pushed the config-include-override branch from daa9564 to 1b4ae3c Compare June 4, 2026 21:37
@derrickstolee
Copy link
Copy Markdown
Author

/submit

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented Jun 8, 2026

Submitted as pull.2139.git.1780927027.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2139/derrickstolee/config-include-override-v1

To fetch this version to local tag pr-2139/derrickstolee/config-include-override-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2139/derrickstolee/config-include-override-v1

@@ -502,6 +502,11 @@ GIT_CONFIG::
historical compatibility; there is generally no reason to use it
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patrick Steinhardt wrote on the Git mailing list (how to reply to this email):

On Mon, Jun 08, 2026 at 01:57:05PM +0000, Derrick Stolee via GitGitGadget wrote:
> From: Derrick Stolee <stolee@gmail.com>
> 
> The config keys 'include.path' and 'includeIf.*' allow users to specify
> config stored in a location outside of the typical list of config files
> (system, global, local, etc.). For example, users who accept the risk
> can specify helpful aliases via a file checked into the repo by pointing
> 'include.path' to the position of that file in the working directory.
> This is dangerous, but people do it.

Huh, I never even considered this use case. But of course, this is
possible, even though it's quite scary.

> What becomes tricky is that this modifies all Git behavior, including
> operations that are intended to be limited in activity or sandboxed in
> some way. These include directives can provide surprising changes to
> behavior, especially when expecting a specific list of allowed file
> accesses. This could lead to failed builds, for instance.
> 
> To allow for these user-desired features when they are running commands,
> add a new GIT_CONFIG_INCLUDES environment variable that disables these
> redirections of config when set to zero. This variable can be set by
> automation, such as build tooling, to avoid these strange behaviors.
> This could be considered a recommended option for tools executing Git
> commands, the same as GIT_ADVICE=0.

I don't know about this part though. I could see use cases where the
tools _should_ read the project-relative configuration. It might also be
the case that the user may want to evaluate some includes, but not all
of them.

That raises the question whether we can introduce the configuration in a
way that it allows a bit more flexibility than just "yes"/"no", like for
example an allow-list of locations that should be evaluated. But maybe
I'm overthinking this.

Patrick

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented Jun 8, 2026

User Patrick Steinhardt <ps@pks.im> has been added to the cc: list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant