From patchwork Mon Sep 20 17:57:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506697 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 F16D1C433EF for ; Tue, 21 Sep 2021 00:55:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4D9361211 for ; Tue, 21 Sep 2021 00:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234326AbhIUA4p (ORCPT ); Mon, 20 Sep 2021 20:56:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233758AbhIUAyp (ORCPT ); Mon, 20 Sep 2021 20:54:45 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AB2BC1030BE for ; Mon, 20 Sep 2021 10:57:41 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id q11so32119673wrr.9 for ; Mon, 20 Sep 2021 10:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=LFZ4CtwaX9GfeGr8oWw1CEmhEHwToUBYtMe3B0wkmBo=; b=l39AfmMgP6h9xprcFq8wSbOeTQDnwEsFoO7Z4VDc/4GV987ndraBdFUYn2flxzM1dy ihTk6eK7cmqayO2uJvq4EUPIWy55oXgbBoxqqmqhIDlZ2Gz5hnMz4oZ+9FrtXR49YtoY U2QhY4yZd6Ze++ks6SCdithqkTZoiGwEn+G6U876UkTX2kwn/v6kud3P4Q5FaJzxCYxB 4K0jjjyPtA7wH1D+bHZhEpjKkUYYdWYw5mwDLyyUrvCp7XVB9bcfU1KZnpSSc5nuDZ8z vIlEuJMULJ1WKoVkzcPkQW8yHmnqfnOYNJoic4m4TH4mZp0Mwx6jZyvv4DcPXeOmB/0I ioKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=LFZ4CtwaX9GfeGr8oWw1CEmhEHwToUBYtMe3B0wkmBo=; b=mhHyyKyUzNIzcfli9ZTtueCSlTmuPJT/roXp3Z7DuGnQzVRE+ck5JXvdlWci3RqGf3 d2WKiPCVWdmqzTiZ5NsthdiREyJ9pj4MGdnJw+ghMX0q6A6D+rOMjwc7dcHlpstNysIC 2D6jPil+bDjjIjJvhXs7kMUVYG6p54VnZh2wYvv2/6PLfj+pagkIqdt7Vmoj0aqenk10 rzwIE14xrmSEFYWNaR33Q+LsUAeD0r16S4HrLNqyIRiF1G5Rv87PINHkcfuAsuro8/gU KHndu78JyCQTSnCGNdl5nYFLx/Sd/Wg7LAnMYbqwBKkALkAIXgBtEyxMovs6S95rPneR nwSw== X-Gm-Message-State: AOAM531f1J1GxKPkZ4PFocfDwNdzy0n3E85ge+oRkj8UtPsfHAduIz1c 9hHlH+4xweBp9u6Bd61P247u9GHXZ+o= X-Google-Smtp-Source: ABdhPJz0Zq1coYNMyOXhQDZNaEvC6lQyphKNDkC0QjAHUgKfJx2XFCU0jWlQ8eykA789iPv10DZoYQ== X-Received: by 2002:a5d:4212:: with SMTP id n18mr30642720wrq.37.1632160659910; Mon, 20 Sep 2021 10:57:39 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j2sm16666671wrq.35.2021.09.20.10.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:57:39 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 20 Sep 2021 17:57:36 +0000 Subject: [PATCH 1/3] sparse-checkout: fix OOM error with mixed patterns Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, calbabreaker@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Add a test to t1091-sparse-checkout-builtin.sh that would result in an infinite loop and out-of-memory error before this change. The issue relies on having non-cone-mode patterns while trying to modify the patterns in cone-mode. The fix is simple, allowing us to break from the loop when the input path does not contain a slash, as the "dir" pattern we added does not. This is only a fix to the critical out-of-memory error. A better response to such a strange state will follow in a later change. Reported-by: Calbabreaker Helped-by: Taylor Blau Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 2 +- t/t1091-sparse-checkout-builtin.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 8ba9f13787b..b45fd97a98b 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -389,7 +389,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat char *oldpattern = e->pattern; size_t newlen; - if (slash == e->pattern) + if (!slash || slash == e->pattern) break; newlen = slash - e->pattern; diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 38fc8340f5c..a429d2cc671 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -103,6 +103,14 @@ test_expect_success 'clone --sparse' ' check_files clone a ' +test_expect_success 'switching to cone mode with non-cone mode patterns' ' + git init bad-patterns && + git -C bad-patterns sparse-checkout init && + git -C bad-patterns sparse-checkout add dir && + git -C bad-patterns config core.sparseCheckoutCone true && + git -C bad-patterns sparse-checkout add dir +' + test_expect_success 'interaction with clone --no-checkout (unborn index)' ' git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout && git -C clone_no_checkout sparse-checkout init --cone && From patchwork Mon Sep 20 17:57:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506699 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 09473C433F5 for ; Tue, 21 Sep 2021 00:55:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF70461211 for ; Tue, 21 Sep 2021 00:55:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235714AbhIUA4u (ORCPT ); Mon, 20 Sep 2021 20:56:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233309AbhIUAyt (ORCPT ); Mon, 20 Sep 2021 20:54:49 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BED1DC1030BF for ; Mon, 20 Sep 2021 10:57:41 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id q26so32086870wrc.7 for ; Mon, 20 Sep 2021 10:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=098eEX50Z/eS3AZWOiMa5VUm9U4YsE42KDjUAll0ROs=; b=XjeJSpYaYdEQjuvRQfHy0VRo3rb6s/fwWLa5pImWraYp7Isk4gUamTxdvpG6P20eY2 /5Uk/nZLoJELnbb4oTGoiLaah1nhXaF2FiBywwn7pu7Tw+D5eefxDZkcPeYFxluT4VIM wge644zxUXLWyCFhBzyicrAcmZHQTA+tMFL4fPywcSuxuTVtoqtCGKW79CNuabT4RISi 260RYp6NycoPqiNWprYPEaWiQh+4iSL4LEQUTBRYOAm0l2WLkQN1DAX2dP+35HlwrFUX f+8X0i2Q6S77R6NKXXosNgVLU3Gz181oyDnx5gpMCGTOlYIp+Vxgvw1wFx1Gs77i3z9k iE/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=098eEX50Z/eS3AZWOiMa5VUm9U4YsE42KDjUAll0ROs=; b=41vgUoMV8ZLynPfIrFRG1NoUPn17he9BZHpJW0Abiyi/tZ1JsWeZf4DUIMyuKep/dk +SB7ET8ZwJ5g5VLqgz+2nFtYJHftTH3TXI+xVcksjscG6Q0CtkklsRDKhRhSTG0c4ueB iIKzYG5dLeP0wzeAhePsQT97FWdpNuBxEYY1U8xOayXwZCT8nwhHTpkvBdDmk3/Iv+DJ LgmMjW0v8TaTvPcFGt5Gi93C2EwpaNkWHlBSPnKmLL3hS0nl4Oa6RUMRmp7FxlDbVHPz +h/fD2gaQ0zGvwlu60PUygebg7cTkYqSCY00QDw9+tA3DIxAVft+GPXdyIpi8yrzMZ+x 7kfw== X-Gm-Message-State: AOAM530N3cpw+Q5mjY30BuDKXloQu+vhMXIK4thrW9CmQ2avYfD6mWVr HGxYSkqsVjPDRJI4xMSyrPTIL06nLkM= X-Google-Smtp-Source: ABdhPJzI3ddytG73/PTKtncvVjCm+BjUmyY5oHiR0zsjAhDfqoGwuHbplIrr6ObQVPGAjXj+qbaC8w== X-Received: by 2002:a05:600c:3641:: with SMTP id y1mr273134wmq.181.1632160660435; Mon, 20 Sep 2021 10:57:40 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w14sm16594294wro.8.2021.09.20.10.57.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:57:40 -0700 (PDT) Message-Id: <450b90dad57c42e37a4edc52dac88caf98021fc6.1632160658.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Sep 2021 17:57:37 +0000 Subject: [PATCH 2/3] sparse-checkout: clear patterns when switching modes Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, calbabreaker@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Previously, when a user runs 'git sparse-checkout init --cone', the existing patterns would remain, even if the patterns were not in cone mode. This causes confusion as to how the patterns should work when later 'git sparse-checkout add' commands append to the pattern list. In fact, the way these patterns were modified was not even a strict appending of patterns, but mutating and reordering patterns because of how the paths were interpreted and rewritten. As a first step, we shall start overwriting the pattern set completely when switching to cone mode, unless the existing patterns already match cone mode patterns. The 'use_cone_patterns' member is set to false if the patterns fail to parse using cone mode restrictions. Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 13 +++++++++++-- t/t1091-sparse-checkout-builtin.sh | 9 ++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index b45fd97a98b..fe76c3eedda 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -348,8 +348,17 @@ static int sparse_checkout_init(int argc, const char **argv) /* If we already have a sparse-checkout file, use it. */ if (res >= 0) { - free(sparse_filename); - return update_working_directory(NULL); + if (pl.use_cone_patterns || !init_opts.cone_mode) { + free(sparse_filename); + return update_working_directory(NULL); + } + + /* + * At this point, note that if res >= 0 but pl.use_cone_patterns + * is false, then we want to override the patterns with the + * initial set of cone mode patterns. + */ + clear_pattern_list(&pl); } if (get_oid("HEAD", &oid)) { diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index a429d2cc671..af0acd32bd9 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -108,7 +108,14 @@ test_expect_success 'switching to cone mode with non-cone mode patterns' ' git -C bad-patterns sparse-checkout init && git -C bad-patterns sparse-checkout add dir && git -C bad-patterns config core.sparseCheckoutCone true && - git -C bad-patterns sparse-checkout add dir + git -C bad-patterns sparse-checkout add dir && + + git -C bad-patterns sparse-checkout init --cone && + cat >expect <<-\EOF && + /* + !/*/ + EOF + test_cmp expect bad-patterns/.git/info/sparse-checkout ' test_expect_success 'interaction with clone --no-checkout (unborn index)' ' From patchwork Mon Sep 20 17:57:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506701 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 E0E31C433EF for ; Tue, 21 Sep 2021 00:55:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C821D6115B for ; Tue, 21 Sep 2021 00:55:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237443AbhIUA4x (ORCPT ); Mon, 20 Sep 2021 20:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233349AbhIUAyx (ORCPT ); Mon, 20 Sep 2021 20:54:53 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53110C10F500 for ; Mon, 20 Sep 2021 10:57:42 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id g16so32138048wrb.3 for ; Mon, 20 Sep 2021 10:57:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=7ws927nRBkUxD7akW53F4I2dOz6lGl4lLidCwsiUMgE=; b=h8qrDfS+6w4UOQlgQN25eUsVqyaRRfsQVRCkPla/6bDD9v18dEECO625l36QEXY9aI WKp7bSlx762lI+yq3bSX6mtwGaMRrwx/9nd8Tj+8mhMuBn2YzOUWqVzmtWjAKHrlGvHb FKyom6egTIB/1gMVHSS6EfzU+jjv65vYtSsOQzuHd0Dw2Fhcuvpk1sPpEqHEsLXgpTMm 2ckGcPfyv5eaedHNz8j2Xe6n7SJCYJ5lwEZ3HVxdjtzuIBI0UEs0pkFfKpZZCbS39DOh ntD77p4DxlXw8GTO1U4UlwNip98MC12E/XMYAFb+9x2W4FiMdNxlK2vCEAeuuwTqclpM NDOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=7ws927nRBkUxD7akW53F4I2dOz6lGl4lLidCwsiUMgE=; b=bJoLDmE/H1+rgS3MHFzugrgU1fFrf6emkmLo+l0AQ5QDQ5Ukcg0eGXKkY6t7rME+Gf oWGako9wcqb/EBPpsZSiYhezPcREqktRF+3J7AVMM7wrGVQtGdcej0DxCpiDpbwjFupz 9jRaOjj6v81KvwAT5kHEJuzwR3AHvebcqU622welAlF7lKduq2OF4YcIZ9OmbNFTB9De qa+K5J2ujgmbibWlXQUljAiuq8svjX//oyVnnRHImJsUuc2W/SqphDF8aAPrs8bG/egO MQ3G8t472ca/P1qbnyzCRQZLJMwOLngq/Xm0LCdUCATONCxyPjkjULhQXsX3al6gkh8C OX7g== X-Gm-Message-State: AOAM5302dTDJjWfmpdQs8V2vVKcP0HVZojZ9wrhmb46DiFBSfO+rjNVl 5Jlehkt7MV+viQkb68iP6t+ahX0LyWc= X-Google-Smtp-Source: ABdhPJzXi+uPd+CSojQkRa0zyOOis8bOI2YB2mctzEHtZZ1DZanHFNgdkiIWa7GOre8eteL82ZLNeA== X-Received: by 2002:a05:600c:1910:: with SMTP id j16mr317482wmq.11.1632160661001; Mon, 20 Sep 2021 10:57:41 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g22sm174164wmp.39.2021.09.20.10.57.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:57:40 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 20 Sep 2021 17:57:38 +0000 Subject: [PATCH 3/3] sparse-checkout: refuse to add to bad patterns Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, calbabreaker@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When in cone mode sparse-checkout, it is unclear how 'git sparse-checkout add ...' should behave if the existing sparse-checkout file does not match the cone mode patterns. Change the behavior to fail with an error message about the existing patterns. Also, all cone mode patterns start with a '/' character, so add that restriction. This is necessary for our example test 'cone mode: warn on bad pattern', but also requires modifying the example sparse-checkout file we use to test the warnings related to recognizing cone mode patterns. Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 3 +++ dir.c | 2 +- t/t1091-sparse-checkout-builtin.sh | 11 +++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index fe76c3eedda..2492ae828a9 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -513,6 +513,9 @@ static void add_patterns_cone_mode(int argc, const char **argv, die(_("unable to load existing sparse-checkout patterns")); free(sparse_filename); + if (!existing.use_cone_patterns) + die(_("existing sparse-checkout patterns do not use cone mode")); + hashmap_for_each_entry(&existing.recursive_hashmap, &iter, pe, ent) { if (!hashmap_contains_parent(&pl->recursive_hashmap, pe->pattern, &buffer) || diff --git a/dir.c b/dir.c index 03c4d212672..93136442103 100644 --- a/dir.c +++ b/dir.c @@ -727,7 +727,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern } if (given->patternlen < 2 || - *given->pattern == '*' || + *given->pattern != '/' || strstr(given->pattern, "**")) { /* Not a cone pattern. */ warning(_("unrecognized pattern: '%s'"), given->pattern); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index af0acd32bd9..780c6a1aaae 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -108,14 +108,17 @@ test_expect_success 'switching to cone mode with non-cone mode patterns' ' git -C bad-patterns sparse-checkout init && git -C bad-patterns sparse-checkout add dir && git -C bad-patterns config core.sparseCheckoutCone true && - git -C bad-patterns sparse-checkout add dir && + + test_must_fail git -C bad-patterns sparse-checkout add dir 2>err && + grep "existing sparse-checkout patterns do not use cone mode" err && git -C bad-patterns sparse-checkout init --cone && cat >expect <<-\EOF && /* !/*/ EOF - test_cmp expect bad-patterns/.git/info/sparse-checkout + test_cmp expect bad-patterns/.git/info/sparse-checkout && + git -C bad-patterns sparse-checkout add dir ' test_expect_success 'interaction with clone --no-checkout (unborn index)' ' @@ -182,9 +185,9 @@ test_expect_success 'set sparse-checkout using --stdin' ' test_expect_success 'add to sparse-checkout' ' cat repo/.git/info/sparse-checkout >expect && cat >add <<-\EOF && - pattern1 + /pattern1 /folder1/ - pattern2 + /pattern2 EOF cat add >>expect && git -C repo sparse-checkout add --stdin