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

[PATCH] fetch: Fix segfault on pull --set-upstream outside a branch.

From
CFClemens Fruhwirth <clemens@endorphin.org>
Date
Jul 6, 2021, 16:22 UTC
Message-ID
<20210706162238.575988-1-clemens@endorphin.org>

branch_get("HEAD") can return NULL, when we are outside a branch and the user calls pull --set-upstream. Catch this case and warn the user to avoid a segfault.

Signed-off-by: Clemens Fruhwirth <clemens@endorphin.org>
---
 builtin/fetch.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 9191620e50..1097235b90 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1602,6 +1602,10 @@ static int do_fetch(struct transport *transport,
 		struct ref *rm;
 		struct ref *source_ref = NULL;
 
+		if (!branch) {
+			warning(_("no branch detected to use --set-upstream with."));
+			goto skip;
+		}
 		/*
 		 * We're setting the upstream configuration for the
 		 * current branch. The relevant upstream is the
-- 
2.31.1
Next: Junio C Hamano
Message 1 of 5 in “fetch: Fix segfault on pull --set-upstream outside a branch.”
  1. fetch: Fix segfault on pull --set-upstream outside a branch.Clemens Fruhwirth, Jul 6, 2021
  2. Junio C HamanoJul 6, 2021
  3. Eric SunshineJul 6, 2021
  4. Junio C HamanoJul 6, 2021
  5. Junio C HamanoJul 6, 2021

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.