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

Re: [SOLVED] Re: safe.directory does not work at all (git 2.39.5, 2.51.0)

From
Jeff King <peff@peff.net>
Date
Sep 15, 2025, 02:46 UTC
Message-ID
<20250915024630.GA595592@coredump.intra.peff.net>
In-Reply-To
<20250915022301.GA593748@coredump.intra.peff.net>
On Sun, Sep 14, 2025 at 10:23:01PM -0400, Jeff King wrote:
Show 5 quoted lines
>   - could upload-pack install a die() handler that prints the message in
>     an ERR packet? I worry a little that older versions of Git would not
>     handle this great, as I don't think they were always prepared to see
>     an ERR packet at any point. OTOH, it is probably better than sending
>     nothing, which is what we do now.
Just for fun, I tried the patch below on v2.39.5:
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index f446ff04f6..ad40143beb 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -13,6 +13,21 @@ static const char * const upload_pack_usage[] = {
 	NULL
 };
 
+NORETURN
+static void send_err_pkt_on_die(const char *fmt, va_list ap)
+{
+	struct strbuf buf = STRBUF_INIT;
+
+	/* format into a buf since interfaces below do not handle va_list */
+	strbuf_vaddf(&buf, fmt, ap);
+
+	/* write our ERR packet */
+	packet_write_fmt_gently(1, "ERR %s", buf.buf);
+
+	/* and then do the usual die to stderr */
+	exit(die_message("%s", buf.buf));
+}
+
 int cmd_upload_pack(int argc, const char **argv, const char *prefix)
 {
 	const char *dir;
@@ -38,6 +53,8 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
 	/* TODO: This should use NO_LAZY_FETCH_ENVIRONMENT */
 	xsetenv("GIT_NO_LAZY_FETCH", "1", 0);
 
+	set_die_routine(send_err_pkt_on_die);
+
 	argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
 
 	if (argc != 1)


The results are...not great. You get every message twice, of course,
because we still print it to stderr. Though that could easily be fixed.
But for the multi-line message in question, the "remote error" part is
hard to see amidst the other lines:

  Cloning into 'foo'...
  fatal: detected dubious ownership in repository at '/tmp/foo.git'
  To add an exception for this directory, call:
  
  	git config --global --add safe.directory /tmp/foo.git
  fatal: remote error: detected dubious ownership in repository at '/tmp/foo.git'
  To add an exception for this directory, call:
  
  	git config --global --add safe.directory /tmp/foo.git

Probably it would help to look for newlines and prefix every line with
"remote: or similar. But an even bigger problem is that we die
immediately on seeing the remote ERR packet, so we miss out on any local
error messages. An obvious one is trying to clone something that doesn't
exist at all. We used to say:

  Cloning into 'does-not-exist'...
  fatal: '/tmp/does-not-exist.git' does not appear to be a git repository
  fatal: Could not read from remote repository.

  Please make sure you have the correct access rights
  and the repository exists.

Noting that we saw an error from the remote side and giving some hints.
And the stderr from the other side is enough to give us the more
specific message (though again, over http the user would not get that
stderr message; however, if we get a 404 we do show a useful message).

But with the patch above we just relay what the other side says:

  Cloning into 'does-not-exist'...
  fatal: '/tmp/does-not-exist.git' does not appear to be a git repository
  fatal: remote error: '/tmp/does-not-exist.git' does not appear to be a git repository

which seems worse to me.

So probably not a very productive direction. Oh well.

-Peff
Previous: Jeff KingNext: Marc-Jano Knopp
Message 5 of 6 in “safe.directory does not work at all (git 2.39.5, 2.51.0)”
  1. Marc-Jano KnoppSep 13, 2025
  2. Carlo Marcelo Arenas BelónSep 13, 2025
  3. [SOLVED] Re: safe.directory does not work at all (git 2.39.5, 2.51.0)Marc-Jano Knopp, Sep 14, 2025
  4. Jeff KingSep 15, 2025
  5. Jeff KingSep 15, 2025
  6. Marc-Jano KnoppSep 17, 2025

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.