{"thread":{"id":"66414","subject":"hostname: includeIf condition — anyone already working on this?","startedAt":"2026-09-28T23:44:04Z","lastAt":"2026-10-15T19:32:40Z","messageCount":20,"participants":["Isabella Caselli","Jeff King","Ignacio Encinas","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"553531","messageId":"CAK4AdTRdNEU8cLFQ_7A=CUUL6u6dc327rn_H-SeBBD_dD-K7PA@mail.gmail.com","threadId":"66414","inReplyTo":null,"subject":"hostname: includeIf condition — anyone already working on this?","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-09-28T23:43:49Z","receivedAt":"2026-09-28T23:44:04Z","isPatch":false,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"Hi all,\n\nI'm looking for a small, relatively simple first contribution to Git\nas part of an undergraduate thesis on community/contribution barriers,\nand I'd like to work on the \"hostname:\" includeIf condition requested\nin gitgitgadget/git#1665 [1]: matching includeIf on the machine's\nhostname, mainly for sharing dotfiles across machines, e.g.:\n\n    [includeIf \"hostname:laptop\"]\n        path = ~/.gitconfig-laptop\n\nI found a related proposal from 2022 for an includeIf condition based\non the operating system [2], which stalled over disagreements about\nnaming and case sensitivity. My understanding is that \"hostname:\" is a\nnarrower, separate condition (machine identity, not platform), so I\ndon't think it needs to revisit that discussion, but I wanted to check\nbefore starting:\n\n- Is it still relevant for the project?\n   - If yes, is anyone already working on this issue?\n- Any objection to the approach itself? The same machine can report\nits hostname differently depending on how it's set up — sometimes just\nthe short name, sometimes with the full network address attached to it\n— so it isn't obvious whether the condition should compare that value\nexactly as the system reports it, or normalize it somehow before\ncomparing.\n\nIf nobody is on it, I'll put together a small patch modeled on the\nexisting onbranch: condition (dispatch in config.c, tests in\nt1305-config-include.sh, docs in config.adoc).\n\nThanks,\nIsabella Caselli\n[1] https://github.com/gitgitgadget/git/issues/1665\n[2] https://patchwork.kernel.org/project/git/patch/pull.1429.v2.git.1669058388327.gitgitgadget@gmail.com/\n"},{"id":"553534","messageId":"20260929014415.GB1089022@coredump.intra.peff.net","threadId":"66414","inReplyTo":"CAK4AdTRdNEU8cLFQ_7A=CUUL6u6dc327rn_H-SeBBD_dD-K7PA@mail.gmail.com","subject":"Re: hostname: includeIf condition — anyone already working on this?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2026-09-29T01:44:15Z","receivedAt":"2026-09-29T01:44:17Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Sep 28, 2026 at 08:43:49PM -0300, Isabella Caselli wrote:\n\n> I found a related proposal from 2022 for an includeIf condition based\n> on the operating system [2], which stalled over disagreements about\n> naming and case sensitivity. My understanding is that \"hostname:\" is a\n> narrower, separate condition (machine identity, not platform), so I\n> don't think it needs to revisit that discussion, but I wanted to check\n> before starting:\n> \n> - Is it still relevant for the project?\n>    - If yes, is anyone already working on this issue?\n\nI think it's a reasonable feature to have. I don't recall seeing anybody\nelse work on it recently (and a quick search of the list archive\nconfirms).\n\nBut see below.\n\n> - Any objection to the approach itself? The same machine can report\n> its hostname differently depending on how it's set up — sometimes just\n> the short name, sometimes with the full network address attached to it\n> — so it isn't obvious whether the condition should compare that value\n> exactly as the system reports it, or normalize it somehow before\n> comparing.\n\nYes, that is the tricky part. :) There were some patches in 2024:\n\n  https://lore.kernel.org/git/20240307205006.467443-1-ignacio@iencinas.com/\n\nwhere the issue came up. Based on my recollection and a quick skim of\nthe thread, I think the consensus was that it's OK to document that it\nis system-dependent whether we'll match against a short of fully\nqualified hostname. But exposing our view of the hostname via git-var\n(e.g., \"git var GIT_HOSTNAME\") might be a helpful debugging aid.\n\nIt looks like after review on v3 of the series we never saw more. I'd\nguess the author (cc'd) just never got around to pushing it forward.\n\n-Peff\n"},{"id":"553593","messageId":"DLRSIZ3JV2DF.10GG1YB2D8DHW@iencinas.com","threadId":"66414","inReplyTo":"20260929014415.GB1089022@coredump.intra.peff.net","subject":"Re: hostname: includeIf condition — anyone already working on this?","fromName":"Ignacio Encinas","fromEmail":"ignacio@iencinas.com","sentAt":"2026-09-29T12:14:34Z","receivedAt":"2026-09-29T12:14:48Z","isPatch":false,"sender":{"key":"ignacio@iencinas.com","avatar":null},"body":"Hello,\n\nOn Tue Sep 29, 2026 at 2:44 AM IST, Jeff King wrote:\n> On Mon, Sep 28, 2026 at 08:43:49PM -0300, Isabella Caselli wrote:\n>\n>> - Any objection to the approach itself? The same machine can report\n>> its hostname differently depending on how it's set up — sometimes just\n>> the short name, sometimes with the full network address attached to it\n>> — so it isn't obvious whether the condition should compare that value\n>> exactly as the system reports it, or normalize it somehow before\n>> comparing.\n>\n> Yes, that is the tricky part. :) There were some patches in 2024:\n>\n>   https://lore.kernel.org/git/20240307205006.467443-1-ignacio@iencinas.com/\n>\n> where the issue came up. Based on my recollection and a quick skim of\n> the thread, I think the consensus was that it's OK to document that it\n> is system-dependent whether we'll match against a short of fully\n> qualified hostname. But exposing our view of the hostname via git-var\n> (e.g., \"git var GIT_HOSTNAME\") might be a helpful debugging aid.\n>\n> It looks like after review on v3 of the series we never saw more. I'd\n> guess the author (cc'd) just never got around to pushing it forward.\n\nThat's what happened. Similar to Isabella, I was looking for a small\ncontribution but it ended up being more complicated than expected. I got\na bit overwhelmed and decided to drop it.\n\nI kept wondering if I should have communicated that, so apologies if\nthat was the case.\n\nI hope the discussion from 2024 is at least helpful now if this ends up\nbeing implemented by Isabella.\n\nBest regards,\nIgnacio\n"},{"id":"553625","messageId":"20260929182850.GB1710046@coredump.intra.peff.net","threadId":"66414","inReplyTo":"DLRSIZ3JV2DF.10GG1YB2D8DHW@iencinas.com","subject":"Re: hostname: includeIf condition — anyone already working on this?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2026-09-29T18:28:50Z","receivedAt":"2026-09-29T18:28:51Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Sep 29, 2026 at 01:14:34PM +0100, Ignacio Encinas wrote:\n\n> > Yes, that is the tricky part. :) There were some patches in 2024:\n> >\n> >   https://lore.kernel.org/git/20240307205006.467443-1-ignacio@iencinas.com/\n> >\n> > where the issue came up. Based on my recollection and a quick skim of\n> > the thread, I think the consensus was that it's OK to document that it\n> > is system-dependent whether we'll match against a short of fully\n> > qualified hostname. But exposing our view of the hostname via git-var\n> > (e.g., \"git var GIT_HOSTNAME\") might be a helpful debugging aid.\n> >\n> > It looks like after review on v3 of the series we never saw more. I'd\n> > guess the author (cc'd) just never got around to pushing it forward.\n> \n> That's what happened. Similar to Isabella, I was looking for a small\n> contribution but it ended up being more complicated than expected. I got\n> a bit overwhelmed and decided to drop it.\n> \n> I kept wondering if I should have communicated that, so apologies if\n> that was the case.\n\nNah, it's not a big deal. This is open source, so everybody is here\nvoluntarily, and it's normal for people to come in and out as time and\ninterest permits. Plus the very reason that people end up dropping a\nseries (getting overwhelmed) often makes it hard to decide whether and\nwhen to write the \"I'm dropping this\" email. :)\n\n> I hope the discussion from 2024 is at least helpful now if this ends up\n> being implemented by Isabella.\n\nYeah, I think there's a lot of good discussion there, and the patches\nthemselves can probably give a boost to another attempt. Even if we did\nnot finish it back then, thank you for the work so far.\n\n-Peff\n"},{"id":"553636","messageId":"xmqqa4ozg7dk.fsf@gitster.g","threadId":"66414","inReplyTo":"DLRSIZ3JV2DF.10GG1YB2D8DHW@iencinas.com","subject":"Re: hostname: includeIf condition — anyone already working on this?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-09-29T19:55:19Z","receivedAt":"2026-09-29T19:55:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ignacio Encinas\" <ignacio@iencinas.com> writes:\n\n> On Tue Sep 29, 2026 at 2:44 AM IST, Jeff King wrote:\n> ...\n>> It looks like after review on v3 of the series we never saw more. I'd\n>> guess the author (cc'd) just never got around to pushing it forward.\n>\n> That's what happened. Similar to Isabella, I was looking for a small\n> contribution but it ended up being more complicated than expected. I got\n> a bit overwhelmed and decided to drop it.\n> ...\n> I hope the discussion from 2024 is at least helpful now if this ends up\n> being implemented by Isabella.\n\nI was re-reading the thread yesterday.  It looked like we were _so_\nclose to the finish line before the discussion stopped, which is a\nshame.  All the good bits were already designed and the only thing\nleft was to assemble and package them up.\n"},{"id":"553882","messageId":"CAK4AdTSnaAOk649a0GLe1M9C+cYuDa0Nwo54=HT47R53Q4ZdWw@mail.gmail.com","threadId":"66414","inReplyTo":"xmqqa4ozg7dk.fsf@gitster.g","subject":"Re: hostname: includeIf condition — anyone already working on this?","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-10-02T01:52:18Z","receivedAt":"2026-10-02T01:52:31Z","isPatch":false,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"Interesting, I didn't know there had already been a discussion\nabout this issue. Thank you, Jeff, for pointing me to the 2024 series.\n\nJunio C Hamano <gitster@pobox.com> writes:\n\n> \"Ignacio Encinas\" <ignacio@iencinas.com> writes:\n>\n>> That's what happened. Similar to Isabella, I was looking for a small\n>> contribution but it ended up being more complicated than expected. I got\n>> a bit overwhelmed and decided to drop it.\n>> ...\n>> I hope the discussion from 2024 is at least helpful now if this ends up\n>> being implemented by Isabella.\n\nIgnacio, if you don't mind, I'd like to continue the work based on\nyours and credit you when submitting the series.\n\n> I was re-reading the thread yesterday.  It looked like we were _so_\n> close to the finish line before the discussion stopped, which is a\n> shame.  All the good bits were already designed and the only thing\n> left was to assemble and package them up.\n\nThat's encouraging to hear! Sounds like a plan to go through the 2024\nthread, including Jeff's suggestion of exposing the hostname via \"git var\",\nand send an updated version of the series addressing the comments on v3.\n\nThanks,\nIsabella\n"},{"id":"554733","messageId":"20261012015846.2649843-1-bellacaselli20@gmail.com","threadId":"66414","inReplyTo":"CAK4AdTSnaAOk649a0GLe1M9C+cYuDa0Nwo54=HT47R53Q4ZdWw@mail.gmail.com","subject":"[PATCH 0/3] Add hostname condition to includeIf","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-10-12T01:58:43Z","receivedAt":"2026-10-12T01:58:43Z","isPatch":true,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"This series adds a \"hostname:\" condition to includeIf, allowing a\nconfiguration file to be included only on machines whose hostname\nmatches a pattern. It also adds GIT_HOSTNAME to \"git var\", so users\ncan see which hostname Git uses for matching.\n\nThe series is based on Ignacio Encinas's v3 from March 2024 [1].\nIgnacio dropped the series and agreed to let me give it a try,\nso I am sending it as a new series.\nThe \"hostname:\" patch retains his work and credits him with\nBased-on-patch-by.\n\nChanges since Ignacio's v3:\n\n - Drop \"test-tool xgethostname\". Eric pointed out that exposing the\n   hostname to users would make the helper unnecessary, and suggested\n   adding GIT_HOSTNAME to \"git var\", which I agree is the best way to\n   make this information available to users. Patch 1 adds it, and the\n   tests use it instead of the helper.\n\n - Make \"git var -l\" omit GIT_HOSTNAME when the hostname cannot be\n   determined, rather than failing, as Jeff suggested.\n\n - Make t6500 use \"git var GIT_HOSTNAME || echo unknown\", as Jeff\n   suggested and Junio agreed.\n\n - Document that the hostname may be short or fully qualified, using\n   Jeff's proposed wording, and point to \"git var GIT_HOSTNAME\"\n   instead of gethostname(2), which Eric noted would not be helpful\n   to users.\n\n - Use xmemdupz() in include_by_hostname(), as Jeff suggested.\n\n - In t1305, read the hostname into a variable before each\n   here-document, so that failures are not silently ignored, as\n   Junio pointed out.\n\nOne open question is case sensitivity. Matching is case-sensitive,\nlike \"onbranch:\", so \"hostname:MyHost\" would not match a machine that\nreports \"myhost\", even though DNS names are case-insensitive. Keeping\nit case-sensitive seems reasonable to me, but I was not sure. Should\nit stay as is, ignore case, or have a \"hostname/i:\" variant, like\n\"gitdir/i:\"?\n\n[1] https://lore.kernel.org/git/20240319183722.211300-1-ignacio@iencinas.com/\n\nIsabella Caselli (3):\n  var: add GIT_HOSTNAME\n  t6500: get hostname from \"git var\"\n  config: learn the \"hostname:\" includeIf condition\n\n Documentation/config.adoc  | 14 ++++++++++++\n Documentation/git-var.adoc |  5 +++++\n builtin/var.c              | 13 +++++++++++\n config.c                   | 17 +++++++++++++++\n t/t0007-git-var.sh         |  5 +++++\n t/t1305-config-include.sh  | 44 ++++++++++++++++++++++++++++++++++++++\n t/t6500-gc.sh              |  2 +-\n 7 files changed, 99 insertions(+), 1 deletion(-)\n\n\nbase-commit: 5a7d1e8045ce66c908f62598e26cbb8df7b39a90\n-- \n2.43.0\n\n\n"},{"id":"554734","messageId":"20261012015846.2649843-2-bellacaselli20@gmail.com","threadId":"66414","inReplyTo":"20261012015846.2649843-1-bellacaselli20@gmail.com","subject":"[PATCH 1/3] var: add GIT_HOSTNAME","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-10-12T01:58:44Z","receivedAt":"2026-10-12T01:58:44Z","isPatch":true,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"Git asks the system for the name of the machine it runs on in a few\nplaces. For example, \"git gc\" records it in \"gc.pid\" to tell whether\nthe gc holding the lock runs on the same machine. Users have no way\nto see which name Git uses, and depending on how the system is\nconfigured, it may be a short name (\"myhost\") or a fully qualified\none (\"myhost.example.com\").\n\nThis matters more once the config can depend on the hostname, which\na later commit adds as an includeIf condition. Without a way to see\nthe value Git uses, users would have to guess what to write in their\nconfig file.\n\nAdd a GIT_HOSTNAME variable to \"git var\" that prints the hostname\nGit sees. If the hostname can't be determined, \"git var GIT_HOSTNAME\"\nexits with a non-zero status, and \"git var -l\" omits the variable\ninstead of failing.\n\nAn option to \"git config\" to show the hostname was also discussed,\nbut \"git var\" was chosen, since the hostname is not specific to\nthe configuration code.\n\nThe test only checks that a non-empty value is printed. The test has\nno independent way to know the expected hostname, as the \"hostname\"\ncommand may not agree with what Git sees on every platform. The\nincludeIf tests added later check that the value matches what the\nconfiguration code uses.\n\nSuggested-by: Eric Sunshine <sunshine@sunshineco.com>\nSuggested-by: Jeff King <peff@peff.net>\nSigned-off-by: Isabella Caselli <bellacaselli20@gmail.com>\n---\n Documentation/git-var.adoc |  3 +++\n builtin/var.c              | 13 +++++++++++++\n t/t0007-git-var.sh         |  5 +++++\n 3 files changed, 21 insertions(+)\n\ndiff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc\nindex 697c10aded..e813ab4fd2 100644\n--- a/Documentation/git-var.adoc\n+++ b/Documentation/git-var.adoc\n@@ -84,6 +84,9 @@ endif::git-default-pager[]\n `GIT_CONFIG_GLOBAL`::\n     The path to the global (per-user) configuration files, if any.\n \n+`GIT_HOSTNAME`::\n+    The hostname of the machine, as reported by the operating system.\n+\n Most path values contain only one value. However, some can contain multiple\n values, which are separated by newlines, and are listed in order from highest to\n lowest priority.  Callers should be prepared for any such path value to contain\ndiff --git a/builtin/var.c b/builtin/var.c\nindex cc3a43cde2..b427ebd61e 100644\n--- a/builtin/var.c\n+++ b/builtin/var.c\n@@ -115,6 +115,15 @@ static char *git_config_val_global(int ident_flag UNUSED)\n \treturn strbuf_detach(&buf, &unused);\n }\n \n+static char *hostname(int ident_flag UNUSED)\n+{\n+\tchar buf[HOST_NAME_MAX + 1];\n+\n+\tif (xgethostname(buf, sizeof(buf)))\n+\t\treturn NULL;\n+\treturn xstrdup(buf);\n+}\n+\n struct git_var {\n \tconst char *name;\n \tchar *(*read)(int);\n@@ -166,6 +175,10 @@ static struct git_var git_vars[] = {\n \t\t.read = git_config_val_global,\n \t\t.multivalued = 1,\n \t},\n+\t{\n+\t\t.name = \"GIT_HOSTNAME\",\n+\t\t.read = hostname,\n+\t},\n \t{\n \t\t.name = \"\",\n \t\t.read = NULL,\ndiff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh\nindex 2b60317758..f50c62a25e 100755\n--- a/t/t0007-git-var.sh\n+++ b/t/t0007-git-var.sh\n@@ -224,6 +224,11 @@ test_expect_success 'GIT_CONFIG_GLOBAL points to the correct location' '\n \t)\n '\n \n+test_expect_success 'GIT_HOSTNAME is not empty' '\n+\thostname=$(git var GIT_HOSTNAME) &&\n+\ttest -n \"$hostname\"\n+'\n+\n # For git var -l, we check only a representative variable;\n # testing the whole output would make our test too brittle with\n # respect to unrelated changes in the test suite's environment.\n-- \n2.43.0\n\n\n"},{"id":"554735","messageId":"20261012015846.2649843-3-bellacaselli20@gmail.com","threadId":"66414","inReplyTo":"20261012015846.2649843-1-bellacaselli20@gmail.com","subject":"[PATCH 2/3] t6500: get hostname from \"git var\"","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-10-12T01:58:45Z","receivedAt":"2026-10-12T01:58:45Z","isPatch":true,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"The test \"background auto gc respects lock for all operations\" simulates\na concurrent gc by writing our shell's pid and hostname to \"gc.pid\".\nIt gets the hostname from the \"hostname\" command, falling back to\n\"unknown\" if the command fails.\n\n\"git gc\" gets its hostname from the system and only checks whether the\npid is alive if the two hostnames match. Otherwise, it assumes the\nlock belongs to a gc running on another machine. Since the test passes\nin either case, a missing \"hostname\" command or a mismatch between\nits output and the system hostname can cause the test to silently\nexercise the wrong case.\n\nUse \"git var GIT_HOSTNAME\" to get the same hostname as \"git gc\".\nKeep the \"unknown\" fallback, which is also used by \"git gc\" when it\ncannot determine the hostname.\n\nHelped-by: Jeff King <peff@peff.net>\nSigned-off-by: Isabella Caselli <bellacaselli20@gmail.com>\n---\n t/t6500-gc.sh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/t/t6500-gc.sh b/t/t6500-gc.sh\nindex a7142ab815..f928089bf0 100755\n--- a/t/t6500-gc.sh\n+++ b/t/t6500-gc.sh\n@@ -413,7 +413,7 @@ test_expect_success 'background auto gc respects lock for all operations' '\n \n \t# now fake a concurrent gc that holds the lock; we can use our\n \t# shell pid so that it looks valid.\n-\thostname=$(hostname || echo unknown) &&\n+\thostname=$(git var GIT_HOSTNAME || echo unknown) &&\n \tshell_pid=$$ &&\n \tif test_have_prereq MINGW && test -f /proc/$shell_pid/winpid\n \tthen\n-- \n2.43.0\n\n\n"},{"id":"554736","messageId":"20261012015846.2649843-4-bellacaselli20@gmail.com","threadId":"66414","inReplyTo":"20261012015846.2649843-1-bellacaselli20@gmail.com","subject":"[PATCH 3/3] config: learn the \"hostname:\" includeIf condition","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-10-12T01:58:46Z","receivedAt":"2026-10-12T01:58:46Z","isPatch":true,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"When the same home directory is shared across multiple machines, they\nall read the same ~/.gitconfig. Settings that should differ between\nmachines therefore need a way to make that file behave differently\non each host. The same problem affects people who keep their dotfiles\nin a repository and check them out on multiple machines.\n\nAdd a \"hostname:\" keyword to includeIf. The value that follows is a\npattern supporting standard glob wildcards, and the condition is met\nwhen the machine's hostname matches it. If the hostname cannot be\ndetermined, the condition is not met.\n\nDepending on the system configuration, the hostname may be either a\nshort name or a fully qualified domain name. Making the name fully\nqualified ourselves was considered, but it could require a DNS lookup\nwhile reading the configuration. Instead, match the name as the\nsystem reports it, document this, and point to \"git var GIT_HOSTNAME\"\nas a way to check the value being matched.\n\nThe tests obtain the hostname with \"git var GIT_HOSTNAME\" before\nwriting the configuration, so that a failure to retrieve it makes\nthe test fail instead of going unnoticed inside the here-document.\n\nBased-on-patch-by: Ignacio Encinas <ignacio@iencinas.com>\nSigned-off-by: Isabella Caselli <bellacaselli20@gmail.com>\n---\n Documentation/config.adoc  | 14 ++++++++++++\n Documentation/git-var.adoc |  2 ++\n config.c                   | 17 +++++++++++++++\n t/t1305-config-include.sh  | 44 ++++++++++++++++++++++++++++++++++++++\n 4 files changed, 77 insertions(+)\n\ndiff --git a/Documentation/config.adoc b/Documentation/config.adoc\nindex f67dcd2f8e..aa6360e230 100644\n--- a/Documentation/config.adoc\n+++ b/Documentation/config.adoc\n@@ -232,6 +232,16 @@ As for the naming of this keyword, it is for forwards compatibility with\n a naming scheme that supports more variable-based include conditions,\n but currently Git only supports the exact keyword described above.\n \n+`hostname`::\n+\tThe data that follows the keyword `hostname:` is taken to be a\n+\tpattern with standard globbing wildcards. If the hostname of\n+\tthe machine matches the pattern, the include condition is met.\n++\n+Depending on how your system is configured, the hostname used for\n+matching may be short (e.g., \"myhost\") or a fully qualified domain\n+name (\"myhost.example.com\"). Run `git var GIT_HOSTNAME` to see the\n+hostname Git uses (see linkgit:git-var[1]).\n+\n A few more notes on matching via `gitdir` and `gitdir/i`:\n \n  * Symlinks in `$GIT_DIR` are not resolved before matching.\n@@ -315,6 +325,10 @@ Example\n \tpath = foo.inc\n [remote \"origin\"]\n \turl = https://example.com/git\n+\n+; include only if the hostname of the machine matches some-hostname\n+[includeIf \"hostname:some-hostname\"]\n+\tpath = foo.inc\n ----\n \n Values\ndiff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc\nindex e813ab4fd2..fc2def16d3 100644\n--- a/Documentation/git-var.adoc\n+++ b/Documentation/git-var.adoc\n@@ -86,6 +86,8 @@ endif::git-default-pager[]\n \n `GIT_HOSTNAME`::\n     The hostname of the machine, as reported by the operating system.\n+    This is the hostname matched by `includeIf \"hostname:...\"` (see\n+    linkgit:git-config[1]).\n \n Most path values contain only one value. However, some can contain multiple\n values, which are separated by newlines, and are listed in order from highest to\ndiff --git a/config.c b/config.c\nindex e0bb29b53d..c891f63e60 100644\n--- a/config.c\n+++ b/config.c\n@@ -316,6 +316,21 @@ static int include_by_branch(struct config_include_data *data,\n \treturn ret;\n }\n \n+static int include_by_hostname(const char *cond, size_t cond_len)\n+{\n+\tint ret;\n+\tchar my_host[HOST_NAME_MAX + 1];\n+\tchar *pattern;\n+\n+\tif (xgethostname(my_host, sizeof(my_host)))\n+\t\treturn 0;\n+\n+\tpattern = xmemdupz(cond, cond_len);\n+\tret = !wildmatch(pattern, my_host, 0);\n+\tfree(pattern);\n+\treturn ret;\n+}\n+\n static int add_remote_url(const char *var, const char *value,\n \t\t\t  const struct config_context *ctx UNUSED, void *data)\n {\n@@ -411,6 +426,8 @@ static int include_condition_is_true(const struct key_value_info *kvi,\n \telse if (skip_prefix_mem(cond, cond_len, \"hasconfig:remote.*.url:\", &cond,\n \t\t\t\t   &cond_len))\n \t\treturn include_by_remote_url(inc, cond, cond_len);\n+\telse if (skip_prefix_mem(cond, cond_len, \"hostname:\", &cond, &cond_len))\n+\t\treturn include_by_hostname(cond, cond_len);\n \n \t/* unknown conditionals are always false */\n \treturn 0;\ndiff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh\nindex 507b8ebd06..01069237ba 100755\n--- a/t/t1305-config-include.sh\n+++ b/t/t1305-config-include.sh\n@@ -524,4 +524,48 @@ test_expect_success 'conditional include, worktree without repository but explic\n \ttest_must_fail nongit git --git-dir=nonexistent config get foo.bar\n '\n \n+test_expect_success 'conditional include, hostname' '\n+\thostname=$(git var GIT_HOSTNAME) &&\n+\tcat >>.git/config <<-EOF &&\n+\t[includeIf \"hostname:${hostname}a\"]\n+\t\tpath = bar12\n+\tEOF\n+\tcat >>.git/bar12 <<-EOF &&\n+\t[test]\n+\t\ttwelve=12\n+\tEOF\n+\n+\ttest_must_fail git config test.twelve &&\n+\n+\tcat >>.git/config <<-EOF &&\n+\t[includeIf \"hostname:$hostname\"]\n+\t\tpath = bar12\n+\tEOF\n+\techo 12 >expect &&\n+\tgit config test.twelve >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'conditional include, hostname, wildcard' '\n+\thostname=$(git var GIT_HOSTNAME) &&\n+\tcat >>.git/config <<-EOF &&\n+\t[includeIf \"hostname:${hostname}a*\"]\n+\t\tpath = bar13\n+\tEOF\n+\tcat >>.git/bar13 <<-EOF &&\n+\t[test]\n+\t\tthirteen = 13\n+\tEOF\n+\n+\ttest_must_fail git config test.thirteen &&\n+\n+\tcat >>.git/config <<-EOF &&\n+\t[includeIf \"hostname:$hostname*\"]\n+\t\tpath = bar13\n+\tEOF\n+\techo 13 >expect &&\n+\tgit config test.thirteen >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.43.0\n\n\n"},{"id":"554800","messageId":"xmqqecdu67zq.fsf@gitster.g","threadId":"66414","inReplyTo":"20261012015846.2649843-3-bellacaselli20@gmail.com","subject":"Re: [PATCH 2/3] t6500: get hostname from \"git var\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-12T19:20:41Z","receivedAt":"2026-10-12T19:20:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Isabella Caselli <bellacaselli20@gmail.com> writes:\n\n> The test \"background auto gc respects lock for all operations\" simulates\n> a concurrent gc by writing our shell's pid and hostname to \"gc.pid\".\n> It gets the hostname from the \"hostname\" command, falling back to\n> \"unknown\" if the command fails.\n>\n> \"git gc\" gets its hostname from the system and only checks whether the\n> pid is alive if the two hostnames match. Otherwise, it assumes the\n> lock belongs to a gc running on another machine. Since the test passes\n> in either case, a missing \"hostname\" command or a mismatch between\n> its output and the system hostname can cause the test to silently\n> exercise the wrong case.\n\n\"exercise the wrong case\", meaning...  where hostname(1) output is\ndifferent from \"git var GIT_HOSTNAME\" (aka xgethostname()), we would\nhave written bogus name in .git/gc.pid file, simulating the case where\ngc.pid was written by a process running on a different machine.\n\nWhat is the implications of doing so?\n>\n> Use \"git var GIT_HOSTNAME\" to get the same hostname as \"git gc\".\n> Keep the \"unknown\" fallback, which is also used by \"git gc\" when it\n> cannot determine the hostname.\n>\n> Helped-by: Jeff King <peff@peff.net>\n> Signed-off-by: Isabella Caselli <bellacaselli20@gmail.com>\n> ---\n>  t/t6500-gc.sh | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh\n> index a7142ab815..f928089bf0 100755\n> --- a/t/t6500-gc.sh\n> +++ b/t/t6500-gc.sh\n> @@ -413,7 +413,7 @@ test_expect_success 'background auto gc respects lock for all operations' '\n>  \n>  \t# now fake a concurrent gc that holds the lock; we can use our\n>  \t# shell pid so that it looks valid.\n> -\thostname=$(hostname || echo unknown) &&\n> +\thostname=$(git var GIT_HOSTNAME || echo unknown) &&\n>  \tshell_pid=$$ &&\n>  \tif test_have_prereq MINGW && test -f /proc/$shell_pid/winpid\n>  \tthen\n\n"},{"id":"554802","messageId":"xmqqa4oi67tx.fsf@gitster.g","threadId":"66414","inReplyTo":"20261012015846.2649843-4-bellacaselli20@gmail.com","subject":"Re: [PATCH 3/3] config: learn the \"hostname:\" includeIf condition","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-12T19:24:10Z","receivedAt":"2026-10-12T19:24:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Isabella Caselli <bellacaselli20@gmail.com> writes:\n\n> +static int include_by_hostname(const char *cond, size_t cond_len)\n> +{\n> +\tint ret;\n> +\tchar my_host[HOST_NAME_MAX + 1];\n> +\tchar *pattern;\n> +\n> +\tif (xgethostname(my_host, sizeof(my_host)))\n> +\t\treturn 0;\n> +\n> +\tpattern = xmemdupz(cond, cond_len);\n> +\tret = !wildmatch(pattern, my_host, 0);\n> +\tfree(pattern);\n> +\treturn ret;\n> +}\n> +\n>  static int add_remote_url(const char *var, const char *value,\n>  \t\t\t  const struct config_context *ctx UNUSED, void *data)\n>  {\n> @@ -411,6 +426,8 @@ static int include_condition_is_true(const struct key_value_info *kvi,\n>  \telse if (skip_prefix_mem(cond, cond_len, \"hasconfig:remote.*.url:\", &cond,\n>  \t\t\t\t   &cond_len))\n>  \t\treturn include_by_remote_url(inc, cond, cond_len);\n> +\telse if (skip_prefix_mem(cond, cond_len, \"hostname:\", &cond, &cond_len))\n> +\t\treturn include_by_hostname(cond, cond_len);\n\nNeat.  With this include_condition_is_true() helper, adding such\nconditional inclusion is made very easy.  Quite nice.\n\n\n"},{"id":"554820","messageId":"CAK4AdTQNqp_B3kp_Be=2pLuX0bSfK_v59_AP5kHwh2YmfHYo_w@mail.gmail.com","threadId":"66414","inReplyTo":"xmqqecdu67zq.fsf@gitster.g","subject":"Re: [PATCH 2/3] t6500: get hostname from \"git var\"","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-10-13T01:14:57Z","receivedAt":"2026-10-13T01:14:57Z","isPatch":true,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> \"exercise the wrong case\", meaning...  where hostname(1) output is\n> different from \"git var GIT_HOSTNAME\" (aka xgethostname()), we would\n> have written bogus name in .git/gc.pid file, simulating the case where\n> gc.pid was written by a process running on a different machine.\n>\n> What is the implications of doing so?\n\nIf the hostnames differ, lock_repo_for_gc() assumes the lock belongs\nto a process on another machine. In that case, strcmp(locking_host,\nmy_host) is already true, so the remaining conditions are never\nevaluated, such as !kill(pid, 0).\nSo the test would still pass, but wouldn't actually check whether Git\ndetects that the pid belongs to a running process on the same machine,\nwhich is the behavior it is meant to verify.\n\nShould I adjust the commit message to clarify this?\n\n"},{"id":"554823","messageId":"xmqqecdu2x42.fsf@gitster.g","threadId":"66414","inReplyTo":"CAK4AdTQNqp_B3kp_Be=2pLuX0bSfK_v59_AP5kHwh2YmfHYo_w@mail.gmail.com","subject":"Re: [PATCH 2/3] t6500: get hostname from \"git var\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-13T01:43:57Z","receivedAt":"2026-10-13T01:43:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Isabella Caselli <bellacaselli20@gmail.com> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> \"exercise the wrong case\", meaning...  where hostname(1) output is\n>> different from \"git var GIT_HOSTNAME\" (aka xgethostname()), we would\n>> have written bogus name in .git/gc.pid file, simulating the case where\n>> gc.pid was written by a process running on a different machine.\n>>\n>> What is the implications of doing so?\n>\n> If the hostnames differ, lock_repo_for_gc() assumes the lock belongs\n> to a process on another machine. In that case, strcmp(locking_host,\n> my_host) is already true, so the remaining conditions are never\n> evaluated, such as !kill(pid, 0).\n> So the test would still pass, but wouldn't actually check whether Git\n> detects that the pid belongs to a running process on the same machine,\n> which is the behavior it is meant to verify.\n>\n> Should I adjust the commit message to clarify this?\n\nAbsolutely.  The only reason I asked was because I didn't understand\nwhat you wanted to say in the proposed log message, which means it\nis very likely other people would have difficulty reading \"git log\"\nif we committed it as-is.\n\nThanks.\n\n\n"},{"id":"554994","messageId":"20261014103118.GA1356555@coredump.intra.peff.net","threadId":"66414","inReplyTo":"20261012015846.2649843-1-bellacaselli20@gmail.com","subject":"Re: [PATCH 0/3] Add hostname condition to includeIf","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2026-10-14T10:31:18Z","receivedAt":"2026-10-14T10:31:18Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Oct 11, 2026 at 10:58:43PM -0300, Isabella Caselli wrote:\n\n> This series adds a \"hostname:\" condition to includeIf, allowing a\n> configuration file to be included only on machines whose hostname\n> matches a pattern. It also adds GIT_HOSTNAME to \"git var\", so users\n> can see which hostname Git uses for matching.\n> \n> The series is based on Ignacio Encinas's v3 from March 2024 [1].\n> Ignacio dropped the series and agreed to let me give it a try,\n> so I am sending it as a new series.\n> The \"hostname:\" patch retains his work and credits him with\n> Based-on-patch-by.\n> \n> Changes since Ignacio's v3:\n> [...]\n\nThanks for thoroughly collecting and including all of the review\nfeedback from the earlier round. I gave the series only a fairly cursory\nread, but I didn't see anything to complain about.\n\n-Peff\n\n"},{"id":"555133","messageId":"20261015105859.3184108-1-bellacaselli20@gmail.com","threadId":"66414","inReplyTo":"20261012015846.2649843-1-bellacaselli20@gmail.com","subject":"[PATCH v2 0/3] Add hostname condition to includeIf","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-10-15T10:58:56Z","receivedAt":"2026-10-15T10:58:56Z","isPatch":true,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"This series adds a \"hostname:\" condition to includeIf, allowing a\nconfiguration file to be included only on machines whose hostname\nmatches a pattern. It also adds GIT_HOSTNAME to \"git var\", so users\ncan see which hostname Git uses for matching.\n\nChanges since v1 [1]:\n\n - Rewrite the commit message of patch 2 to explain what the test\n   no longer verifies when the hostnames differ, as Junio asked.\n\n[1] https://lore.kernel.org/git/20261012015846.2649843-1-bellacaselli20@gmail.com/\n\nIsabella Caselli (3):\n  var: add GIT_HOSTNAME\n  t6500: get hostname from \"git var\"\n  config: learn the \"hostname:\" includeIf condition\n\n Documentation/config.adoc  | 14 ++++++++++++\n Documentation/git-var.adoc |  5 +++++\n builtin/var.c              | 13 +++++++++++\n config.c                   | 17 +++++++++++++++\n t/t0007-git-var.sh         |  5 +++++\n t/t1305-config-include.sh  | 44 ++++++++++++++++++++++++++++++++++++++\n t/t6500-gc.sh              |  2 +-\n 7 files changed, 99 insertions(+), 1 deletion(-)\n\nRange-diff against v1:\n1:  a34e1eb36f = 1:  7609601553 var: add GIT_HOSTNAME\n2:  c341ae75c0 ! 2:  cb1599c7ce t6500: get hostname from \"git var\"\n    @@ Commit message\n         It gets the hostname from the \"hostname\" command, falling back to\n         \"unknown\" if the command fails.\n     \n    -    \"git gc\" gets its hostname from the system and only checks whether the\n    -    pid is alive if the two hostnames match. Otherwise, it assumes the\n    -    lock belongs to a gc running on another machine. Since the test passes\n    -    in either case, a missing \"hostname\" command or a mismatch between\n    -    its output and the system hostname can cause the test to silently\n    -    exercise the wrong case.\n    +    \"git gc\" only checks whether the pid in \"gc.pid\" is alive if the\n    +    recorded hostname matches its own. If the hostnames differ, it assumes\n    +    the lock belongs to a gc running on another machine and skips the pid\n    +    check. Since the test passes in either case, it may pass without\n    +    checking whether \"git gc\" detects a running process on the same\n    +    machine.\n     \n         Use \"git var GIT_HOSTNAME\" to get the same hostname as \"git gc\".\n    -    Keep the \"unknown\" fallback, which is also used by \"git gc\" when it\n    -    cannot determine the hostname.\n    +    Keep the \"unknown\" fallback, which \"git gc\" also uses when it cannot\n    +    determine the hostname.\n     \n         Helped-by: Jeff King <peff@peff.net>\n         Signed-off-by: Isabella Caselli <bellacaselli20@gmail.com>\n3:  a1e4fc5ba3 = 3:  5a2bb2172a config: learn the \"hostname:\" includeIf condition\n\nbase-commit: 6de20f6092dcf9bdb1c8efe03db4b70c82b423dd\n-- \n2.43.0\n\n\n"},{"id":"555134","messageId":"20261015105859.3184108-2-bellacaselli20@gmail.com","threadId":"66414","inReplyTo":"20261015105859.3184108-1-bellacaselli20@gmail.com","subject":"[PATCH v2 1/3] var: add GIT_HOSTNAME","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-10-15T10:58:57Z","receivedAt":"2026-10-15T10:58:57Z","isPatch":true,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"Git asks the system for the name of the machine it runs on in a few\nplaces. For example, \"git gc\" records it in \"gc.pid\" to tell whether\nthe gc holding the lock runs on the same machine. Users have no way\nto see which name Git uses, and depending on how the system is\nconfigured, it may be a short name (\"myhost\") or a fully qualified\none (\"myhost.example.com\").\n\nThis matters more once the config can depend on the hostname, which\na later commit adds as an includeIf condition. Without a way to see\nthe value Git uses, users would have to guess what to write in their\nconfig file.\n\nAdd a GIT_HOSTNAME variable to \"git var\" that prints the hostname\nGit sees. If the hostname can't be determined, \"git var GIT_HOSTNAME\"\nexits with a non-zero status, and \"git var -l\" omits the variable\ninstead of failing.\n\nAn option to \"git config\" to show the hostname was also discussed,\nbut \"git var\" was chosen, since the hostname is not specific to\nthe configuration code.\n\nThe test only checks that a non-empty value is printed. The test has\nno independent way to know the expected hostname, as the \"hostname\"\ncommand may not agree with what Git sees on every platform. The\nincludeIf tests added later check that the value matches what the\nconfiguration code uses.\n\nSuggested-by: Eric Sunshine <sunshine@sunshineco.com>\nSuggested-by: Jeff King <peff@peff.net>\nSigned-off-by: Isabella Caselli <bellacaselli20@gmail.com>\n---\n Documentation/git-var.adoc |  3 +++\n builtin/var.c              | 13 +++++++++++++\n t/t0007-git-var.sh         |  5 +++++\n 3 files changed, 21 insertions(+)\n\ndiff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc\nindex 697c10aded..e813ab4fd2 100644\n--- a/Documentation/git-var.adoc\n+++ b/Documentation/git-var.adoc\n@@ -84,6 +84,9 @@ endif::git-default-pager[]\n `GIT_CONFIG_GLOBAL`::\n     The path to the global (per-user) configuration files, if any.\n \n+`GIT_HOSTNAME`::\n+    The hostname of the machine, as reported by the operating system.\n+\n Most path values contain only one value. However, some can contain multiple\n values, which are separated by newlines, and are listed in order from highest to\n lowest priority.  Callers should be prepared for any such path value to contain\ndiff --git a/builtin/var.c b/builtin/var.c\nindex cc3a43cde2..b427ebd61e 100644\n--- a/builtin/var.c\n+++ b/builtin/var.c\n@@ -115,6 +115,15 @@ static char *git_config_val_global(int ident_flag UNUSED)\n \treturn strbuf_detach(&buf, &unused);\n }\n \n+static char *hostname(int ident_flag UNUSED)\n+{\n+\tchar buf[HOST_NAME_MAX + 1];\n+\n+\tif (xgethostname(buf, sizeof(buf)))\n+\t\treturn NULL;\n+\treturn xstrdup(buf);\n+}\n+\n struct git_var {\n \tconst char *name;\n \tchar *(*read)(int);\n@@ -166,6 +175,10 @@ static struct git_var git_vars[] = {\n \t\t.read = git_config_val_global,\n \t\t.multivalued = 1,\n \t},\n+\t{\n+\t\t.name = \"GIT_HOSTNAME\",\n+\t\t.read = hostname,\n+\t},\n \t{\n \t\t.name = \"\",\n \t\t.read = NULL,\ndiff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh\nindex 2b60317758..f50c62a25e 100755\n--- a/t/t0007-git-var.sh\n+++ b/t/t0007-git-var.sh\n@@ -224,6 +224,11 @@ test_expect_success 'GIT_CONFIG_GLOBAL points to the correct location' '\n \t)\n '\n \n+test_expect_success 'GIT_HOSTNAME is not empty' '\n+\thostname=$(git var GIT_HOSTNAME) &&\n+\ttest -n \"$hostname\"\n+'\n+\n # For git var -l, we check only a representative variable;\n # testing the whole output would make our test too brittle with\n # respect to unrelated changes in the test suite's environment.\n-- \n2.43.0\n\n\n"},{"id":"555135","messageId":"20261015105859.3184108-3-bellacaselli20@gmail.com","threadId":"66414","inReplyTo":"20261015105859.3184108-1-bellacaselli20@gmail.com","subject":"[PATCH v2 2/3] t6500: get hostname from \"git var\"","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-10-15T10:58:58Z","receivedAt":"2026-10-15T10:58:58Z","isPatch":true,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"The test \"background auto gc respects lock for all operations\" simulates\na concurrent gc by writing our shell's pid and hostname to \"gc.pid\".\nIt gets the hostname from the \"hostname\" command, falling back to\n\"unknown\" if the command fails.\n\n\"git gc\" only checks whether the pid in \"gc.pid\" is alive if the\nrecorded hostname matches its own. If the hostnames differ, it assumes\nthe lock belongs to a gc running on another machine and skips the pid\ncheck. Since the test passes in either case, it may pass without\nchecking whether \"git gc\" detects a running process on the same\nmachine.\n\nUse \"git var GIT_HOSTNAME\" to get the same hostname as \"git gc\".\nKeep the \"unknown\" fallback, which \"git gc\" also uses when it cannot\ndetermine the hostname.\n\nHelped-by: Jeff King <peff@peff.net>\nSigned-off-by: Isabella Caselli <bellacaselli20@gmail.com>\n---\n t/t6500-gc.sh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/t/t6500-gc.sh b/t/t6500-gc.sh\nindex a7142ab815..f928089bf0 100755\n--- a/t/t6500-gc.sh\n+++ b/t/t6500-gc.sh\n@@ -413,7 +413,7 @@ test_expect_success 'background auto gc respects lock for all operations' '\n \n \t# now fake a concurrent gc that holds the lock; we can use our\n \t# shell pid so that it looks valid.\n-\thostname=$(hostname || echo unknown) &&\n+\thostname=$(git var GIT_HOSTNAME || echo unknown) &&\n \tshell_pid=$$ &&\n \tif test_have_prereq MINGW && test -f /proc/$shell_pid/winpid\n \tthen\n-- \n2.43.0\n\n\n"},{"id":"555136","messageId":"20261015105859.3184108-4-bellacaselli20@gmail.com","threadId":"66414","inReplyTo":"20261015105859.3184108-1-bellacaselli20@gmail.com","subject":"[PATCH v2 3/3] config: learn the \"hostname:\" includeIf condition","fromName":"Isabella Caselli","fromEmail":"bellacaselli20@gmail.com","sentAt":"2026-10-15T10:58:59Z","receivedAt":"2026-10-15T10:58:59Z","isPatch":true,"sender":{"key":"bellacaselli20@gmail.com","avatar":null},"body":"When the same home directory is shared across multiple machines, they\nall read the same ~/.gitconfig. Settings that should differ between\nmachines therefore need a way to make that file behave differently\non each host. The same problem affects people who keep their dotfiles\nin a repository and check them out on multiple machines.\n\nAdd a \"hostname:\" keyword to includeIf. The value that follows is a\npattern supporting standard glob wildcards, and the condition is met\nwhen the machine's hostname matches it. If the hostname cannot be\ndetermined, the condition is not met.\n\nDepending on the system configuration, the hostname may be either a\nshort name or a fully qualified domain name. Making the name fully\nqualified ourselves was considered, but it could require a DNS lookup\nwhile reading the configuration. Instead, match the name as the\nsystem reports it, document this, and point to \"git var GIT_HOSTNAME\"\nas a way to check the value being matched.\n\nThe tests obtain the hostname with \"git var GIT_HOSTNAME\" before\nwriting the configuration, so that a failure to retrieve it makes\nthe test fail instead of going unnoticed inside the here-document.\n\nBased-on-patch-by: Ignacio Encinas <ignacio@iencinas.com>\nSigned-off-by: Isabella Caselli <bellacaselli20@gmail.com>\n---\n Documentation/config.adoc  | 14 ++++++++++++\n Documentation/git-var.adoc |  2 ++\n config.c                   | 17 +++++++++++++++\n t/t1305-config-include.sh  | 44 ++++++++++++++++++++++++++++++++++++++\n 4 files changed, 77 insertions(+)\n\ndiff --git a/Documentation/config.adoc b/Documentation/config.adoc\nindex f67dcd2f8e..aa6360e230 100644\n--- a/Documentation/config.adoc\n+++ b/Documentation/config.adoc\n@@ -232,6 +232,16 @@ As for the naming of this keyword, it is for forwards compatibility with\n a naming scheme that supports more variable-based include conditions,\n but currently Git only supports the exact keyword described above.\n \n+`hostname`::\n+\tThe data that follows the keyword `hostname:` is taken to be a\n+\tpattern with standard globbing wildcards. If the hostname of\n+\tthe machine matches the pattern, the include condition is met.\n++\n+Depending on how your system is configured, the hostname used for\n+matching may be short (e.g., \"myhost\") or a fully qualified domain\n+name (\"myhost.example.com\"). Run `git var GIT_HOSTNAME` to see the\n+hostname Git uses (see linkgit:git-var[1]).\n+\n A few more notes on matching via `gitdir` and `gitdir/i`:\n \n  * Symlinks in `$GIT_DIR` are not resolved before matching.\n@@ -315,6 +325,10 @@ Example\n \tpath = foo.inc\n [remote \"origin\"]\n \turl = https://example.com/git\n+\n+; include only if the hostname of the machine matches some-hostname\n+[includeIf \"hostname:some-hostname\"]\n+\tpath = foo.inc\n ----\n \n Values\ndiff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc\nindex e813ab4fd2..fc2def16d3 100644\n--- a/Documentation/git-var.adoc\n+++ b/Documentation/git-var.adoc\n@@ -86,6 +86,8 @@ endif::git-default-pager[]\n \n `GIT_HOSTNAME`::\n     The hostname of the machine, as reported by the operating system.\n+    This is the hostname matched by `includeIf \"hostname:...\"` (see\n+    linkgit:git-config[1]).\n \n Most path values contain only one value. However, some can contain multiple\n values, which are separated by newlines, and are listed in order from highest to\ndiff --git a/config.c b/config.c\nindex e0bb29b53d..c891f63e60 100644\n--- a/config.c\n+++ b/config.c\n@@ -316,6 +316,21 @@ static int include_by_branch(struct config_include_data *data,\n \treturn ret;\n }\n \n+static int include_by_hostname(const char *cond, size_t cond_len)\n+{\n+\tint ret;\n+\tchar my_host[HOST_NAME_MAX + 1];\n+\tchar *pattern;\n+\n+\tif (xgethostname(my_host, sizeof(my_host)))\n+\t\treturn 0;\n+\n+\tpattern = xmemdupz(cond, cond_len);\n+\tret = !wildmatch(pattern, my_host, 0);\n+\tfree(pattern);\n+\treturn ret;\n+}\n+\n static int add_remote_url(const char *var, const char *value,\n \t\t\t  const struct config_context *ctx UNUSED, void *data)\n {\n@@ -411,6 +426,8 @@ static int include_condition_is_true(const struct key_value_info *kvi,\n \telse if (skip_prefix_mem(cond, cond_len, \"hasconfig:remote.*.url:\", &cond,\n \t\t\t\t   &cond_len))\n \t\treturn include_by_remote_url(inc, cond, cond_len);\n+\telse if (skip_prefix_mem(cond, cond_len, \"hostname:\", &cond, &cond_len))\n+\t\treturn include_by_hostname(cond, cond_len);\n \n \t/* unknown conditionals are always false */\n \treturn 0;\ndiff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh\nindex 507b8ebd06..01069237ba 100755\n--- a/t/t1305-config-include.sh\n+++ b/t/t1305-config-include.sh\n@@ -524,4 +524,48 @@ test_expect_success 'conditional include, worktree without repository but explic\n \ttest_must_fail nongit git --git-dir=nonexistent config get foo.bar\n '\n \n+test_expect_success 'conditional include, hostname' '\n+\thostname=$(git var GIT_HOSTNAME) &&\n+\tcat >>.git/config <<-EOF &&\n+\t[includeIf \"hostname:${hostname}a\"]\n+\t\tpath = bar12\n+\tEOF\n+\tcat >>.git/bar12 <<-EOF &&\n+\t[test]\n+\t\ttwelve=12\n+\tEOF\n+\n+\ttest_must_fail git config test.twelve &&\n+\n+\tcat >>.git/config <<-EOF &&\n+\t[includeIf \"hostname:$hostname\"]\n+\t\tpath = bar12\n+\tEOF\n+\techo 12 >expect &&\n+\tgit config test.twelve >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'conditional include, hostname, wildcard' '\n+\thostname=$(git var GIT_HOSTNAME) &&\n+\tcat >>.git/config <<-EOF &&\n+\t[includeIf \"hostname:${hostname}a*\"]\n+\t\tpath = bar13\n+\tEOF\n+\tcat >>.git/bar13 <<-EOF &&\n+\t[test]\n+\t\tthirteen = 13\n+\tEOF\n+\n+\ttest_must_fail git config test.thirteen &&\n+\n+\tcat >>.git/config <<-EOF &&\n+\t[includeIf \"hostname:$hostname*\"]\n+\t\tpath = bar13\n+\tEOF\n+\techo 13 >expect &&\n+\tgit config test.thirteen >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.43.0\n\n\n"},{"id":"555187","messageId":"xmqqjynin4iv.fsf@gitster.g","threadId":"66414","inReplyTo":"20261015105859.3184108-2-bellacaselli20@gmail.com","subject":"Re: [PATCH v2 1/3] var: add GIT_HOSTNAME","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-15T19:32:40Z","receivedAt":"2026-10-15T19:32:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Isabella Caselli <bellacaselli20@gmail.com> writes:\n\n> Git asks the system for the name of the machine it runs on in a few\n> places. For example, \"git gc\" records it in \"gc.pid\" to tell whether\n> the gc holding the lock runs on the same machine. Users have no way\n> to see which name Git uses, and depending on how the system is\n> configured, it may be a short name (\"myhost\") or a fully qualified\n> one (\"myhost.example.com\").\n>\n> This matters more once the config can depend on the hostname, which\n> a later commit adds as an includeIf condition. Without a way to see\n> the value Git uses, users would have to guess what to write in their\n> config file.\n>\n> Add a GIT_HOSTNAME variable to \"git var\" that prints the hostname\n> Git sees. If the hostname can't be determined, \"git var GIT_HOSTNAME\"\n> exits with a non-zero status, and \"git var -l\" omits the variable\n> instead of failing.\n>\n> An option to \"git config\" to show the hostname was also discussed,\n> but \"git var\" was chosen, since the hostname is not specific to\n> the configuration code.\n>\n> The test only checks that a non-empty value is printed. The test has\n> no independent way to know the expected hostname, as the \"hostname\"\n> command may not agree with what Git sees on every platform. The\n> includeIf tests added later check that the value matches what the\n> configuration code uses.\n>\n> Suggested-by: Eric Sunshine <sunshine@sunshineco.com>\n> Suggested-by: Jeff King <peff@peff.net>\n> Signed-off-by: Isabella Caselli <bellacaselli20@gmail.com>\n> ---\n>  Documentation/git-var.adoc |  3 +++\n>  builtin/var.c              | 13 +++++++++++++\n>  t/t0007-git-var.sh         |  5 +++++\n>  3 files changed, 21 insertions(+)\n\nNicely written, and the implementation looks sensible.\n\n\n"}]}