From patchwork Tue Aug 6 12:27:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11078759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C753617E0 for ; Tue, 6 Aug 2019 12:28:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B56D328900 for ; Tue, 6 Aug 2019 12:28:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9D712896D; Tue, 6 Aug 2019 12:28:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SUSPICIOUS_RECIPS autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5922D2890C for ; Tue, 6 Aug 2019 12:28:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730368AbfHFM2A (ORCPT ); Tue, 6 Aug 2019 08:28:00 -0400 Received: from cloud.peff.net ([104.130.231.41]:35166 "HELO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726711AbfHFM2A (ORCPT ); Tue, 6 Aug 2019 08:28:00 -0400 Received: (qmail 16562 invoked by uid 109); 6 Aug 2019 12:27:59 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with SMTP; Tue, 06 Aug 2019 12:27:59 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 1286 invoked by uid 111); 6 Aug 2019 12:30:19 -0000 Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Tue, 06 Aug 2019 08:30:19 -0400 Authentication-Results: peff.net; auth=none Date: Tue, 6 Aug 2019 08:27:58 -0400 From: Jeff King To: Jeff Hostetler Cc: Johannes Schindelin , Johannes Schindelin via GitGitGadget , git@vger.kernel.org, Junio C Hamano Subject: [PATCH 3/3] config: stop checking whether the_repository is NULL Message-ID: <20190806122758.GC13513@sigill.intra.peff.net> References: <20190806122601.GA21475@sigill.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190806122601.GA21475@sigill.intra.peff.net> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since the previous commit, our invariant that the_repository is never NULL is restored, and we can stop being defensive in include_by_branch(). We can confirm the fix by showing that an onbranch config include will not cause a segfault when run outside a git repository. I've put this in t1309-early-config since it's related to the case added by 85fe0e800c (config: work around bug with includeif:onbranch and early config, 2019-07-31), though technically the issue was with read_very_early_config() and not read_early_config(). Signed-off-by: Jeff King --- config.c | 2 +- t/t1309-early-config.sh | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 3900e4947b..cc637363bb 100644 --- a/config.c +++ b/config.c @@ -275,7 +275,7 @@ static int include_by_branch(const char *cond, size_t cond_len) int flags; int ret; struct strbuf pattern = STRBUF_INIT; - const char *refname = !the_repository || !the_repository->gitdir ? + const char *refname = !the_repository->gitdir ? NULL : resolve_ref_unsafe("HEAD", 0, NULL, &flags); const char *shortname; diff --git a/t/t1309-early-config.sh b/t/t1309-early-config.sh index eeb60e4143..3a0de0ddaa 100755 --- a/t/t1309-early-config.sh +++ b/t/t1309-early-config.sh @@ -94,4 +94,9 @@ test_expect_success 'early config and onbranch' ' test_with_config "[includeif \"onbranch:master\"]path=../broken" ' +test_expect_success 'onbranch config outside of git repo' ' + test_config_global includeIf.onbranch:master.path non-existent && + nongit git help +' + test_done