Re: [PATCH] fetch: Fix segfault on pull --set-upstream outside a branch.
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 6, 2021, 17:57 UTC
- Message-ID
- <xmqq1r8bl40i.fsf@gitster.g>
- In-Reply-To
- <20210706162238.575988-1-clemens@endorphin.org>
Clemens Fruhwirth <clemens@endorphin.org> writes:
> 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.Nit. What do you mean by "outside a branch"? If you mean "when the HEAD is detached", please say so, and use the same terminology in your warning message.
Thanks.
Show 21 quoted lines
>
> 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