[PATCH 0/3] Add hostname condition to includeIf
- From
- Isabella Caselli <bellacaselli20@gmail.com>
- Date
- Oct 12, 2026, 01:58 UTC
- Message-ID
- <20261012015846.2649843-1-bellacaselli20@gmail.com>
- In-Reply-To
- <CAK4AdTSnaAOk649a0GLe1M9C+cYuDa0Nwo54=HT47R53Q4ZdWw@mail.gmail.com>
This series adds a "hostname:" condition to includeIf, allowing a configuration file to be included only on machines whose hostname matches a pattern. It also adds GIT_HOSTNAME to "git var", so users can see which hostname Git uses for matching.
The series is based on Ignacio Encinas's v3 from March 2024 [1]. Ignacio dropped the series and agreed to let me give it a try, so I am sending it as a new series. The "hostname:" patch retains his work and credits him with Based-on-patch-by.
Changes since Ignacio's v3:
- Drop "test-tool xgethostname". Eric pointed out that exposing the hostname to users would make the helper unnecessary, and suggested adding GIT_HOSTNAME to "git var", which I agree is the best way to make this information available to users. Patch 1 adds it, and the tests use it instead of the helper.
- Make "git var -l" omit GIT_HOSTNAME when the hostname cannot be determined, rather than failing, as Jeff suggested.
- Make t6500 use "git var GIT_HOSTNAME || echo unknown", as Jeff suggested and Junio agreed.
- Document that the hostname may be short or fully qualified, using Jeff's proposed wording, and point to "git var GIT_HOSTNAME" instead of gethostname(2), which Eric noted would not be helpful to users.
- Use xmemdupz() in include_by_hostname(), as Jeff suggested.
- In t1305, read the hostname into a variable before each here-document, so that failures are not silently ignored, as Junio pointed out.
One open question is case sensitivity. Matching is case-sensitive, like "onbranch:", so "hostname:MyHost" would not match a machine that reports "myhost", even though DNS names are case-insensitive. Keeping it case-sensitive seems reasonable to me, but I was not sure. Should it stay as is, ignore case, or have a "hostname/i:" variant, like "gitdir/i:"?
[1] https://lore.kernel.org/git/20240319183722.211300-1-ignacio@iencinas.com/
Isabella Caselli (3): var: add GIT_HOSTNAME t6500: get hostname from "git var" config: learn the "hostname:" includeIf condition
Documentation/config.adoc | 14 ++++++++++++ Documentation/git-var.adoc | 5 +++++ builtin/var.c | 13 +++++++++++ config.c | 17 +++++++++++++++ t/t0007-git-var.sh | 5 +++++ t/t1305-config-include.sh | 44 ++++++++++++++++++++++++++++++++++++++ t/t6500-gc.sh | 2 +- 7 files changed, 99 insertions(+), 1 deletion(-)
base-commit: 5a7d1e8045ce66c908f62598e26cbb8df7b39a90
-- 2.43.0