All of lore.kernel.org
 help / color / mirror / Atom feed
From: Isabella Caselli <bellacaselli20@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Eric Sunshine <sunshine@sunshineco.com>,
	Ignacio Encinas <ignacio@iencinas.com>,
	Isabella Caselli <bellacaselli20@gmail.com>
Subject: [PATCH 1/3] var: add GIT_HOSTNAME
Date: Sun, 11 Oct 2026 22:58:44 -0300	[thread overview]
Message-ID: <20261012015846.2649843-2-bellacaselli20@gmail.com> (raw)
In-Reply-To: <20261012015846.2649843-1-bellacaselli20@gmail.com>

Git asks the system for the name of the machine it runs on in a few
places. For example, "git gc" records it in "gc.pid" to tell whether
the gc holding the lock runs on the same machine. Users have no way
to see which name Git uses, and depending on how the system is
configured, it may be a short name ("myhost") or a fully qualified
one ("myhost.example.com").

This matters more once the config can depend on the hostname, which
a later commit adds as an includeIf condition. Without a way to see
the value Git uses, users would have to guess what to write in their
config file.

Add a GIT_HOSTNAME variable to "git var" that prints the hostname
Git sees. If the hostname can't be determined, "git var GIT_HOSTNAME"
exits with a non-zero status, and "git var -l" omits the variable
instead of failing.

An option to "git config" to show the hostname was also discussed,
but "git var" was chosen, since the hostname is not specific to
the configuration code.

The test only checks that a non-empty value is printed. The test has
no independent way to know the expected hostname, as the "hostname"
command may not agree with what Git sees on every platform. The
includeIf tests added later check that the value matches what the
configuration code uses.

Suggested-by: Eric Sunshine <sunshine@sunshineco.com>
Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Isabella Caselli <bellacaselli20@gmail.com>
---
 Documentation/git-var.adoc |  3 +++
 builtin/var.c              | 13 +++++++++++++
 t/t0007-git-var.sh         |  5 +++++
 3 files changed, 21 insertions(+)

diff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc
index 697c10aded..e813ab4fd2 100644
--- a/Documentation/git-var.adoc
+++ b/Documentation/git-var.adoc
@@ -84,6 +84,9 @@ endif::git-default-pager[]
 `GIT_CONFIG_GLOBAL`::
     The path to the global (per-user) configuration files, if any.
 
+`GIT_HOSTNAME`::
+    The hostname of the machine, as reported by the operating system.
+
 Most path values contain only one value. However, some can contain multiple
 values, which are separated by newlines, and are listed in order from highest to
 lowest priority.  Callers should be prepared for any such path value to contain
diff --git a/builtin/var.c b/builtin/var.c
index cc3a43cde2..b427ebd61e 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -115,6 +115,15 @@ static char *git_config_val_global(int ident_flag UNUSED)
 	return strbuf_detach(&buf, &unused);
 }
 
+static char *hostname(int ident_flag UNUSED)
+{
+	char buf[HOST_NAME_MAX + 1];
+
+	if (xgethostname(buf, sizeof(buf)))
+		return NULL;
+	return xstrdup(buf);
+}
+
 struct git_var {
 	const char *name;
 	char *(*read)(int);
@@ -166,6 +175,10 @@ static struct git_var git_vars[] = {
 		.read = git_config_val_global,
 		.multivalued = 1,
 	},
+	{
+		.name = "GIT_HOSTNAME",
+		.read = hostname,
+	},
 	{
 		.name = "",
 		.read = NULL,
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
index 2b60317758..f50c62a25e 100755
--- a/t/t0007-git-var.sh
+++ b/t/t0007-git-var.sh
@@ -224,6 +224,11 @@ test_expect_success 'GIT_CONFIG_GLOBAL points to the correct location' '
 	)
 '
 
+test_expect_success 'GIT_HOSTNAME is not empty' '
+	hostname=$(git var GIT_HOSTNAME) &&
+	test -n "$hostname"
+'
+
 # For git var -l, we check only a representative variable;
 # testing the whole output would make our test too brittle with
 # respect to unrelated changes in the test suite's environment.
-- 
2.43.0


  reply	other threads:[~2026-10-12  2:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 23:43 hostname: includeIf condition — anyone already working on this? Isabella Caselli
2026-09-29  1:44 ` Jeff King
2026-09-29 12:14   ` Ignacio Encinas
2026-09-29 18:28     ` Jeff King
2026-09-29 19:55     ` Junio C Hamano
2026-10-02  1:52       ` Isabella Caselli
2026-10-12  1:58         ` [PATCH 0/3] Add hostname condition to includeIf Isabella Caselli
2026-10-12  1:58           ` Isabella Caselli [this message]
2026-10-12  1:58           ` [PATCH 2/3] t6500: get hostname from "git var" Isabella Caselli
2026-10-12 19:20             ` Junio C Hamano
2026-10-13  1:14               ` Isabella Caselli
2026-10-13  1:43                 ` Junio C Hamano
2026-10-12  1:58           ` [PATCH 3/3] config: learn the "hostname:" includeIf condition Isabella Caselli
2026-10-12 19:24             ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261012015846.2649843-2-bellacaselli20@gmail.com \
    --to=bellacaselli20@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ignacio@iencinas.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.