git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fetch: Fix segfault on pull --set-upstream outside a branch.
@ 2021-07-06 16:22 Clemens Fruhwirth
  2021-07-06 17:57 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Clemens Fruhwirth @ 2021-07-06 16:22 UTC (permalink / raw)
  To: git; +Cc: Clemens Fruhwirth

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-06 19:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 16:22 [PATCH] fetch: Fix segfault on pull --set-upstream outside a branch Clemens Fruhwirth
2021-07-06 17:57 ` Junio C Hamano
2021-07-06 18:03   ` Eric Sunshine
2021-07-06 19:48   ` Junio C Hamano
2021-07-06 19:50     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).