From patchwork Sun Feb 13 00:39:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12744463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9F7BC433F5 for ; Sun, 13 Feb 2022 00:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232723AbiBMAkH (ORCPT ); Sat, 12 Feb 2022 19:40:07 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:45980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232696AbiBMAkG (ORCPT ); Sat, 12 Feb 2022 19:40:06 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0F6F60056 for ; Sat, 12 Feb 2022 16:40:01 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id q7so21062494wrc.13 for ; Sat, 12 Feb 2022 16:40:01 -0800 (PST) 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=Vtq8XORj/hxx6nCc44oK4fdOBAXFCtRiqMrYaxSzNHk=; b=T8Tk4waw0GvI+fBwIq/BmlVJVvQpouJe2tQtTb0jpupXmExCzEwCK1sJSvjz3JMC4B ATiwCkbsUWLFb5h89ii3hkkxKuJzEQMCtZJK1QLKw/yEPRm5D+4NSX5v7xDsWEICMZKT GYTo31Wq4/u64wRFFw6GkfjQQvBmGZWcD3fBJkjtPJftupBx8/9wq3D78Z1qXWPFH1dl DlzYjKBcKv6AF4eO709A/FHcbO82QmGAMXa5IXM1unfv5ZLlgNSRmbGeC4YU4KcKH9Hl Qfi4wg4m/DS1oJTEjLyWxw3uha/KI+TX+LXPvsDLTslDxZKq3cBwnBOzFcqYCcV5nUk+ 55hg== 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=Vtq8XORj/hxx6nCc44oK4fdOBAXFCtRiqMrYaxSzNHk=; b=2yrKqepo2S93bNC8vyxe1RofAuIkBAAzkoKNS3Of6dDUGGRjz31lQz+phNaIKxkPGS UfAzqiIAkigd7Bo7EGgoTQYCdbbbwSPpIH5KllEjLPq7SmnRJ4uIlJeTogXMDbmGgPFB Kz1ifvkQBFVVNY+Y6oa7QEiL5XEOnx4UujXTsR5PrVkz3/RblaAgv9UWwoFBFfIG3ZIA bfsBaBm74EQchOzayZR32LtcC67vuw7r3YPB20tVqdm98Yknjzq0wRxQnDIblxwa+Q8B xWR3GiqdE91xG40mQ3MTUX8POP+gj1MvCoBH0K4fANQy7JBnxGSbg1QprCpfWz5MZLFh 9EhA== X-Gm-Message-State: AOAM531TZ3ibEcUQwC4wXYZnuCKL/9DlAAYr3eHfb8YhBCM6c61J100N F0825/0mLhrAiECmaXs4FRSxXb2CGec= X-Google-Smtp-Source: ABdhPJxwOymwGSWbvc338q2z/4tlHyaGR8vKTuUTqSJO08WH7MEEMKbzJCSCT/fk2ntCweijE6VgXw== X-Received: by 2002:a05:6000:1242:: with SMTP id j2mr6262402wrx.39.1644712800219; Sat, 12 Feb 2022 16:40:00 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z2sm7368446wrn.60.2022.02.12.16.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 16:39:59 -0800 (PST) Message-Id: <00777e77118c2479c9dd3cede87b0690602dbc7b.1644712798.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 13 Feb 2022 00:39:51 +0000 Subject: [PATCH 1/7] sparse-checkout: correct reapply's handling of options Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Victoria Dye , Derrick Stolee , Lessley Dennington , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Commit 4e256731d6 ("sparse-checkout: enable reapply to take --[no-]{cone,sparse-index}", 2021-12-14) made it so that reapply could take additional options but added no tests. Tests would have shown that the feature doesn't work because the initial values are set AFTER parsing the command line options instead of before. Add a test and set the initial value at the appropriate time. Signed-off-by: Elijah Newren --- builtin/sparse-checkout.c | 6 +++--- t/t1091-sparse-checkout-builtin.sh | 31 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index b9f79e74969..510cb89b544 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -785,15 +785,15 @@ static int sparse_checkout_reapply(int argc, const char **argv) if (!core_apply_sparse_checkout) die(_("must be in a sparse-checkout to reapply sparsity patterns")); + reapply_opts.cone_mode = -1; + reapply_opts.sparse_index = -1; + argc = parse_options(argc, argv, NULL, builtin_sparse_checkout_reapply_options, builtin_sparse_checkout_reapply_usage, 0); repo_read_index(the_repository); - reapply_opts.cone_mode = -1; - reapply_opts.sparse_index = -1; - if (update_modes(&reapply_opts.cone_mode, &reapply_opts.sparse_index)) return 1; diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 502d42d183a..4a7394f7a58 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -510,6 +510,37 @@ test_expect_failure 'sparse-checkout reapply' ' git -C tweak sparse-checkout disable ' +test_expect_success 'reapply can handle config options' ' + git -C repo sparse-checkout init --cone --no-sparse-index && + git -C repo config --worktree --list >actual && + cat >expect <<-\EOF && + core.sparsecheckout=true + core.sparsecheckoutcone=true + index.sparse=false + EOF + test_cmp expect actual && + + git -C repo sparse-checkout reapply --no-cone --no-sparse-index && + git -C repo config --worktree --list >actual && + cat >expect <<-\EOF && + core.sparsecheckout=true + core.sparsecheckoutcone=false + index.sparse=false + EOF + test_cmp expect actual && + + git -C repo sparse-checkout reapply --cone --sparse-index && + git -C repo config --worktree --list >actual && + cat >expect <<-\EOF && + core.sparsecheckout=true + core.sparsecheckoutcone=true + index.sparse=true + EOF + test_cmp expect actual && + + git -C repo sparse-checkout disable +' + test_expect_success 'cone mode: set with core.ignoreCase=true' ' rm repo/.git/info/sparse-checkout && git -C repo sparse-checkout init --cone && From patchwork Sun Feb 13 00:39:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12744465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 003B8C433EF for ; Sun, 13 Feb 2022 00:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232735AbiBMAkM (ORCPT ); Sat, 12 Feb 2022 19:40:12 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:45996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232724AbiBMAkH (ORCPT ); Sat, 12 Feb 2022 19:40:07 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B409A60054 for ; Sat, 12 Feb 2022 16:40:02 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id v12so21213481wrv.2 for ; Sat, 12 Feb 2022 16:40:02 -0800 (PST) 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=1rnONSHMUvxE7YK2UJ2Br18QguH0y2A+FDjiLUSsvRw=; b=nYrmNTV1xMyjv5/61HkHxoD2o/nt9DXJwUgLVKNvrkJo7lwoIQzVEMogyk2eLk9T04 GTwE1tlbOhEGU6uMs9y9iIpWJ2jXRGxkagAPGNb4wMSGxuZ9Q5KI91vJeZeI0vVq1O1e R1xZDzny5LHgSFVBlcKkG+it92vif3NEZZ1/+XB+m/v8j7x3IVJcotMdC74vYp5nXGbB e1SlQdKlUGqcuLcmrZb9in56Sk8X4eq5PIQNszGqBYW2ZMl3pVv2zyx6wyNsqd5gthHr eef6l03CJa5TJhKgztRX/VSvpy9x/H6r5eqnvoYsKcxK++jIS0IkIsZTRDeA2Jpn9u62 DrKQ== 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=1rnONSHMUvxE7YK2UJ2Br18QguH0y2A+FDjiLUSsvRw=; b=KEHYuxd3DCzLHnEFFEMoQAju4wWQi1hVu9N/+GgkT6aE61dfj+Zn8xqwBir5R4ddMj g4hbkVsYboc7nfuiinPI2cguCL9GiJLDk1QUw2SPKMEcP1MBc9q1UZnuV8dwSX6wEkEa 7K8mh8K6on/Hj3R8Iw5wMl+bzXQQOqSRGJt8yFzzTg9MCfveXl3ZeZB+aN0R0POwACYu 6AO4l8s65ydpDdJWJb2RTp3/d8mPfTwY8VQNYIVMsTJDHJpaysaK5fdn8Eb7ly2cGL+Z rhaVXiqtH1NXlfSyfRmpKEf4pfpqGBz5jOkKBGFU09YZ+hWIcbUpZAzvJUd4QQN8ZE1y mH8Q== X-Gm-Message-State: AOAM533ABiozA0gdlq3lVDcztvDMRVek40VwdyZXi10Ye2xRgJa3dO+C VWtOniH0++PlVTGj2Obm1x9gXeqjkm8= X-Google-Smtp-Source: ABdhPJyY/TwZwc9YZDfp0rCNdzX5u3HaNHhUIz9s6W+5YUHIlWtBz3wu2Gzu9bDwZRGIp3XCd4/LtQ== X-Received: by 2002:a5d:6452:: with SMTP id d18mr6156301wrw.493.1644712801127; Sat, 12 Feb 2022 16:40:01 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bk5sm13253148wrb.10.2022.02.12.16.40.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 16:40:00 -0800 (PST) Message-Id: <3bab59604046facb1e31ff1496e5bdb1afc7bf22.1644712798.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 13 Feb 2022 00:39:52 +0000 Subject: [PATCH 2/7] sparse-checkout: correctly set non-cone mode when expected Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Victoria Dye , Derrick Stolee , Lessley Dennington , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren commit f2e3a218e8 ("sparse-checkout: enable `set` to initialize sparse-checkout mode", 2021-12-14) made the `set` command able to intialize sparse-checkout mode, but it also had to function when sparse-checkout mode was already setup and the user just wanted to change the sparsity paths. So, if the user passed --cone or --no-cone, then we should override the current setting, but if they didn't pass either, we should use whatever the current cone mode setting is. Unfortunately, there was a small error in the logic in that it would not set the in-memory cone mode value (core_sparse_checkout_one) when --no-cone was specified, but since it did set the config setting on disk, any subsequent git invocation would correctly get non-cone mode. As such, the error did not previously matter. However, a sbusequent commit will add some logic that depends on core_sparse_checkout_cone being set to the correct mode, so make sure it is set consistently with the config values we will be writing to disk. Signed-off-by: Elijah Newren --- builtin/sparse-checkout.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 510cb89b544..8d595189ea3 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -399,6 +399,8 @@ static int update_modes(int *cone_mode, int *sparse_index) core_sparse_checkout_cone = 1; } else { mode = MODE_ALL_PATTERNS; + if (record_mode) + core_sparse_checkout_cone = 0; } if (record_mode && set_config(mode)) return 1; From patchwork Sun Feb 13 00:39:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12744464 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF8BAC433FE for ; Sun, 13 Feb 2022 00:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232741AbiBMAkM (ORCPT ); Sat, 12 Feb 2022 19:40:12 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232696AbiBMAkI (ORCPT ); Sat, 12 Feb 2022 19:40:08 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D69460056 for ; Sat, 12 Feb 2022 16:40:03 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id v129so7583038wme.2 for ; Sat, 12 Feb 2022 16:40:03 -0800 (PST) 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=Lf81j0EfViiw5yQag7tu+GvRr1Mg3cI/hhwGiCBZiqo=; b=oVuV5N552m8O87pICXxug0aRTzR5oA0QtDEW44AIkpTYu5PyoQepzHt7QU/WxxUZtq ZNd7sio9jxLg1UaEv4dOQH0gA8OjHOq2THdIxF/qQQbc4f7MgjQDtHtOntsVtrSqx2sP BFzx+Og+PsGEYVsDRhbI8F4XY0GL0b6nuVfiiwPdm0r0kpCXX/Sr679pVjpKPTW/CvDW 95zut+tOc1aC0eR65x56FyMEGrEnax5pvLU+whFPWqYE9i6c8e0hXwdzdayoOZJagWur g8comxG+HotWX3iCPqKVYPwRGV5yGqQiZIfwMfjkLmajCF1ZWmsinHC2b0+Bi4H0QFOR 65PA== 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=Lf81j0EfViiw5yQag7tu+GvRr1Mg3cI/hhwGiCBZiqo=; b=Jxph9YbohhRZoKpsAOLqsuNyy1S5G5NDuU3zF4J9Nud4ZTopqTU7uL0CKZTj6EXAzf 5TSlFaAXRItW1JM2pbCc861UkuWsUWXvtMQojhWkphIps3aMJQmBJfCMEGRWzaAG9eXk s2F7DDvL4xr8978Q8TSmabmDi8s2u4W1YwLCa3oUPA3oIrzg7W0wLDDBYAybZjeeWuDM +0rqG2bv51g39HS6fmjbXt0S1RlNBA7DN+uQkMYL9uPp8lLMTHtIPR4oyRFm9qE4ppbw IYltJ0tfDiF1jIstBC9BKIOwDd53wK75nBkZCcunRGZxzjs987JQWfcDbQ29diu6lNDP gieg== X-Gm-Message-State: AOAM5309AJnUNucJ+MaV26tSQZJHgEdaI5djZY7tUn4FMwP7yJn2cHuu oJlx2/GMjUtf2opHSIhoGsFt6g25X8A= X-Google-Smtp-Source: ABdhPJzJVhjGmw5OLwcODbqWUCouJ0lPLJd8szzU4+i2/K8sX/JzppvIrf7YtwP9y0gX8vfWlN664w== X-Received: by 2002:a1c:4b11:: with SMTP id y17mr5575941wma.46.1644712801838; Sat, 12 Feb 2022 16:40:01 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b10sm25898101wrd.8.2022.02.12.16.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 16:40:01 -0800 (PST) Message-Id: <679f869ff11b5c3e61081018f7eafa81c334f3d1.1644712798.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 13 Feb 2022 00:39:53 +0000 Subject: [PATCH 3/7] sparse-checkout: pay attention to prefix for {set, add} Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Victoria Dye , Derrick Stolee , Lessley Dennington , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren In cone mode, non-option arguments to set & add are clearly paths, and as such, we should pay attention to prefix. In non-cone mode, it is not clear that folks intend to provide paths since the inputs are gitignore-style patterns. Paying attention to prefix would prevent folks from doing things like git sparse-checkout add /.gitattributes git sparse-checkout add '/toplevel-dir/*' In fact, the former will result in fatal: '/.gitattributes' is outside repository... while the later will result in fatal: Invalid path '/toplevel-dir': No such file or directory despite the fact that both are valid gitignore-style patterns that would select real files if added to the sparse-checkout file. However, these commands can be run successfully from the toplevel directory, and many gitignore-style patterns ARE paths, and bash completion seems to be suggesting directories and files, so perhaps for consistency we pay attention to the prefix? It's not clear what is okay here, but maybe that's yet another reason to deprecate non-cone mode as we will do later in this series. For now, incorporate prefix into the positional arguments for either cone or non-cone mode. For additional discussion of this issue, see https://lore.kernel.org/git/29f0410e-6dfa-2e86-394d-b1fb735e7608@gmail.com/ Helped-by: Junio Hamano Signed-off-by: Elijah Newren --- builtin/sparse-checkout.c | 22 ++++++++++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 8d595189ea3..bec423d5af9 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -681,6 +681,24 @@ static int modify_pattern_list(int argc, const char **argv, int use_stdin, return result; } +static void sanitize_paths(int argc, const char **argv, const char *prefix) +{ + if (!argc) + return; + + if (prefix && *prefix) { + /* + * The args are not pathspecs, so unfortunately we + * cannot imitate how cmd_add() uses parse_pathspec(). + */ + int i; + int prefix_len = strlen(prefix); + + for (i = 0; i < argc; i++) + argv[i] = prefix_path(prefix, prefix_len, argv[i]); + } +} + static char const * const builtin_sparse_checkout_add_usage[] = { N_("git sparse-checkout add (--stdin | )"), NULL @@ -708,6 +726,8 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix) builtin_sparse_checkout_add_usage, PARSE_OPT_KEEP_UNKNOWN); + sanitize_paths(argc, argv, prefix); + return modify_pattern_list(argc, argv, add_opts.use_stdin, ADD); } @@ -759,6 +779,8 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix) if (!core_sparse_checkout_cone && argc == 0) { argv = default_patterns; argc = default_patterns_nr; + } else { + sanitize_paths(argc, argv, prefix); } return modify_pattern_list(argc, argv, set_opts.use_stdin, REPLACE); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 4a7394f7a58..b9e6987f5a6 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -816,4 +816,31 @@ test_expect_success 'malformed cone-mode patterns' ' grep "warning: disabling cone pattern matching" err ' +test_expect_success 'set from subdir pays attention to prefix' ' + git -C repo sparse-checkout disable && + git -C repo/deep sparse-checkout set --cone deeper2 ../folder1 && + + git -C repo sparse-checkout list >actual && + + cat >expect <<-\EOF && + deep/deeper2 + folder1 + EOF + test_cmp expect actual +' + +test_expect_success 'add from subdir pays attention to prefix' ' + git -C repo sparse-checkout set --cone deep/deeper2 && + git -C repo/deep sparse-checkout add deeper1/deepest ../folder1 && + + git -C repo sparse-checkout list >actual && + + cat >expect <<-\EOF && + deep/deeper1/deepest + deep/deeper2 + folder1 + EOF + test_cmp expect actual +' + test_done From patchwork Sun Feb 13 00:39:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12744466 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14BCFC43217 for ; Sun, 13 Feb 2022 00:40:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232745AbiBMAkN (ORCPT ); Sat, 12 Feb 2022 19:40:13 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232725AbiBMAkJ (ORCPT ); Sat, 12 Feb 2022 19:40:09 -0500 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 47F3A6005A for ; Sat, 12 Feb 2022 16:40:04 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id d27so17366330wrb.5 for ; Sat, 12 Feb 2022 16:40:04 -0800 (PST) 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=wMtVOKdIdUvfblmdEHAlxd8ozSGdUKNBlb2K8VUene8=; b=HeFjaF+Cs4f+6Fphp61yCsYtdIqiGVGhe2RCCkX0UTSRQg/01UuRr8Ysfg/UGBqrpE 6HMDiz3pAc9t959Ztuo+BYWjULvdS3X6CERfFZDed1AFdLuHBjIj6RTTNh9Y9dseHV4E N2Dcms5sAT7iChR4Dg4d9DERh6tAOitzKUZ2ZXjg7tb5gzl7v2ImJqhYSYbjbUC4Jc3M TKBeIHzJ3as18KeYL6b5im9UKV8f6SeFVS95xQ9YyGhUssgB8o6S91mwtrU0nDERx5jy TK1IAtqxW3N7nAtMEVSNbIWLaO+Kw1Y0t1lPeNQj1SCL9T6vTXixaqzx/oQXVzSbYL+m 27XQ== 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=wMtVOKdIdUvfblmdEHAlxd8ozSGdUKNBlb2K8VUene8=; b=dONBgwCieijg3oA2tl12gCF6nF7WzQaEb6yu3HAU6DBukq+IlxjuSx3zCINcSo1KPo obbCOWjAQ8BWrJKf5VLI0EthuE+aWsDKofwHfcaw0mZa4vUMc8NZr8MT9GcNdgKDJ2PO l1O1C0Tg8uTmrwD30nQwifbVtQgJGLF964QOS+cGQvpSN9OXLzgoLJcrELGyJXH2mysT vfSd9NoX06np7np8wcns1XKLBvk/ZyM2RgG5Z5k8Z9PO6yzH8PwhpXkVVhDmnlnYCKsC ApJZxgbJDjsBf4PAyZn6PvcEbQ1ijBnyummrOC5xnUwZ5XnRrotFQHWsGWlWpyJeHhIz tQ2A== X-Gm-Message-State: AOAM533jCTYQKrYKo89+VZ7VkTsAXDnjngxx64JnVWTWYhpWBJgGdkzY sHuhwG7b01WzZHGMW2T1GJXyF10xZBI= X-Google-Smtp-Source: ABdhPJycP0OjteDeKmUHER1i/58I3Sofc5fLgxirifix6BOFV2GWb7695IKXYFNUcD4ohNJs7atIYA== X-Received: by 2002:adf:d0c9:: with SMTP id z9mr6249147wrh.245.1644712802690; Sat, 12 Feb 2022 16:40:02 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o10sm13937436wrc.98.2022.02.12.16.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 16:40:02 -0800 (PST) Message-Id: <5e27cad17a7080170f476684610391bd56024f36.1644712798.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 13 Feb 2022 00:39:54 +0000 Subject: [PATCH 4/7] sparse-checkout: error or warn when given individual files Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Victoria Dye , Derrick Stolee , Lessley Dennington , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren The set and add subcommands accept multiple positional arguments. The meaning of these arguments differs slightly in the two modes: Cone mode only accepts directories. If given a file, it would previously treat it as a directory, causing not just the file itself to be included but all sibling files as well -- likely against users' expectations. Throw an error if the specified path is a file in the index. Provide a --skip-checks argument to allow users to override (e.g. for the case when the given path IS a directory on another branch). Non-cone mode accepts general gitignore patterns. However, it has an O(N*M) performance baked into its design, where all N index files must be matched against all M sparse-checkout patterns with EVERY call to unpack_trees() that updates the working tree. As such, it is important to keep the number of patterns small, and thus we should warn users to prefer passing directories and more generic glob patterns to get the paths they want instead of listing each individual file. (The --skip-checks argument can also be used to bypass this warning.) Also, even when users do want to specify individual files, they will often want to do so by providing a leading '/' (to avoid selecting the same filename in all subdirectories), in which case this error message would never trigger anyway. Signed-off-by: Elijah Newren --- builtin/sparse-checkout.c | 43 +++++++++++++++++++++++++----- t/t1091-sparse-checkout-builtin.sh | 16 ++++++++++- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index bec423d5af9..8f8d2bd6ba5 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "cache.h" #include "config.h" #include "dir.h" #include "parse-options.h" @@ -681,8 +682,11 @@ static int modify_pattern_list(int argc, const char **argv, int use_stdin, return result; } -static void sanitize_paths(int argc, const char **argv, const char *prefix) +static void sanitize_paths(int argc, const char **argv, + const char *prefix, int skip_checks) { + int i; + if (!argc) return; @@ -691,26 +695,49 @@ static void sanitize_paths(int argc, const char **argv, const char *prefix) * The args are not pathspecs, so unfortunately we * cannot imitate how cmd_add() uses parse_pathspec(). */ - int i; int prefix_len = strlen(prefix); for (i = 0; i < argc; i++) argv[i] = prefix_path(prefix, prefix_len, argv[i]); } + + if (skip_checks) + return; + + for (i = 0; i < argc; i++) { + struct cache_entry *ce; + struct index_state *index = the_repository->index; + int pos = index_name_pos(index, argv[i], strlen(argv[i])); + + if (pos < 0) + continue; + ce = index->cache[pos]; + if (S_ISSPARSEDIR(ce->ce_mode)) + continue; + + if (core_sparse_checkout_cone) + die(_("\"%s\" is not a directory; to treat it as a directory anyway, rerun with --skip-checks"), argv[i]); + else + warning(_("path \"%s\" is an individual file; passing directories or less specific patterns is recommended (see NON-CONE PROBLEMS in the git-sparse-checkout manual)."), argv[i]); + } } static char const * const builtin_sparse_checkout_add_usage[] = { - N_("git sparse-checkout add (--stdin | )"), + N_("git sparse-checkout add [--skip-checks] (--stdin | )"), NULL }; static struct sparse_checkout_add_opts { + int skip_checks; int use_stdin; } add_opts; static int sparse_checkout_add(int argc, const char **argv, const char *prefix) { static struct option builtin_sparse_checkout_add_options[] = { + OPT_BOOL_F(0, "skip-checks", &add_opts.skip_checks, + N_("skip some sanity checks on the given paths that might give false positives"), + PARSE_OPT_NONEG), OPT_BOOL(0, "stdin", &add_opts.use_stdin, N_("read patterns from standard in")), OPT_END(), @@ -726,19 +753,20 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix) builtin_sparse_checkout_add_usage, PARSE_OPT_KEEP_UNKNOWN); - sanitize_paths(argc, argv, prefix); + sanitize_paths(argc, argv, prefix, add_opts.skip_checks); return modify_pattern_list(argc, argv, add_opts.use_stdin, ADD); } static char const * const builtin_sparse_checkout_set_usage[] = { - N_("git sparse-checkout set [--[no-]cone] [--[no-]sparse-index] (--stdin | )"), + N_("git sparse-checkout set [--[no-]cone] [--[no-]sparse-index] [--skip-checks] (--stdin | )"), NULL }; static struct sparse_checkout_set_opts { int cone_mode; int sparse_index; + int skip_checks; int use_stdin; } set_opts; @@ -752,6 +780,9 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix) N_("initialize the sparse-checkout in cone mode")), OPT_BOOL(0, "sparse-index", &set_opts.sparse_index, N_("toggle the use of a sparse index")), + OPT_BOOL_F(0, "skip-checks", &set_opts.skip_checks, + N_("skip some sanity checks on the given paths that might give false positives"), + PARSE_OPT_NONEG), OPT_BOOL_F(0, "stdin", &set_opts.use_stdin, N_("read patterns from standard in"), PARSE_OPT_NONEG), @@ -780,7 +811,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix) argv = default_patterns; argc = default_patterns_nr; } else { - sanitize_paths(argc, argv, prefix); + sanitize_paths(argc, argv, prefix, set_opts.skip_checks); } return modify_pattern_list(argc, argv, set_opts.use_stdin, REPLACE); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index b9e6987f5a6..1d95fa47258 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -580,7 +580,7 @@ test_expect_success 'different sparse-checkouts with worktrees' ' ' test_expect_success 'set using filename keeps file on-disk' ' - git -C repo sparse-checkout set a deep && + git -C repo sparse-checkout set --skip-checks a deep && cat >expect <<-\EOF && /* !/*/ @@ -843,4 +843,18 @@ test_expect_success 'add from subdir pays attention to prefix' ' test_cmp expect actual ' +test_expect_success 'by default, cone mode will error out when passed files' ' + git -C repo sparse-checkout reapply --cone && + test_must_fail git -C repo sparse-checkout add .gitignore 2>error && + + grep ".gitignore.*is not a directory" error +' + +test_expect_success 'by default, non-cone mode will warn on individual files' ' + git -C repo sparse-checkout reapply --no-cone && + git -C repo sparse-checkout add .gitignore 2>warning && + + grep "passing directories or less specific patterns is recommended" warning +' + test_done From patchwork Sun Feb 13 00:39:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12744468 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5CE4C433EF for ; Sun, 13 Feb 2022 00:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbiBMAkO (ORCPT ); Sat, 12 Feb 2022 19:40:14 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232727AbiBMAkJ (ORCPT ); Sat, 12 Feb 2022 19:40:09 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 290686005E for ; Sat, 12 Feb 2022 16:40:05 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id k3-20020a1ca103000000b0037bdea84f9cso8616459wme.1 for ; Sat, 12 Feb 2022 16:40:05 -0800 (PST) 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=87B8g00aRBUIF982wcafTYUkZmMVb2hLgP1kfIXtpRo=; b=jm8tU4drgVxHtrsOcP+GeJ/xUnOnUJJkpvsSoxbQ89Hz0+oBvLQZfVuIOw9oMIIlJE l5GtYtLOA1iUUY77soMMCA0PngW5+5wyUrAGbnHaPqsQ2Dlv/QXxg2lCx6S4hvy75+h7 W8dWCKFlN7yoScGlPBCzDcXyGH3ZqA4/1wNSYdBE5bTW1idodES7ku7d2rsscv8ytHBs 2QtOTIDMvk71B8/HL8I5jQO6rdhP4TyyaPUQlfOt64bzuookjeuyI5LIMQuFNkiPFPet y69fAtFB0bBv+KZE97WQFcOnJtCo2uvbLFDBMy98B/co6ZENC8AntVesftOo3fCCOuIL W17g== 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=87B8g00aRBUIF982wcafTYUkZmMVb2hLgP1kfIXtpRo=; b=5PY88dJfJoFSQJbNlCBmdDxYLStqZ7F3GutNqCGK/vV+HkVLRJJ0bH8m3XRVVD21At ahCjk1jNH9jsoMLHoe/36JsZrfwQImoqLKFek0Hvs1hUglsudHpq85dfcBvTl/tjlDLZ 4u39E67RQ8NLsaXGbX+8vGPNki3mNbhoKxbRGHw3ELtyBPZK6k1jC4P5SKuUbdl5WSXB zNVX7VKOBFQaHak9Q+Yl/DTDHpLmy64KfNxmcG/un3iybxNAP5XtQg8Ma+mpGD/byY7V UhLdTCK1hD9gzSmcVWOwELK6WFrM6t82V+A4qGRdJSqKMPlY+lekurolu0Q6dJoYZKyy oWZw== X-Gm-Message-State: AOAM533DTPsGwVeiXWYrkhEI8oSbi2WXBB32mPBomAoMbXEV7LHL21WT kvYaKW+RhPT2qcRFvyrp/hjZr4/wH+E= X-Google-Smtp-Source: ABdhPJw0hLdttstIcnrCwkRrlNqf0YoBZqXqMZ8+tbsaiTI/N+YdwznXgV2ii6qFiZypWsxoaMCA+g== X-Received: by 2002:a05:600c:601a:: with SMTP id az26mr5663234wmb.2.1644712803587; Sat, 12 Feb 2022 16:40:03 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k34sm6869991wms.35.2022.02.12.16.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 16:40:03 -0800 (PST) Message-Id: <265cbe36b2df5a9a076877fe3ddc3880a64a9217.1644712798.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 13 Feb 2022 00:39:55 +0000 Subject: [PATCH 5/7] sparse-checkout: reject non-cone-mode patterns starting with a '#' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Victoria Dye , Derrick Stolee , Lessley Dennington , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren In sparse-checkout add/set, in cone mode any specified directories will be transformed into appropriate patterns. In non-cone mode, the non-option arguments are treated as patterns. Since .git/info/sparse-checkout will ignore any patterns starting with a '#' (they are just gitignore patterns), if the user passes an argument starting with a '#' to sparse-checkout add/set in non-cone mode, it would just be treated as a comment and ignored. Error out in such cases, informing the user that they need to backslash escape it. Signed-off-by: Elijah Newren --- builtin/sparse-checkout.c | 5 +++++ t/t1091-sparse-checkout-builtin.sh | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 8f8d2bd6ba5..0f9e737ed97 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -704,6 +704,11 @@ static void sanitize_paths(int argc, const char **argv, if (skip_checks) return; + if (!core_sparse_checkout_cone) + for (i = 0; i < argc; i++) + if (argv[i][0] == '#') + die(_("paths beginning with a '#' must be preceeded by a backslash")); + for (i = 0; i < argc; i++) { struct cache_entry *ce; struct index_state *index = the_repository->index; diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 1d95fa47258..32b77415679 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -857,4 +857,10 @@ test_expect_success 'by default, non-cone mode will warn on individual files' ' grep "passing directories or less specific patterns is recommended" warning ' +test_expect_success 'paths starting with hash must be escaped in non-cone mode' ' + test_must_fail git -C repo sparse-checkout set --no-cone "#funny-path" 2>error && + + grep "paths beginning.*#.*must be preceeded by a backslash" error +' + test_done From patchwork Sun Feb 13 00:39:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12744467 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6A62C433F5 for ; Sun, 13 Feb 2022 00:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232770AbiBMAkQ (ORCPT ); Sat, 12 Feb 2022 19:40:16 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232728AbiBMAkK (ORCPT ); Sat, 12 Feb 2022 19:40:10 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CA5D60061 for ; Sat, 12 Feb 2022 16:40:06 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id j26so10314390wrb.7 for ; Sat, 12 Feb 2022 16:40:05 -0800 (PST) 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=brGviHVD/ER7adMOJxV+OlzowtgFiRjqrVrbut9m81o=; b=SINSBP7wMys/sjgbGKngC+cxzWcEeWEI0iTNMvRJErnUPnBgMf95Bg1ecL+oNXA83D ccxbwJQcejp9JpqRQn4iz9HYcVablvYfTKJoM+54RMxSS+CjKqtps01RF31SG8afFyeM ivclkk/f3XGAC82SCRcKXYWG+Nexxjw6UqmWgs3RFoL1NkQurhS6duyNniEpbI8pDZjB wolt9FAHMObW2Q1OahcJNqeqpZ6MnJM0WZONRq+F5Y9BbwhIiSSM20EeicO8WiluMeT7 dqRCOJqYXo1JiUkoNJONJTIBV17s225nVSQlTQ8Cb2Uxr0hkA/rK1QgaWL9UK5XLNNhY RiMA== 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=brGviHVD/ER7adMOJxV+OlzowtgFiRjqrVrbut9m81o=; b=c5a+6fxq1UTC8BQOikAfeHBgGmHYpZ3RcUATcBk8LRLCsjxZYzSGG+msLKlMTCHe37 s0C1meaASX8VdKuvDHdkI4RU9cD7wJKrW6VWqXb/Shgny4qUkxw8zQ0eWfpHldVEjmdR gKoO/PIv9Mm9eLbmJCXRGpHA98PlQWVi7l6zi4M+H4dZqDXSs7JrWGL2hluijog8sAuT UXBudx304+GNZTXvMjOqAZb70JVYhQoZDQ7nJE/y/2wuPaVsWOFD+V6PxO46eR7spKOj IPa9FFxcHJjIe3fgyF2AgtRMfBSoStDra4w8gWj2fHyiv+QT3A6hwRry68af1xR1045E XE5w== X-Gm-Message-State: AOAM532smPIn7wTNaeMngzMh+TaZM5rK3rZj7ToK9xsPMMymGjgNGQzZ KI2dLtf5rZ1FMskhzGWrsRIrT+/7LDQ= X-Google-Smtp-Source: ABdhPJxRk/UQWYiOocThS3k4oSZdk6bXTggHxcMItM+glMOwWumN6Sr6KdVjCu4Strlu4rJFgwFDxg== X-Received: by 2002:a5d:4bc7:: with SMTP id l7mr6362135wrt.230.1644712804455; Sat, 12 Feb 2022 16:40:04 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o16sm13298260wrn.87.2022.02.12.16.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 16:40:03 -0800 (PST) Message-Id: <502da48b8f43e2c5a67d5519ac7aacf80accd818.1644712798.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 13 Feb 2022 00:39:56 +0000 Subject: [PATCH 6/7] sparse-checkout: reject arguments in cone-mode that look like patterns Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Victoria Dye , Derrick Stolee , Lessley Dennington , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren In sparse-checkout add/set under cone mode, the arguments passed are supposed to be directories rather than gitignore-style patterns. However, given the amount of effort spent in the manual discussing patterns, it is easy for users to assume they need to pass patterns such as /foo/* or !/bar/*/ or perhaps they really do ignore the directory rule and specify a random gitignore-style pattern like *.c To help catch such mistakes, throw an error if any of the positional arguments: * starts with any of '/!' * contains any of '*\?[]' Inform users they can pass --skip-checks if they have a directory that really does have such special characters in its name. Signed-off-by: Elijah Newren --- builtin/sparse-checkout.c | 16 ++++++++++++++-- t/t1091-sparse-checkout-builtin.sh | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 0f9e737ed97..6e0af166f80 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -704,10 +704,22 @@ static void sanitize_paths(int argc, const char **argv, if (skip_checks) return; - if (!core_sparse_checkout_cone) - for (i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { + if (core_sparse_checkout_cone) { + if (argv[i][0] == '/') + die(_("specify directories rather than patterns (no leading slash)")); + if (argv[i][0] == '!') + die(_("specify directories rather than patterns. If your directory starts with a '!', pass --skip-checks")); + if (strchr(argv[i], '*') || + strchr(argv[i], '?') || + strchr(argv[i], '[') || + strchr(argv[i], ']')) + die(_("specify directories rather than patterns. If your directory really has any of '*?[]' in it, pass --skip-checks")); + } else { if (argv[i][0] == '#') die(_("paths beginning with a '#' must be preceeded by a backslash")); + } + } for (i = 0; i < argc; i++) { struct cache_entry *ce; diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 32b77415679..343ce16a534 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -691,7 +691,7 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' ' git -C escaped reset --hard $COMMIT && check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? && git -C escaped sparse-checkout init --cone && - git -C escaped sparse-checkout set zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" && + git -C escaped sparse-checkout set --skip-checks zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" && cat >expect <<-\EOF && /* !/*/ From patchwork Sun Feb 13 00:39:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12744469 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4C2CC4332F for ; Sun, 13 Feb 2022 00:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232803AbiBMAkR (ORCPT ); Sat, 12 Feb 2022 19:40:17 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232740AbiBMAkM (ORCPT ); Sat, 12 Feb 2022 19:40:12 -0500 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 241C960063 for ; Sat, 12 Feb 2022 16:40:07 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id u1so7404463wrg.11 for ; Sat, 12 Feb 2022 16:40:07 -0800 (PST) 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=z9ZjyuUbCFmXJ+QFmd5JFTucKVhEzd4nfQj2WDALRHg=; b=YaeN440/APSz4qfXzw7T3L/qPO57Ff9Sy+y/HrUR4shtMibUf4LgktEvl48JLQlGkj mjTRfaV9dTWe8GuUS1zUgKK/JyEj+ZcBOxG+iUjFcxiRPoo4Rhkn0AMsAavUefIPFp54 KsG1E60BlnW0QMZ179CW+UYf2GO58XBbIYbw4aaEReKbhzwxa+1Lg62b7pZ5lGEkW1aQ ikw+a7VhMSlyPri6n0+RwRVj1/MKAysU6hkvSlywrw9YpEqlCiqDSlng5h/heCdlw/Qi RXWE4jxfspJ/g7r+h5n+XncOPj5Ijh8ykUmFb06VbI2ErqlBxxF1Xyp9QfpvUOHhkNJg 9bTw== 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=z9ZjyuUbCFmXJ+QFmd5JFTucKVhEzd4nfQj2WDALRHg=; b=LKxjkYb0/UlP9dDFJOK0jS0t+49Kymfr17qLRQUac6KO+hGvYL4FbnGFCZvLEvA6ch waRXvIZlJuZUDDKJMX85a/wKGAkuFp9PeNiMpgVqPZJejTUa7tOVFljFlRCNkkRBWvE7 T8vBxDK32N9ArgRy3MlGu1GX0BH7lhbofN8eKq/W4Lo+yIr/OXbM9ssEJ2TpJew6GiwK EEmZ8EcM9/oAea7M/g/LG2DxrhFyo96EHPgQUUzIHcSOuMWBoLdIvayDqEb8H5EIIqN5 9Ra6GWEHIWYhamNvO0rdYUCC8st+ea0w2eGZbL/r7fvCKEL57P4cHSmQPX1HiOk7NXBz L+5A== X-Gm-Message-State: AOAM530O6mLYLM42hir2TOjeKx0KzzBj7/pyhMXHmqtx+89VXrz5uIlu ZJjlK5xkksq9YEkBSCnZrNXhahn1UFs= X-Google-Smtp-Source: ABdhPJzCrhN4mIB+uEE90KjEBBCo6/Tz6g0xBIG19x6z6IHIKPynn9PBC+JoLedvUiHMOt2fvQqNlg== X-Received: by 2002:a5d:468a:: with SMTP id u10mr6270998wrq.273.1644712805271; Sat, 12 Feb 2022 16:40:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 1sm7451415wmk.16.2022.02.12.16.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 16:40:04 -0800 (PST) Message-Id: In-Reply-To: References: Date: Sun, 13 Feb 2022 00:39:57 +0000 Subject: [PATCH 7/7] sparse-checkout: make --cone the default and deprecate --no-cone Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Victoria Dye , Derrick Stolee , Lessley Dennington , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Make --cone mode the default, and deprecate --no-cone mode. While we have no current plans to actually remove --no-cone mode, we think users would be better off not using it. Update the documentation accordingly, including explaining why we think non-cone mode is problematic for users. While at it, since the new default just uses directories and removes the need to understand patterns, we can mark multiple sections in the manual as "INTERNALS" to reflect the fact that users do not need to wade through those sections to understand how to use the command any more. We can instead add a simple EXAMPLES section to the manual which distills the necessary bits from the more complex INTERNALS sections. Signed-off-by: Elijah Newren --- Documentation/git-sparse-checkout.txt | 228 +++++++++++++++++++------- builtin/sparse-checkout.c | 8 +- t/t1091-sparse-checkout-builtin.sh | 15 +- t/t3602-rm-sparse-checkout.sh | 6 +- t/t3705-add-sparse-checkout.sh | 4 +- t/t6428-merge-conflicts-sparse.sh | 4 +- t/t7002-mv-sparse-checkout.sh | 2 +- t/t7012-skip-worktree-writing.sh | 2 +- 8 files changed, 190 insertions(+), 79 deletions(-) diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt index 88e55f432f3..abe8c796313 100644 --- a/Documentation/git-sparse-checkout.txt +++ b/Documentation/git-sparse-checkout.txt @@ -42,11 +42,11 @@ COMMANDS 'set':: Enable the necessary sparse-checkout config settings - (`core.sparseCheckout`, `core.sparseCheckoutCone`, and - `index.sparse`) if they are not already set to the desired values, - and write a set of patterns to the sparse-checkout file from the - list of arguments following the 'set' subcommand. Update the - working directory to match the new patterns. + (`extensions.worktreeConfig`, `core.sparseCheckout`, + `core.sparseCheckoutCone`, and `index.sparse`) if they are not + already set to the desired values, populate the sparse-checkout + file from the list of arguments following the 'set' subcommand, + and update the working directory to match. + To ensure that adjusting the sparse-checkout settings within a worktree does not alter the sparse-checkout settings in other worktrees, the 'set' @@ -60,22 +60,24 @@ When the `--stdin` option is provided, the directories or patterns are read from standard in as a newline-delimited list instead of from the arguments. + -When `--cone` is passed or `core.sparseCheckoutCone` is enabled, the -input list is considered a list of directories. This allows for -better performance with a limited set of patterns (see 'CONE PATTERN -SET' below). The input format matches the output of `git ls-tree ---name-only`. This includes interpreting pathnames that begin with a -double quote (") as C-style quoted strings. Note that the set command -will write patterns to the sparse-checkout file to include all files -contained in those directories (recursively) as well as files that are -siblings of ancestor directories. This may become the default in the -future; --no-cone can be passed to request non-cone mode. +By default, the input list is considered a list of directories, matching +the output of `git ls-tree -d --name-only`. This includes interpreting +pathnames that begin with a double quote (") as C-style quoted strings. +Note that all files under the specified directories (at any depth) will +be included in the sparse checkout, as well as files that are siblings +of either the given directory or any of its ancestors (see 'CONE PATTERN +SET' below for more details). In the past, this was not the default, +and `--cone` needed to be specified or `core.sparseCheckoutCone` needed +to be enabled. + -When `--no-cone` is passed or `core.sparseCheckoutCone` is not enabled, -the input list is considered a list of patterns. This mode is harder -to use and less performant, and is thus not recommended. See the -"Sparse Checkout" section of linkgit:git-read-tree[1] and the "Pattern -Set" sections below for more details. +When `--no-cone` is passed, the input list is considered a list of +patterns. This mode is harder to use, and unless you can keep the +number of patterns very small, its design also scales quite poorly. It +used to be the default mode, but we do not recommend using it. It does +not work with the `--sparse-index` option, and will likely be +incompatible with other new features as they are added. See the +"Non-cone Problems" section below and the "Sparse Checkout" section of +linkgit:git-read-tree[1] for more details. + Use the `--[no-]sparse-index` option to use a sparse index (the default is to not use it). A sparse index reduces the size of the @@ -137,8 +139,44 @@ paths to pass to a subsequent 'set' or 'add' command. However, the disable command, so the easy restore of calling a plain `init` decreased in utility. -SPARSE CHECKOUT ---------------- +EXAMPLES +-------- +`git sparse-checkout set MY/DIR1 SUB/DIR2`:: + + Change to a sparse-checkout with all files (at any depth) under + MY/DIR1/ and SUB/DIR2/ present in the working copy (plus all + files immediately under MY/ and SUB/ and the toplevel + directory). If already in a sparse checkout, change which files + are present in the working copy to this new selection. Note + that this command will also delete all ignored files in any + directory that no longer has either tracked or + non-ignored-untracked files present. + +`git sparse-checkout disable`:: + + Repopulate the working directory with all files, disabling sparse + checkouts. + +`git sparse-checkout add SOME/DIR/ECTORY`:: + + Add all files under SOME/DIR/ECTORY/ (at any depth) to the + sparse checkout, as well as all files immediately under + SOME/DIR/ and immediately under SOME/. Must already be in a + sparse checkout before using this command. + +`git sparse-checkout reapply`:: + + It is possible for commands to update the working tree in a way + that does not respect the selected sparsity directories, either + because of special cases (such as hitting conflicts when + merging/rebasing), or because some commands didn't fully support + sparse checkouts (e.g. the old `recursive` merge backend had + only limited support). This command reapplies the existing + sparse directory specifications to make the working directory + match. + +INTERNALS -- SPARSE CHECKOUT +---------------------------- "Sparse checkout" allows populating the working directory sparsely. It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell Git @@ -155,22 +193,93 @@ directory, it updates the skip-worktree bits in the index based on this file. The files matching the patterns in the file will appear in the working directory, and the rest will not. -To enable the sparse-checkout feature, run `git sparse-checkout set` to -set the patterns you want to use. - -To repopulate the working directory with all files, use the -`git sparse-checkout disable` command. - - -FULL PATTERN SET ----------------- - -By default, the sparse-checkout file uses the same syntax as `.gitignore` -files. - -While `$GIT_DIR/info/sparse-checkout` is usually used to specify what -files are included, you can also specify what files are _not_ included, -using negative patterns. For example, to remove the file `unwanted`: +INTERNALS -- NON-CONE PROBLEMS +------------------------------ + +The `$GIT_DIR/info/sparse-checkout` file populated by the `set` and +`add` subcommands is defined to be a bunch of patterns (one per line) +using the same syntax as `.gitignore` files. In cone mode, these +patterns are restricted to matching directories (and users only ever +need supply or see directory names), while in non-cone mode any +gitignore-style pattern is permitted. Using the full gitignore-style +patterns in non-cone mode has a number of shortcomings: + + * Fundamentally, it makes various worktree-updating processes (pull, + merge, rebase, switch, reset, checkout, etc.) require O(N*M) pattern + matches, where N is the number of patterns and M is the number of + paths in the index. This scales poorly. + + * Avoiding the scaling issue means selecting paths via leading + directory name or glob. Passing globs on the command line is + error-prone as users may forget to quote the glob, causing the + shell to expand it into all matching files and pass them all + individually along to sparse-checkout set/add. This both + exacerbates the scaling problem, and hardcodes the list of + selected files to those which were present at the time the initial + set/add subcommand was run (and thus ignoring other files matching + the same glob which come into the working tree after switching + branches or pulling down updates). + + * It uses "ignore"/"exclude" syntax for selecting what to "include", + which periodically causes confusion. + + * It introduces inconsistencies in the Git command line, since other + commands use pathspecs, but sparse-checkout (in non-cone mode) uses + gitignore patterns. + + * It has edge cases where the "right" behavior is unclear. Two examples: + + First, two users are in a subdirectory, and the first runs + git sparse-checkout set '/toplevel-dir/*.c' + while the second runs + git sparse-checkout set relative-dir + Should those arguments be transliterated into + current/subdirectory/toplevel-dir/*.c + and + current/subdirectory/relative-dir + before inserting into the sparse-checkout file? The user who typed + the first command is probably aware that arguments to set/add are + supposed to be patterns in non-cone mode, and probably would not be + happy with such a transliteration. However, many gitignore-style + patterns are just paths, which might be what the user who typed the + second command was thinking, and they'd be upset if their argument + wasn't transliterated. + + Second, what should bash-completion complete on for set/add commands + for non-cone users? If it suggests paths, is it exacerbating the + problem above? Also, if it suggests paths, what if the user has a + file or directory that begins with either a '!' or '#' or has a '*', + '\', '?', '[', or ']' in its name? And if it suggests paths, will + it complete "/pro" to "/proc" (in the root filesytem) rather than to + "/progress.txt" in the current directory? (Note that users are + likely to want to start paths with a leading '/' in non-cone mode, + for the same reason that .gitignore files often have one.) + Completing on files or directories might give nasty surprises in + all these cases. + + * The excessive flexibility made other extensions essentially + impractical. `--sparse-index` may not have been feasible in + non-cone mode, but even if it was, it would have been far more work + to implement and may have been too slow in practice. Some ideas for + adding coupling between partial clones and sparse-checkouts are only + practical with a more restricted set of paths. + +For all these reasons, non-cone mode is deprecated. Please switch to +using cone mode. + +INTERNALS -- FULL PATTERN SET +----------------------------- + +As noted above, the sparse-checkout file uses the same syntax as +`.gitignore` files; see linkgit:gitignore[5] for details. Here, though, +the patterns are being used to select which files to include rather than +which files to exclude. + +To complicate things a bit further, while +`$GIT_DIR/info/sparse-checkout` is usually used to specify what files +are included, you can also specify what files are _not_ included, using +negative patterns. For example, to select everything, and then to remove +the file `unwanted`: ---------------- /* @@ -178,14 +287,14 @@ using negative patterns. For example, to remove the file `unwanted`: ---------------- -CONE PATTERN SET ----------------- +INTERNALS -- CONE PATTERN SET +----------------------------- -The full pattern set allows for arbitrary pattern matches and complicated -inclusion/exclusion rules. These can result in O(N*M) pattern matches when -updating the index, where N is the number of patterns and M is the number -of paths in the index. To combat this performance issue, a more restricted -pattern set is allowed when `core.sparseCheckoutCone` is enabled. +The full pattern set allows for arbitrary pattern matches and +complicated inclusion/exclusion rules. As noted above, this can result +in O(N*M) pattern matches when updating the index, where N is the number +of patterns and M is the number of paths in the index. To combat this +performance issue, a more restricted pattern set is used by default. The accepted patterns in the cone pattern set are: @@ -197,9 +306,9 @@ In addition to the above two patterns, we also expect that all files in the root directory are included. If a recursive pattern is added, then all leading directories are added as parent patterns. -By default, when running `git sparse-checkout init`, the root directory is -added as a parent pattern. At this point, the sparse-checkout file contains -the following patterns: +By default, when running `git sparse-checkout set` with no directories +specified, the root directory is added as a parent pattern. At this +point, the sparse-checkout file contains the following patterns: ---------------- /* @@ -208,11 +317,11 @@ the following patterns: This says "include everything in root, but nothing two levels below root." -When in cone mode, the `git sparse-checkout set` subcommand takes a list of -directories instead of a list of sparse-checkout patterns. In this mode, -the command `git sparse-checkout set A/B/C` sets the directory `A/B/C` as -a recursive pattern, the directories `A` and `A/B` are added as parent -patterns. The resulting sparse-checkout file is now +When in cone mode, the `git sparse-checkout set` subcommand takes a list +of directories. In this mode, the command `git sparse-checkout set +A/B/C` sets the directory `A/B/C` as a recursive pattern, the +directories `A` and `A/B` are added as parent patterns. The resulting +sparse-checkout file is now ---------------- /* @@ -227,10 +336,11 @@ patterns. The resulting sparse-checkout file is now Here, order matters, so the negative patterns are overridden by the positive patterns that appear lower in the file. -If `core.sparseCheckoutCone=true`, then Git will parse the sparse-checkout file -expecting patterns of these types. Git will warn if the patterns do not match. -If the patterns do match the expected format, then Git will use faster hash- -based algorithms to compute inclusion in the sparse-checkout. +If `core.sparseCheckoutCone=true` (set by default or with an explicit +`--cone`), then Git will parse the sparse-checkout file expecting +patterns of these types. Git will warn if the patterns do not match. If +the patterns do match the expected format, then Git will use faster +hash- based algorithms to compute inclusion in the sparse-checkout. In the cone mode case, the `git sparse-checkout list` subcommand will list the directories that define the recursive patterns. For the example sparse-checkout @@ -257,8 +367,8 @@ use `git add` and `git commit` to store them, then remove any remaining files manually to ensure Git can behave optimally. -SUBMODULES ----------- +INTERNALS -- SUBMODULES +----------------------- If your repository contains one or more submodules, then submodules are populated based on interactions with the `git submodule` command. diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 6e0af166f80..aa2c66f15e3 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -395,13 +395,13 @@ static int update_modes(int *cone_mode, int *sparse_index) /* Set cone/non-cone mode appropriately */ core_apply_sparse_checkout = 1; - if (*cone_mode == 1) { + if (*cone_mode == 1 || *cone_mode == -1) { mode = MODE_CONE_PATTERNS; - core_sparse_checkout_cone = 1; + if (record_mode) + core_sparse_checkout_cone = 1; } else { mode = MODE_ALL_PATTERNS; - if (record_mode) - core_sparse_checkout_cone = 0; + core_sparse_checkout_cone = 0; } if (record_mode && set_config(mode)) return 1; diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 343ce16a534..5e1a6d91411 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -72,7 +72,7 @@ test_expect_success 'git sparse-checkout list (populated)' ' ' test_expect_success 'git sparse-checkout init' ' - git -C repo sparse-checkout init && + git -C repo sparse-checkout init --no-cone && cat >expect <<-\EOF && /* !/*/ @@ -111,6 +111,7 @@ test_expect_success 'init with existing sparse-checkout' ' test_expect_success 'clone --sparse' ' git clone --sparse "file://$(pwd)/repo" clone && + git -C clone sparse-checkout reapply --no-cone && git -C clone sparse-checkout list >actual && cat >expect <<-\EOF && /* @@ -124,7 +125,7 @@ test_expect_success 'switching to cone mode with non-cone mode patterns' ' git init bad-patterns && ( cd bad-patterns && - git sparse-checkout init && + git sparse-checkout init --no-cone && git sparse-checkout add dir && git config --worktree core.sparseCheckoutCone true && test_must_fail git sparse-checkout add dir 2>err && @@ -402,7 +403,7 @@ test_expect_success 'revert to old sparse-checkout on empty update' ' git sparse-checkout set nothing 2>err && test_i18ngrep ! "Sparse checkout leaves no entry on working directory" err && test_i18ngrep ! ".git/index.lock" err && - git sparse-checkout set file + git sparse-checkout set --no-cone file ) ' @@ -424,7 +425,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' git clone repo dirty && echo dirty >dirty/folder1/a && - git -C dirty sparse-checkout init 2>err && + git -C dirty sparse-checkout init --no-cone 2>err && test_i18ngrep "warning.*The following paths are not up to date" err && git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err && @@ -435,7 +436,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' test_must_be_empty err && git -C dirty reset --hard && - git -C dirty sparse-checkout init && + git -C dirty sparse-checkout init --no-cone && git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* && test_path_is_missing dirty/folder1/a && git -C dirty sparse-checkout disable && @@ -451,7 +452,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged stat EOF git -C unmerged update-index --index-info err && + git -C unmerged sparse-checkout init --no-cone 2>err && test_i18ngrep "warning.*The following paths are unmerged" err && git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* 2>err && @@ -462,7 +463,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged stat test_i18ngrep "warning.*The following paths are unmerged" err && git -C unmerged reset --hard && - git -C unmerged sparse-checkout init && + git -C unmerged sparse-checkout init --no-cone && git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* && git -C unmerged sparse-checkout disable ' diff --git a/t/t3602-rm-sparse-checkout.sh b/t/t3602-rm-sparse-checkout.sh index 034ec010910..08580fd3dcc 100755 --- a/t/t3602-rm-sparse-checkout.sh +++ b/t/t3602-rm-sparse-checkout.sh @@ -30,7 +30,7 @@ test_expect_success 'setup' " for opt in "" -f --dry-run do test_expect_success "rm${opt:+ $opt} does not remove sparse entries" ' - git sparse-checkout set a && + git sparse-checkout set --no-cone a && test_must_fail git rm $opt b 2>stderr && test_cmp b_error_and_hint stderr && git ls-files --error-unmatch b @@ -118,7 +118,7 @@ test_expect_success 'can remove files from non-sparse dir' ' test_commit w/f && test_commit x/y/f && - git sparse-checkout set w !/x y/ && + git sparse-checkout set --no-cone w !/x y/ && git rm w/f.t x/y/f.t 2>stderr && test_must_be_empty stderr ' @@ -128,7 +128,7 @@ test_expect_success 'refuse to remove non-skip-worktree file from sparse dir' ' git sparse-checkout disable && mkdir -p x/y/z && test_commit x/y/z/f && - git sparse-checkout set !/x y/ !x/y/z && + git sparse-checkout set --no-cone !/x y/ !x/y/z && git update-index --no-skip-worktree x/y/z/f.t && test_must_fail git rm x/y/z/f.t 2>stderr && diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 95609046c61..2bade9e804f 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -166,7 +166,7 @@ test_expect_success 'do not warn when pathspec matches dense entries' ' test_expect_success 'git add fails outside of sparse-checkout definition' ' test_when_finished git sparse-checkout disable && test_commit a && - git sparse-checkout init && + git sparse-checkout init --no-cone && git sparse-checkout set a && echo >>sparse_entry && @@ -208,7 +208,7 @@ test_expect_success 'add obeys advice.updateSparsePath' ' ' test_expect_success 'add allows sparse entries with --sparse' ' - git sparse-checkout set a && + git sparse-checkout set --no-cone a && echo modified >sparse_entry && test_must_fail git add sparse_entry && test_sparse_entry_unchanged && diff --git a/t/t6428-merge-conflicts-sparse.sh b/t/t6428-merge-conflicts-sparse.sh index 142c9aaabc5..064be1b629e 100755 --- a/t/t6428-merge-conflicts-sparse.sh +++ b/t/t6428-merge-conflicts-sparse.sh @@ -87,7 +87,7 @@ test_expect_success 'conflicting entries written to worktree even if sparse' ' test_path_is_file numerals && git sparse-checkout init && - git sparse-checkout set README && + git sparse-checkout set --no-cone README && test_path_is_file README && test_path_is_missing numerals && @@ -123,7 +123,7 @@ test_expect_success 'present-despite-SKIP_WORKTREE handled reasonably' ' test_path_is_file numerals && git sparse-checkout init && - git sparse-checkout set README && + git sparse-checkout set --no-cone README && test_path_is_file README && test_path_is_missing numerals && diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index 1d3d2aca21c..f0f7cbfcdb7 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -27,7 +27,7 @@ test_expect_success 'setup' " test_expect_success 'mv refuses to move sparse-to-sparse' ' test_when_finished rm -f e && git reset --hard && - git sparse-checkout set a && + git sparse-checkout set --no-cone a && touch b && test_must_fail git mv b e 2>stderr && cat sparse_error_header >expect && diff --git a/t/t7012-skip-worktree-writing.sh b/t/t7012-skip-worktree-writing.sh index cb9f1a6981e..cd5c20fe51b 100755 --- a/t/t7012-skip-worktree-writing.sh +++ b/t/t7012-skip-worktree-writing.sh @@ -151,7 +151,7 @@ test_expect_success 'stash restore in sparse checkout' ' git stash push && - git sparse-checkout set subdir && + git sparse-checkout set --no-cone subdir && # Ensure after sparse-checkout we only have expected files cat >expect <<-EOF &&