From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86383C07E96 for ; Tue, 6 Jul 2021 17:57:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A4F561C4B for ; Tue, 6 Jul 2021 17:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230389AbhGFR7o (ORCPT ); Tue, 6 Jul 2021 13:59:44 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:61091 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229787AbhGFR7o (ORCPT ); Tue, 6 Jul 2021 13:59:44 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 54533148255; Tue, 6 Jul 2021 13:57:05 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=Vr6Gw7JuNzD6UjjxdNfEs/jGRqLankzVEjtwtg bf+ck=; b=SOdkZTO7ono3JPi6jMqhCCxrO7jxPMTdB3LOiJ3EEKoWD8HjWHHDvJ M0lTtLTgaOZYv7wjv1yxQJr/KR6xQmfVzvgYbEvKtXmkxl/d18D6CQqovyJVE66K rO1EAsomX17Jdg1Yn6jdaSIl5IXb6MS2XHtHIK0O8/0W5khWGPIXM= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 4C9FB148254; Tue, 6 Jul 2021 13:57:05 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.74.3.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id C6E4F148253; Tue, 6 Jul 2021 13:57:02 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: Clemens Fruhwirth Cc: git@vger.kernel.org Subject: Re: [PATCH] fetch: Fix segfault on pull --set-upstream outside a branch. References: <20210706162238.575988-1-clemens@endorphin.org> Date: Tue, 06 Jul 2021 10:57:01 -0700 In-Reply-To: <20210706162238.575988-1-clemens@endorphin.org> (Clemens Fruhwirth's message of "Tue, 6 Jul 2021 18:22:38 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 9182FAE2-DE83-11EB-9E97-FA9E2DDBB1FC-77302942!pb-smtp21.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Clemens Fruhwirth 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. > > Signed-off-by: Clemens Fruhwirth > --- > 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