var: add GIT_HOSTNAME
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
seen
parent
6de20f6092
commit
a13fc94041
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue