git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/3] t6500: get hostname from "git var"

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 12, 2026, 19:20 UTC
Message-ID
<xmqqecdu67zq.fsf@gitster.g>
In-Reply-To
<20261012015846.2649843-3-bellacaselli20@gmail.com>
Isabella Caselli <bellacaselli20@gmail.com> writes:
Show 11 quoted lines
> The test "background auto gc respects lock for all operations" simulates
> a concurrent gc by writing our shell's pid and hostname to "gc.pid".
> It gets the hostname from the "hostname" command, falling back to
> "unknown" if the command fails.
>
> "git gc" gets its hostname from the system and only checks whether the
> pid is alive if the two hostnames match. Otherwise, it assumes the
> lock belongs to a gc running on another machine. Since the test passes
> in either case, a missing "hostname" command or a mismatch between
> its output and the system hostname can cause the test to silently
> exercise the wrong case.

"exercise the wrong case", meaning... where hostname(1) output is different from "git var GIT_HOSTNAME" (aka xgethostname()), we would have written bogus name in .git/gc.pid file, simulating the case where gc.pid was written by a process running on a different machine.

What is the implications of doing so?
Show 24 quoted lines
>
> Use "git var GIT_HOSTNAME" to get the same hostname as "git gc".
> Keep the "unknown" fallback, which is also used by "git gc" when it
> cannot determine the hostname.
>
> Helped-by: Jeff King <peff@peff.net>
> Signed-off-by: Isabella Caselli <bellacaselli20@gmail.com>
> ---
>  t/t6500-gc.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
> index a7142ab815..f928089bf0 100755
> --- a/t/t6500-gc.sh
> +++ b/t/t6500-gc.sh
> @@ -413,7 +413,7 @@ test_expect_success 'background auto gc respects lock for all operations' '
>  
>  	# now fake a concurrent gc that holds the lock; we can use our
>  	# shell pid so that it looks valid.
> -	hostname=$(hostname || echo unknown) &&
> +	hostname=$(git var GIT_HOSTNAME || echo unknown) &&
>  	shell_pid=$$ &&
>  	if test_have_prereq MINGW && test -f /proc/$shell_pid/winpid
>  	then
Previous: Isabella CaselliNext: Isabella Caselli
Message 10 of 15 in “hostname: includeIf condition — anyone already working on this?”
  1. Isabella CaselliSep 28, 2026
  2. Jeff KingSep 29, 2026
  3. Ignacio EncinasSep 29, 2026
  4. Jeff KingSep 29, 2026
  5. Junio C HamanoSep 29, 2026
  6. Isabella CaselliOct 2, 2026
  7. 0/3 Add hostname condition to includeIfIsabella Caselli, Oct 12, 2026
  8. 1/3 var: add GIT_HOSTNAMEIsabella Caselli, Oct 12, 2026
  9. 2/3 t6500: get hostname from "git var"Isabella Caselli, Oct 12, 2026
  10. Junio C HamanoOct 12, 2026
  11. Isabella CaselliOct 13, 2026
  12. Junio C HamanoOct 13, 2026
  13. 3/3 config: learn the "hostname:" includeIf conditionIsabella Caselli, Oct 12, 2026
  14. Junio C HamanoOct 12, 2026
  15. Jeff KingOct 14, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.