From patchwork Sun Sep 12 13:23:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486891 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.8 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 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 E65A7C433EF for ; Sun, 12 Sep 2021 13:23:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2D6161056 for ; Sun, 12 Sep 2021 13:23:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235325AbhILNYt (ORCPT ); Sun, 12 Sep 2021 09:24:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235203AbhILNYs (ORCPT ); Sun, 12 Sep 2021 09:24:48 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30667C061757 for ; Sun, 12 Sep 2021 06:23:34 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id k5-20020a05600c1c8500b002f76c42214bso4930566wms.3 for ; Sun, 12 Sep 2021 06:23:34 -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=IiS3fEfviUExWgb8WB/VoOys2Wk2rRgn6Qzz5WQY2aU=; b=chJgrHeMjnJup3YJPvDRoBTlhU3w/xfdRXxz/zlJEMN7wBwuxucDL0qivjLuqTkrLG BlRGn8/QrHKWE5PuBzXDc/ze4e1qIt8JfsifqsPEPfuoWLrsK6BjbOXUsFHNnO2UCUaZ +sxwux2loaBXQ84BREs4gr+8WNgxC6Mkw0NAUxLqGPsEMwLcKSVq0TVTJi1mTx2kd3Ub i1UTOm1tqhqUxUmWEKKHO2sY6uxfuUyUoXUBDlGs9gkGhfsyyOBsy+2frou8k5aqLcQe G+uVDK8q64gM+lpP+/v1Fhh7aZltkdzqRSXHfKfJ53fJ1JroLOyC0RslxxeVOmsMNooh 6Uvw== 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=IiS3fEfviUExWgb8WB/VoOys2Wk2rRgn6Qzz5WQY2aU=; b=SNDtuB1O/V2doekxWUDSzOLSodhdBW8cLnSXl6BmXSDUsT3kGPkCoyuo2Lh6nK4SID XYHYe+iwb39oyOIuFcvoVaPfWiiygwYA3xeAvIvIM6Dc1IkY16Iqc33ccPz6+cR3GgLQ IIi4ww4uPKiN9LPmCGhSDfLaRZETw8zeHTB5iOwede0bMQqNFf+5DgIvvwbJqj3YyWYa v34gu/QI7vFJVEfnKTgrYmkSvuyvl+KbkLlyYqAkGJU6af1m0Q/0RjL8GarolOR5WjY6 1KuW4B5MdaJEDxqjyeq4N4+bvkI5Zbvujys4ACg6qf5FQ6mQhJr4FuVF6A+DI2T0AqUh yKoA== X-Gm-Message-State: AOAM5339W8S2Wh4rQrAIsN5TdEACO/P5UuoV7F9bjgVG/Isixby7c9Ri YTSL58VJT/jFY8nCeOILYtpGs/nty5g= X-Google-Smtp-Source: ABdhPJwKeTB+TJQRw6DfzCat86p68ItWXXQ1wJAcoJ8bHkZhLrYQeBg4SH4p392DYgUPH45q9creJQ== X-Received: by 2002:a05:600c:4fc8:: with SMTP id o8mr6634153wmq.153.1631453012728; Sun, 12 Sep 2021 06:23:32 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u26sm4672550wrd.32.2021.09.12.06.23.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:32 -0700 (PDT) Message-Id: <8aefce6254c0bcbbbca909a62d033c74c90f980b.1631453010.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:17 +0000 Subject: [PATCH v2 01/14] t3705: test that 'sparse_entry' is unstaged Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The tests in t3705-add-sparse-checkout.sh check to see how 'git add' behaves with paths outside the sparse-checkout definition. These currently check to see if a given warning is present but not that the index is not updated with the sparse entries. Add a new 'test_sparse_entry_unstaged' helper to be sure 'git add' is behaving correctly. We need to modify setup_sparse_entry to actually commit the sparse_entry file so it exists at HEAD but is not already staged in the index. Signed-off-by: Derrick Stolee --- t/t3705-add-sparse-checkout.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 2b1fd0d0eef..af81b4b6846 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -19,6 +19,7 @@ setup_sparse_entry () { fi && git add sparse_entry && git update-index --skip-worktree sparse_entry && + git commit --allow-empty -m "ensure sparse_entry exists at HEAD" && SPARSE_ENTRY_BLOB=$(git rev-parse :sparse_entry) } @@ -36,6 +37,11 @@ setup_gitignore () { EOF } +test_sparse_entry_unstaged () { + git status --porcelain >actual && + ! grep "^M sparse_entry\$" actual +} + test_expect_success 'setup' " cat >sparse_error_header <<-EOF && The following pathspecs didn't match any eligible path, but they do match index @@ -55,6 +61,7 @@ test_expect_success 'git add does not remove sparse entries' ' setup_sparse_entry && rm sparse_entry && test_must_fail git add sparse_entry 2>stderr && + test_sparse_entry_unstaged && test_cmp error_and_hint stderr && test_sparse_entry_unchanged ' @@ -73,6 +80,7 @@ test_expect_success 'git add . does not remove sparse entries' ' rm sparse_entry && setup_gitignore && test_must_fail git add . 2>stderr && + test_sparse_entry_unstaged && cat sparse_error_header >expect && echo . >>expect && @@ -88,6 +96,7 @@ do setup_sparse_entry && echo modified >sparse_entry && test_must_fail git add $opt sparse_entry 2>stderr && + test_sparse_entry_unstaged && test_cmp error_and_hint stderr && test_sparse_entry_unchanged ' @@ -98,6 +107,7 @@ test_expect_success 'git add --refresh does not update sparse entries' ' git ls-files --debug sparse_entry | grep mtime >before && test-tool chmtime -60 sparse_entry && test_must_fail git add --refresh sparse_entry 2>stderr && + test_sparse_entry_unstaged && test_cmp error_and_hint stderr && git ls-files --debug sparse_entry | grep mtime >after && test_cmp before after @@ -106,6 +116,7 @@ test_expect_success 'git add --refresh does not update sparse entries' ' test_expect_success 'git add --chmod does not update sparse entries' ' setup_sparse_entry && test_must_fail git add --chmod=+x sparse_entry 2>stderr && + test_sparse_entry_unstaged && test_cmp error_and_hint stderr && test_sparse_entry_unchanged && ! test -x sparse_entry @@ -116,6 +127,7 @@ test_expect_success 'git add --renormalize does not update sparse entries' ' setup_sparse_entry "LINEONE\r\nLINETWO\r\n" && echo "sparse_entry text=auto" >.gitattributes && test_must_fail git add --renormalize sparse_entry 2>stderr && + test_sparse_entry_unstaged && test_cmp error_and_hint stderr && test_sparse_entry_unchanged ' @@ -124,6 +136,7 @@ test_expect_success 'git add --dry-run --ignore-missing warn on sparse path' ' setup_sparse_entry && rm sparse_entry && test_must_fail git add --dry-run --ignore-missing sparse_entry 2>stderr && + test_sparse_entry_unstaged && test_cmp error_and_hint stderr && test_sparse_entry_unchanged ' @@ -148,6 +161,7 @@ test_expect_success 'do not warn when pathspec matches dense entries' ' test_expect_success 'add obeys advice.updateSparsePath' ' setup_sparse_entry && test_must_fail git -c advice.updateSparsePath=false add sparse_entry 2>stderr && + test_sparse_entry_unstaged && test_cmp sparse_entry_error stderr ' From patchwork Sun Sep 12 13:23:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486895 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.8 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 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 A3EE6C433EF for ; Sun, 12 Sep 2021 13:23:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CC5161056 for ; Sun, 12 Sep 2021 13:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235427AbhILNYu (ORCPT ); Sun, 12 Sep 2021 09:24:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235291AbhILNYt (ORCPT ); Sun, 12 Sep 2021 09:24:49 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA3F0C061574 for ; Sun, 12 Sep 2021 06:23:34 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id r128-20020a1c4486000000b003065f0bc631so280668wma.0 for ; Sun, 12 Sep 2021 06:23:34 -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=jKmLVazVK7gtvwbhr3jVySvGWDJtYIfWGhrkZamSAi8=; b=YqYAQBnYWx1BcMauqLe513CEaTTQSUf+QIAqmgywU9B4mBLMrQ4r83zwBmTSjw3L0Q 3UzlAw96KpqElNK8Xb88jLTV/2o6YpoXM4p5LVpme/sskDknnRSgPVA4Cd0rWXtsb/Yc ZKxsWgdOBts2ZSwd+50MGdwNFBw/wM+C9OYukpIO7TrQ6U2MoRhShi0x60z/ZTEKxMhu vW4D8BOYI2PvvXOzOLfWpquXCb4537G319CWXnDycS3MhVGVGA2TFi80Sotd6YYel8KJ a6uajWl34Iptyz2l3vderYro4r5/wycpYJcXF2og9YCFPo9bEXD7BA0uiwR0l4UiThny V2Gg== 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=jKmLVazVK7gtvwbhr3jVySvGWDJtYIfWGhrkZamSAi8=; b=HNK/1cQSHJ/M/guTbk/4p55nx2/9/Yojmcnsj8NPAEnrybYrgyBuXRFC5HmcbRfXCa Z9XAltjJLJYduFGzwl7SDabRb4YlVYYa0yYRL+acrOzBaXrUCnLSwi8gykCKYFcdJTfd dQZZd2Kn4zRPYSfvTYakMvXVj8vIoDp9Ym6Hi1+ZmZV28YpxspS+tAQaBN4YcoEHy0zg 9TyVC1JRgErYpYb10I5APzDYfbCltIeP+kmd/6++VTEwq5Gb2Gmtng9+q1cEZGv2Ryu0 xXNSINqORq/pUO/VeIXu8J0b9wzgwEa6ZbcXZHcTFNXlql9xC6V3lNzYl58aPl6MEMY5 A7RA== X-Gm-Message-State: AOAM532R+7NzIWaVNOamkwuySlcQ0aqdAcDz/52H0eakdLyS3UDCKYtM PX6Y1m49H6HTx82iy7E2QCy0Ue8+jLc= X-Google-Smtp-Source: ABdhPJzYLfJVRShd4I2BWVqETG1+VgBPTVONqkTNGFpSmfNlI9I1KqZusR9WP27JE5ZKfN8U+BmAew== X-Received: by 2002:a1c:2943:: with SMTP id p64mr6676627wmp.107.1631453013429; Sun, 12 Sep 2021 06:23:33 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n3sm4340880wmi.0.2021.09.12.06.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:33 -0700 (PDT) Message-Id: <61c23dc59a6e062e073ba3bea135c370a78415aa.1631453010.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:18 +0000 Subject: [PATCH v2 02/14] t1092: behavior for adding sparse files Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Add some tests to demonstrate the current behavior around adding files outside of the sparse-checkout cone. Currently, untracked files are handled differently from tracked files. A future change will make these cases be handled the same way. Further expand checking that a failed 'git add' does not stage changes to the index. Signed-off-by: Derrick Stolee --- t/t1092-sparse-checkout-compatibility.sh | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 886e78715fe..5b3f55e355e 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -187,6 +187,16 @@ test_sparse_match () { test_cmp sparse-checkout-err sparse-index-err } +test_sparse_unstaged () { + file=$1 && + for repo in sparse-checkout sparse-index + do + git -C $repo status --porcelain >$repo-out && + ! grep "^A $file\$" $repo-out && + ! grep "^M $file\$" $repo-out || return 1 + done +} + test_expect_success 'sparse-index contents' ' init_repos && @@ -291,6 +301,20 @@ test_expect_success 'add, commit, checkout' ' test_all_match git checkout - ' +# NEEDSWORK: This documents current behavior, but is not a desirable +# behavior (untracked files are handled differently than tracked). +test_expect_success 'add outside sparse cone' ' + init_repos && + + run_on_sparse mkdir folder1 && + run_on_sparse ../edit-contents folder1/a && + run_on_sparse ../edit-contents folder1/newfile && + test_sparse_match test_must_fail git add folder1/a && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && + test_sparse_unstaged folder1/a && + test_sparse_match git add folder1/newfile +' + test_expect_success 'commit including unstaged changes' ' init_repos && @@ -339,7 +363,11 @@ test_expect_success 'status/add: outside sparse cone' ' # Adding the path outside of the sparse-checkout cone should fail. test_sparse_match test_must_fail git add folder1/a && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && + test_sparse_unstaged folder1/a && test_sparse_match test_must_fail git add --refresh folder1/a && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && + test_sparse_unstaged folder1/a && # NEEDSWORK: Adding a newly-tracked file outside the cone succeeds test_sparse_match git add folder1/new && From patchwork Sun Sep 12 13:23:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486897 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.8 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 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 61554C433FE for ; Sun, 12 Sep 2021 13:23:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DE8561209 for ; Sun, 12 Sep 2021 13:23:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235483AbhILNYx (ORCPT ); Sun, 12 Sep 2021 09:24:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235361AbhILNYu (ORCPT ); Sun, 12 Sep 2021 09:24:50 -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 71571C061574 for ; Sun, 12 Sep 2021 06:23:35 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id w29so9502165wra.8 for ; Sun, 12 Sep 2021 06:23:35 -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=2zkseZDCrX5eQCOfTAj1pziuYCUVx8n+RzgjO8cPYiw=; b=pXJValooYvPuHvgxr2cF2+J6hmqw6variJGni7LBLXuRY+Emr60Wf/V8o9MrQeeQDb Qs4iVbPgh87/IjKg1ncNeiBAI5ovPCh6SD2r9rBwAlWhy85cvhW3ZqLUjKS7doyyvzD7 HPQH1PneEa4OLWUNloA1Y9VSXDfwQyf98eG/0lnxo8IwieOiQtnFGYne6FgFTERG3rlz Mn2DmPv3w7N3bt+4Ke1+OhSlwc56+KwR1Y1UKmaKivraSh8Wpp9vJPitfyrvLtCTtoKr nYg5/1C+ec2DAaTlIlI2ZzMV6UKL0SE/PiwLTpyfjzrFQG6Y2VE5BZug8qkpfrw/0jex SpLw== 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=2zkseZDCrX5eQCOfTAj1pziuYCUVx8n+RzgjO8cPYiw=; b=Hx8y/U22PATgTqNoKLZPQqaovj809XjIICgbRjfnoGJTnrY8UEDLHVjPPxXl/wfo9+ YhOQBV5ZRWPRy/KRsRp+9Eq/pmslbvJ7rVdDKUDGovoTKMFoppNI6+jBWaN/aCilVzBA qsSpxR/iPHRLUYR3zOVjm2n6ZHgnn3mQWjsB9fZB47XWOuqDmWlIercQF/J0C1rqwI2x wXbROX7JQNSqdC4/3nva+FRaq/07cRmpuSb64+YYcaqLGoAD7FlMi91Eh6peT4Y7HYOy 0giO0QzvBJMF8jUqACY927v8AE7sCB62fAOp4qaxgyr0n2LNaU6mSCn29dWUZReXVjMQ 2kEg== X-Gm-Message-State: AOAM531Imut8yMT/huFXB4nZrdevW14SmGBIuOt4+YKnlAhR8QYegyz/ +PlIWzlAG1gPDowQp+Jqc41Tp+ZnP90= X-Google-Smtp-Source: ABdhPJzXldl0ahwzV0kS+V5R4gp9EgPol3aFVBeRMtfHyM3vkKR+6L+kBqFG011U5w15O7DT92ScCw== X-Received: by 2002:adf:f911:: with SMTP id b17mr7656703wrr.412.1631453014010; Sun, 12 Sep 2021 06:23:34 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o24sm760912wmm.11.2021.09.12.06.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:33 -0700 (PDT) Message-Id: <747b52e7bde1a33953849de233a47a063337548a.1631453010.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:19 +0000 Subject: [PATCH v2 03/14] dir: extract directory-matching logic Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The last_matching_pattern_from_list() logic performs some checks on the filetype of a path within the index when the PATTERN_FLAG_MUSTBEDIR flag is set. This works great when setting SKIP_WORKTREE bits within unpack_trees(), but doesn't work well when passing an arbitrary path such as a file within a matching directory. This change only rearranges the logic but does not change its functionality. We will expand the path_matches_dir_pattern() method in a following change. Signed-off-by: Derrick Stolee --- dir.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/dir.c b/dir.c index 86afa2eae00..652135df896 100644 --- a/dir.c +++ b/dir.c @@ -1303,6 +1303,19 @@ int match_pathname(const char *pathname, int pathlen, WM_PATHNAME) == 0; } +static int path_matches_dir_pattern(const char *pathname, + int pathlen, + int *dtype, + struct path_pattern *pattern, + struct index_state *istate) +{ + *dtype = resolve_dtype(*dtype, istate, pathname, pathlen); + if (*dtype != DT_DIR) + return 0; + + return 1; +} + /* * Scan the given exclude list in reverse to see whether pathname * should be ignored. The first match (i.e. the last on the list), if @@ -1327,11 +1340,10 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname const char *exclude = pattern->pattern; int prefix = pattern->nowildcardlen; - if (pattern->flags & PATTERN_FLAG_MUSTBEDIR) { - *dtype = resolve_dtype(*dtype, istate, pathname, pathlen); - if (*dtype != DT_DIR) - continue; - } + if ((pattern->flags & PATTERN_FLAG_MUSTBEDIR) && + !path_matches_dir_pattern(pathname, pathlen, + dtype, pattern, istate)) + continue; if (pattern->flags & PATTERN_FLAG_NODIR) { if (match_basename(basename, From patchwork Sun Sep 12 13:23:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486899 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.8 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 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 7A94BC433F5 for ; Sun, 12 Sep 2021 13:23:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 538106113E for ; Sun, 12 Sep 2021 13:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235512AbhILNYy (ORCPT ); Sun, 12 Sep 2021 09:24:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235382AbhILNYu (ORCPT ); Sun, 12 Sep 2021 09:24:50 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A661C061757 for ; Sun, 12 Sep 2021 06:23:36 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id b21-20020a1c8015000000b003049690d882so2107483wmd.5 for ; Sun, 12 Sep 2021 06:23:35 -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=IFLBnCb01UTxiG6mjxXgFtXahLMWXCrHCCNfFoecSsw=; b=YY7fRQlCz/Cs5G0c0zcZauUQTePi7jczQCVgvelGP54C1i6l2vP9AUt1h66gTIusqT HPkjhnssWSTkE/0yJFpQvHhIal+fUIhDuQ7QPxrlk6ZLKg9qfpc9iEiilrw4bjjfRh2H cFdvLtT9/PrU7PyOdi33en0xm/gnC3ydlJgUbcI9ZyFd9cJOGNcH3RU15OQVRan+zfyd vQn3yLIrVHm5Im11fpvVwDNUJGA3crwo34E5U2XCm0ra7S8OXePtTf17d1JGiUcimn9D 7FLsHqtQFRgC7216tLluFGLjg/abVxF6vIBlEStowCKUnsm3P2vw4NXROkEzNGAFbO3s vp2A== 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=IFLBnCb01UTxiG6mjxXgFtXahLMWXCrHCCNfFoecSsw=; b=0Ngreeww0c07KM4+uTQibwxZyJr2nNSNhh9BTCg0UVg4NMXe4cuuYFtfkyJHqdwYAE w7vVMh9HFCoITcwu85VmLDruEHt+PvXVP3HwUcMiZxTUlaOomN8DKe6a09Dhx6UTzR/y RV3vXJvKZwnx2LR2tOXv8MhncEsV8udPSYDQydp8Z8IpKqauKKQ6iJttOHqBG2voVDdj ui002WBhkzHjuE82aKpzhBzN4c8wa4j3UxEEny59AR2ZQ2honIZ+R5Nik6nY7l7qgtiF x9mXkCjl3G6UdzM6sOjXl3eFGUN07ebx9Sfd2qV1XWKD33ZCz8lGXZXL4jU4nRCF2nyd BCmg== X-Gm-Message-State: AOAM530LxHkttmt+Dp+or4JurmDMIYT+w2pWoQbJcHAs/DFcr0tIxT7T COaF+q0noCrmoL4BtaIP2fkUOTkuv4E= X-Google-Smtp-Source: ABdhPJxWFwBkS9V2tnR8mF41eMPe8f4RXmoeKxXpyIINOdwzFFN2a6v2Z5aYSgWDIZmx0zQczwfKNg== X-Received: by 2002:a05:600c:a49:: with SMTP id c9mr6580531wmq.159.1631453014645; Sun, 12 Sep 2021 06:23:34 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l3sm4088299wms.4.2021.09.12.06.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:34 -0700 (PDT) Message-Id: <723de4e42582afbe841ed96470fc02db44b24b5e.1631453010.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:20 +0000 Subject: [PATCH v2 04/14] dir: select directories correctly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When matching a path against a list of patterns, the ones that require a directory match previously did not work when a filename is specified. This was fine when all pattern-matching was done within methods such as unpack_trees() that check a directory before recursing into the contained files. However, other commands will start matching individual files against pattern lists without that recursive approach. We modify path_matches_dir_pattern() to take a strbuf 'path_parent' that is used to store the parent directory of 'pathname' between multiple pattern matching tests. This is loaded lazily, only on the first pattern it finds that has the PATTERN_FLAG_MUSTBEDIR flag. If we find that a path has a parent directory, we start by checking to see if that parent directory matches the pattern. If so, then we do not need to query the index for the type (which can be expensive). If we find that the parent does not match, then we still must check the type from the index for the given pathname. Note that this does not affect cone mode pattern matching, but instead the more general -- and slower -- full pattern set. Thus, this does not affect the sparse index. Signed-off-by: Derrick Stolee --- dir.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/dir.c b/dir.c index 652135df896..fe5ee87bb5f 100644 --- a/dir.c +++ b/dir.c @@ -1305,10 +1305,38 @@ int match_pathname(const char *pathname, int pathlen, static int path_matches_dir_pattern(const char *pathname, int pathlen, + struct strbuf *path_parent, int *dtype, struct path_pattern *pattern, struct index_state *istate) { + /* + * Use 'alloc' as an indicator that the string has not been + * initialized, in case the parent is the root directory. + */ + if (!path_parent->alloc) { + char *slash; + strbuf_addstr(path_parent, pathname); + slash = find_last_dir_sep(path_parent->buf); + + if (slash) + *slash = '\0'; + else + strbuf_setlen(path_parent, 0); + } + + /* + * If the parent directory matches the pattern, then we do not + * need to check for dtype. + */ + if (path_parent->len && + match_pathname(path_parent->buf, path_parent->len, + pattern->base, + pattern->baselen ? pattern->baselen - 1 : 0, + pattern->pattern, pattern->nowildcardlen, + pattern->patternlen, pattern->flags)) + return 1; + *dtype = resolve_dtype(*dtype, istate, pathname, pathlen); if (*dtype != DT_DIR) return 0; @@ -1331,6 +1359,7 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname { struct path_pattern *res = NULL; /* undecided */ int i; + struct strbuf path_parent = STRBUF_INIT; if (!pl->nr) return NULL; /* undefined */ @@ -1340,8 +1369,8 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname const char *exclude = pattern->pattern; int prefix = pattern->nowildcardlen; - if ((pattern->flags & PATTERN_FLAG_MUSTBEDIR) && - !path_matches_dir_pattern(pathname, pathlen, + if (pattern->flags & PATTERN_FLAG_MUSTBEDIR && + !path_matches_dir_pattern(pathname, pathlen, &path_parent, dtype, pattern, istate)) continue; @@ -1367,6 +1396,7 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname break; } } + strbuf_release(&path_parent); return res; } From patchwork Sun Sep 12 13:23:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486901 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.8 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 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 BFF01C433FE for ; Sun, 12 Sep 2021 13:23:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 960F06113E for ; Sun, 12 Sep 2021 13:23:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235545AbhILNYz (ORCPT ); Sun, 12 Sep 2021 09:24:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235291AbhILNYv (ORCPT ); Sun, 12 Sep 2021 09:24:51 -0400 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 9C4A5C06175F for ; Sun, 12 Sep 2021 06:23:36 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id t8so5232164wrq.4 for ; Sun, 12 Sep 2021 06:23:36 -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=NIWHJWvBiXtXaJEPmJtf0dHB0etFMwiF78iEbq7VnQc=; b=AhLH0HBi0Np931Ry/AnPRyQ0p6A6Lfw1axtcDBzE4IK/9GAHV+32Ucl0GICYq9l5ho whj3tnIWu5RCAkd2EqKu3bO+YcBL8larpIYDUSnecFl40tbXe9Y2ksVtMgMt3EYR2xbx iMTKFHdWfPWVsolzzF7sFPWTHZOEiCucEAS451b80LJYYcQZ3MgnHJASXHTViUVEVg0R bNNGZiH1HoSHIZdFbJjKlj8fQctg2Kn7txgM3eWt72Cz9Y5JDVeu0ODTp2BKtn++dkY7 zBP3dLXE2d1nXobJWW141ZfR9W0gArLHX/pR5LzczdRwMH2q+5MGnI70SIQbilg1UMhp GivA== 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=NIWHJWvBiXtXaJEPmJtf0dHB0etFMwiF78iEbq7VnQc=; b=AAtjyVkqxMVzxQUUzGRyU6g19JrIluX0sr5LqHIqBkN3lPOtu6sBm/C/S7dtSt/arz 1AACp23+0TD546esldYH61AIN4NjubBIVV7duhyUrMeY0CMqQwZow+bLbI4ORONuUTeV Qy5AwV0g5hOvBJ6e8w069D0qa3kJ6GdMKvdcjvJnkbifHqLtmGPAdLqwS8CaeKYhcD7M XmkvKkGP1z7xecFf9XRzqgJwycaatsInsBmWWML/8QkxrPPqLmOOqE893T3lamdyjsJl w83Ik218yi/z2AVGNSKgT79O3KzS55M8japmSN7LN62TwISqEkJdIWczSnLFZGfRENyP dv9g== X-Gm-Message-State: AOAM533FpFgXTnA/5LPCLRbfdL0UmxYj6OYDg73bqfPw2dVa1zTI78VP /AIuc/eY/kV4KzvfHaJm9kD15172WzI= X-Google-Smtp-Source: ABdhPJwQ/jX3d4b4acFgAqpQE5IrrV2hSpftlfiHDzXvrcbWk+A1aC2XVXJrNHZgdVbn5dLt2Cgmeg== X-Received: by 2002:adf:c501:: with SMTP id q1mr7523652wrf.150.1631453015231; Sun, 12 Sep 2021 06:23:35 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m4sm5308822wrx.81.2021.09.12.06.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:34 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:21 +0000 Subject: [PATCH v2 05/14] dir: fix pattern matching on dirs Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Within match_pathname(), one successful matching category happens when the pattern is equal to its non-wildcard prefix. At this point, we have checked that the input 'pathname' matches the pattern up to the prefix length, and then we subtraced that length from both 'patternlen' and 'namelen'. In the case of a directory match, this prefix match should be sufficient. However, the success condition only cared about _exact_ equality here. Instead, we should allow any path that agrees on this prefix in the case of PATTERN_FLAG_MUSTBEDIR. This case was not tested before because of the way unpack_trees() would match a parent directory before visiting the contained paths. This approach is changing, so we must change this comparison. Signed-off-by: Derrick Stolee --- dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dir.c b/dir.c index fe5ee87bb5f..80fd0ad2fc0 100644 --- a/dir.c +++ b/dir.c @@ -1294,7 +1294,7 @@ int match_pathname(const char *pathname, int pathlen, * then our prefix match is all we need; we * do not need to call fnmatch at all. */ - if (!patternlen && !namelen) + if (!patternlen && (!namelen || (flags & PATTERN_FLAG_MUSTBEDIR))) return 1; } From patchwork Sun Sep 12 13:23:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486903 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.8 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 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 3AD6BC433F5 for ; Sun, 12 Sep 2021 13:23:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2786D6113E for ; Sun, 12 Sep 2021 13:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235554AbhILNY4 (ORCPT ); Sun, 12 Sep 2021 09:24:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235454AbhILNYv (ORCPT ); Sun, 12 Sep 2021 09:24:51 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A7E0C061574 for ; Sun, 12 Sep 2021 06:23:37 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id e26so4660865wmk.2 for ; Sun, 12 Sep 2021 06:23:37 -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=lD+F5ROkJ1GD99oCdCR4e2ZGsZUS65fErrzTrsgh7hQ=; b=UuGzt1FaIZd5ec/aOINpUT8F0zDs80U2CcBuZkxHVZyjKZs4kz4BRi81hfrh7/EyZs nJluh8TDno+vPzy88OhDlHw7gkcPltEOHBhuWdtdJOL8yfWD6QKBcm/qngwzdhvn1gIG wnkBEdl0XG1yX1EbR7UPm4cdw05l2cdnvO7FXBFs+cD1K3APn33bO1Ha6f/pcpEVxpW6 EzRGdbMjwkn/NvHfS46ktOBepmpog/FWQrtovtLzl2/CwYPjAvNjxbEQlHMgNsRUACIU pYb7FAi4q2tsVIet2hEFLkgoTFZ6e8qCHZcR/ti59Ik9K4Z9vwS/yRYjqlFSbRtINeHS RVAg== 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=lD+F5ROkJ1GD99oCdCR4e2ZGsZUS65fErrzTrsgh7hQ=; b=zAEfXyrcZiASoRQkRaTI9LhDIqd3OVweBUz8RGuDrCtHSDL5J5jE91LYWrgNQRIilc boGcceNVPYTPCJL+22jcoWap6J5h1rbT8gppxbKeUtYF4GX6szJMlPjL3gTg7IC33Dm8 dih/mA/Q7DDx6kOp/txZdO/EBJ/yjFemiFwfxQb3uI9ENnuY0jIlwHZ3pgtanqlHNFmt nFe/eaWhJfXp0KQ0dl2tZjnLZpUch4QMspr3XZM6vkaL0pArSPHKSLriaTDK0TQ/gx7H bnBxZmnEFhRgIcYoDsGeCoLuZTZv8vbGKfknyIbJAbtvUs7oQaPJcO45cmBqrzKMEXU0 1GWg== X-Gm-Message-State: AOAM530d3g1Km7TeeHANqkY1mvKSiiFgQXxeVUA77W+0+3HmTusawDsN gNSmIN60tB/ZvecRiZSF2onxngWwPDw= X-Google-Smtp-Source: ABdhPJwM3+rf/R+ANNfZvtzhVdYED7usYxLMnctPmlE4b+09J9YbbMqKkQdLvjvaL8fV3xURBtRpyA== X-Received: by 2002:a05:600c:219:: with SMTP id 25mr6591144wmi.157.1631453015934; Sun, 12 Sep 2021 06:23:35 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k17sm4636551wmj.0.2021.09.12.06.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:35 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:22 +0000 Subject: [PATCH v2 06/14] add: fail when adding an untracked sparse file Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The add_files() method in builtin/add.c takes a set of untracked files that are being added by the input pathspec and inserts them into the index. If these files are outside of the sparse-checkout cone, then they gain the SKIP_WORKTREE bit at some point. However, this was not checked before inserting into the index, so these files are added even though we want to avoid modifying the index outside of the sparse-checkout cone. Add a check within add_files() for these files and write the advice about files outside of the sparse-checkout cone. This behavior change modifies some existing tests within t1092. These tests intended to document how a user could interact with the existing behavior in place. Many of these tests need to be marked as expecting failure. A future change will allow these tests to pass by adding a flag to 'git add' that allows users to modify index entries outside of the sparse-checkout cone. The 'submodule handling' test is intended to document what happens to directories that contain a submodule when the sparse index is enabled. It is not trying to say that users should be able to add submodules outside of the sparse-checkout cone, so that test can be modified to avoid that operation. Signed-off-by: Derrick Stolee --- builtin/add.c | 14 +++++++++ t/t1092-sparse-checkout-compatibility.sh | 37 ++++++++++++++++++------ 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 88a6c0c69fb..8ea9cae0e7a 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -443,6 +443,7 @@ static void check_embedded_repo(const char *path) static int add_files(struct dir_struct *dir, int flags) { int i, exit_status = 0; + struct string_list matched_sparse_paths = STRING_LIST_INIT_NODUP; if (dir->ignored_nr) { fprintf(stderr, _(ignore_error)); @@ -456,6 +457,11 @@ static int add_files(struct dir_struct *dir, int flags) } for (i = 0; i < dir->nr; i++) { + if (!path_in_sparse_checkout(dir->entries[i]->name, &the_index)) { + string_list_append(&matched_sparse_paths, + dir->entries[i]->name); + continue; + } if (add_file_to_index(&the_index, dir->entries[i]->name, flags)) { if (!ignore_add_errors) die(_("adding files failed")); @@ -464,6 +470,14 @@ static int add_files(struct dir_struct *dir, int flags) check_embedded_repo(dir->entries[i]->name); } } + + if (matched_sparse_paths.nr) { + advise_on_updating_sparse_paths(&matched_sparse_paths); + exit_status = 1; + } + + string_list_clear(&matched_sparse_paths, 0); + return exit_status; } diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 5b3f55e355e..997442b13e3 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -301,8 +301,6 @@ test_expect_success 'add, commit, checkout' ' test_all_match git checkout - ' -# NEEDSWORK: This documents current behavior, but is not a desirable -# behavior (untracked files are handled differently than tracked). test_expect_success 'add outside sparse cone' ' init_repos && @@ -312,7 +310,9 @@ test_expect_success 'add outside sparse cone' ' test_sparse_match test_must_fail git add folder1/a && test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/a && - test_sparse_match git add folder1/newfile + test_sparse_match test_must_fail git add folder1/newfile && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && + test_sparse_unstaged folder1/newfile ' test_expect_success 'commit including unstaged changes' ' @@ -343,7 +343,11 @@ test_expect_success 'commit including unstaged changes' ' test_all_match git status --porcelain=v2 ' -test_expect_success 'status/add: outside sparse cone' ' +# NEEDSWORK: Now that 'git add folder1/new' fails, the changes being +# attempted here fail for the sparse-checkout and sparse-index repos. +# We must enable a way for adding files outside the sparse-checkout +# done, even if it is by an optional flag. +test_expect_failure 'status/add: outside sparse cone' ' init_repos && # folder1 is at HEAD, but outside the sparse cone @@ -368,10 +372,11 @@ test_expect_success 'status/add: outside sparse cone' ' test_sparse_match test_must_fail git add --refresh folder1/a && test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/a && + test_sparse_match test_must_fail git add folder1/new && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && + test_sparse_unstaged folder1/new && - # NEEDSWORK: Adding a newly-tracked file outside the cone succeeds - test_sparse_match git add folder1/new && - + # NEEDSWORK: behavior begins to deviate here. test_all_match git add . && test_all_match git status --porcelain=v2 && test_all_match git commit -m folder1/new && @@ -527,7 +532,7 @@ test_expect_success 'merge, cherry-pick, and rebase' ' # Right now, users might be using this flow to work through conflicts, # so any solution should present advice to users who try this sequence # of commands to follow whatever new method we create. -test_expect_success 'merge with conflict outside cone' ' +test_expect_failure 'merge with conflict outside cone' ' init_repos && test_all_match git checkout -b merge-tip merge-left && @@ -541,12 +546,18 @@ test_expect_success 'merge with conflict outside cone' ' test_all_match git status --porcelain=v2 && # 2. Add the file with conflict markers + # NEEDSWORK: Even though the merge conflict removed the + # SKIP_WORKTREE bit from the index entry for folder1/a, we should + # warn that this is a problematic add. test_all_match git add folder1/a && test_all_match git status --porcelain=v2 && # 3. Rename the file to another sparse filename and # accept conflict markers as resolved content. run_on_all mv folder2/a folder2/z && + # NEEDSWORK: This mode now fails, because folder2/z is + # outside of the sparse-checkout cone and does not match an + # existing index entry with the SKIP_WORKTREE bit cleared. test_all_match git add folder2 && test_all_match git status --porcelain=v2 && @@ -555,7 +566,7 @@ test_expect_success 'merge with conflict outside cone' ' test_all_match git rev-parse HEAD^{tree} ' -test_expect_success 'cherry-pick/rebase with conflict outside cone' ' +test_expect_failure 'cherry-pick/rebase with conflict outside cone' ' init_repos && for OPERATION in cherry-pick rebase @@ -572,11 +583,17 @@ test_expect_success 'cherry-pick/rebase with conflict outside cone' ' test_all_match git status --porcelain=v2 && # 2. Add the file with conflict markers + # NEEDSWORK: Even though the merge conflict removed the + # SKIP_WORKTREE bit from the index entry for folder1/a, we should + # warn that this is a problematic add. test_all_match git add folder1/a && test_all_match git status --porcelain=v2 && # 3. Rename the file to another sparse filename and # accept conflict markers as resolved content. + # NEEDSWORK: This mode now fails, because folder2/z is + # outside of the sparse-checkout cone and does not match an + # existing index entry with the SKIP_WORKTREE bit cleared. run_on_all mv folder2/a folder2/z && test_all_match git add folder2 && test_all_match git status --porcelain=v2 && @@ -654,6 +671,7 @@ test_expect_success 'clean' ' test_expect_success 'submodule handling' ' init_repos && + test_sparse_match git sparse-checkout add modules && test_all_match mkdir modules && test_all_match touch modules/a && test_all_match git add modules && @@ -663,6 +681,7 @@ test_expect_success 'submodule handling' ' test_all_match git commit -m "add submodule" && # having a submodule prevents "modules" from collapse + test_sparse_match git sparse-checkout set deep/deeper1 && test-tool -C sparse-index read-cache --table >cache && grep "100644 blob .* modules/a" cache && grep "160000 commit $(git -C initial-repo rev-parse HEAD) modules/sub" cache From patchwork Sun Sep 12 13:23:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486905 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.8 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 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 4A43EC433EF for ; Sun, 12 Sep 2021 13:23:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35DAF61056 for ; Sun, 12 Sep 2021 13:23:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235490AbhILNY6 (ORCPT ); Sun, 12 Sep 2021 09:24:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235292AbhILNYw (ORCPT ); Sun, 12 Sep 2021 09:24:52 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD783C061757 for ; Sun, 12 Sep 2021 06:23:37 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id d21so2565236wra.12 for ; Sun, 12 Sep 2021 06:23:37 -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=091FOS3cmDpnHLPChu5bX9sOuJNv/DvCABY/jg3a3ts=; b=lk5HUr2Sj82nWG2nvuPDPfNQpXXVvgtQ0zvS/CT6iIQkgBmYd8c3fDLMXtys/8u9lI i+VKNtzuDsa+vkD2E11KlANday8fthrhZrNE5HWpH+MxMUvjmuZDg+FIsfRfzTKNppsu 2s05xxMviNjbc3ZBmWMMLSKmBCOB87Tj8vJSPCvVdPYSqrSUEekxG0XJUVGeRh7q6oNG cqxkn004huACf1SylaWqZ5eVawMHJhGdoUTbAeE9qG2d3BoeYbkArUXK5zBxh5Tj7MMY 562mvFdoCS+7/O1h6N/bfwZyDMjfODY18vWM3Tte+oQS8NFQtx0c+wF0nGknUZdbL4AF WVwQ== 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=091FOS3cmDpnHLPChu5bX9sOuJNv/DvCABY/jg3a3ts=; b=4sH9rJmuDx7jgYO5wMpNpDVo5YcfBq5k8ft/96KICaj4+udnPvPRWRU5wu1U/IRapg 4PMkPm5w8f1Km4XN58RpwmpOC83EBG9HKVcwDf6/gcTF79D5CoOCng7KTmQinsbQjuxw q7Hiq3MV05cTELY0IK4NkDVFUE1DZClQ6wnKKoy4PwQRerPYYLLDkbZ+zst3hLHWbJqX 7w8mDqybLZiDoRjMxYwlycXM5XWy5vyWSevj0T+kFbosJHPP8Owg0C4nQvs4zgHRFj0D KtRLnSarbgs+V++nGdxmY2ViSvz05UfgxGYK2vIqAjifA4emfeNOTLr2Q63COJc0wDel RZkA== X-Gm-Message-State: AOAM5301N6SA8pGM2TfXPMjU+gS4srxfL/xZu4N3+R7bCyL3ftSDP2Vn DtnOuEuvv+PnunavafAP1oTK7lBCwrk= X-Google-Smtp-Source: ABdhPJwof5Hcrrl6eMaQxLoxuwMCGNfB/opAbdTtNJ1rMqmjRGPBNi4Bp4JpAL5JfNHDSfjAx7ahOw== X-Received: by 2002:adf:f2c4:: with SMTP id d4mr7687693wrp.434.1631453016445; Sun, 12 Sep 2021 06:23:36 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o13sm1853897wri.53.2021.09.12.06.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:36 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:23 +0000 Subject: [PATCH v2 07/14] add: skip tracked paths outside sparse-checkout cone Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When 'git add' adds a tracked file that is outside of the sparse-checkout cone, it checks the SKIP_WORKTREE bit to see if the file exists outside of the sparse-checkout cone. This is usually correct, except in the case of a merge conflict outside of the cone. Modify add_pathspec_matched_against_index() to be more careful about paths by checking the sparse-checkout patterns in addition to the SKIP_WORKTREE bit. This causes 'git add' to no longer allow files outside of the cone that removed the SKIP_WORKTREE bit due to a merge conflict. With only this change, users will only be able to add the file after adding the file to the sparse-checkout cone. A later change will allow users to force adding even though the file is outside of the sparse-checkout cone. Signed-off-by: Derrick Stolee --- builtin/add.c | 4 ++++ pathspec.c | 5 +++-- t/t1091-sparse-checkout-builtin.sh | 4 +++- t/t1092-sparse-checkout-compatibility.sh | 21 ++++++++++++++------- t/t3705-add-sparse-checkout.sh | 12 ++++++++++++ 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 8ea9cae0e7a..09c3fad6321 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -94,6 +94,10 @@ static void update_callback(struct diff_queue_struct *q, for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; const char *path = p->one->path; + + if (!path_in_sparse_checkout(path, &the_index)) + continue; + switch (fix_unmerged_status(p, data)) { default: die(_("unexpected diff status %c"), p->status); diff --git a/pathspec.c b/pathspec.c index 44306fdaca2..ddeeba79114 100644 --- a/pathspec.c +++ b/pathspec.c @@ -39,7 +39,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec, return; for (i = 0; i < istate->cache_nr; i++) { const struct cache_entry *ce = istate->cache[i]; - if (sw_action == PS_IGNORE_SKIP_WORKTREE && ce_skip_worktree(ce)) + if (sw_action == PS_IGNORE_SKIP_WORKTREE && + (ce_skip_worktree(ce) || !path_in_sparse_checkout(ce->name, istate))) continue; ce_path_match(istate, ce, pathspec, seen); } @@ -70,7 +71,7 @@ char *find_pathspecs_matching_skip_worktree(const struct pathspec *pathspec) for (i = 0; i < istate->cache_nr; i++) { struct cache_entry *ce = istate->cache[i]; - if (ce_skip_worktree(ce)) + if (ce_skip_worktree(ce) || !path_in_sparse_checkout(ce->name, istate)) ce_path_match(istate, ce, pathspec, seen); } diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 71236981e64..af99ae81b1d 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -406,7 +406,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged stat git -C unmerged sparse-checkout disable ' -test_expect_success 'sparse-checkout reapply' ' +test_expect_failure 'sparse-checkout reapply' ' git clone repo tweak && echo dirty >tweak/deep/deeper2/a && @@ -438,6 +438,8 @@ test_expect_success 'sparse-checkout reapply' ' test_i18ngrep "warning.*The following paths are unmerged" err && test_path_is_file tweak/folder1/a && + # NEEDSWORK: We are asking to update a file outside of the + # sparse-checkout cone, but this is no longer allowed. git -C tweak add folder1/a && git -C tweak sparse-checkout reapply 2>err && test_must_be_empty err && diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 997442b13e3..0fdc5c7098c 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -546,10 +546,10 @@ test_expect_failure 'merge with conflict outside cone' ' test_all_match git status --porcelain=v2 && # 2. Add the file with conflict markers - # NEEDSWORK: Even though the merge conflict removed the - # SKIP_WORKTREE bit from the index entry for folder1/a, we should - # warn that this is a problematic add. - test_all_match git add folder1/a && + test_sparse_match test_must_fail git add folder1/a && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && + test_sparse_unstaged folder1/a && + test_all_match git add --sparse folder1/a && test_all_match git status --porcelain=v2 && # 3. Rename the file to another sparse filename and @@ -558,7 +558,10 @@ test_expect_failure 'merge with conflict outside cone' ' # NEEDSWORK: This mode now fails, because folder2/z is # outside of the sparse-checkout cone and does not match an # existing index entry with the SKIP_WORKTREE bit cleared. - test_all_match git add folder2 && + test_sparse_match test_must_fail git add folder2 && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && + test_sparse_unstaged folder2/z && + test_all_match git add --sparse folder2 && test_all_match git status --porcelain=v2 && test_all_match git merge --continue && @@ -586,7 +589,9 @@ test_expect_failure 'cherry-pick/rebase with conflict outside cone' ' # NEEDSWORK: Even though the merge conflict removed the # SKIP_WORKTREE bit from the index entry for folder1/a, we should # warn that this is a problematic add. - test_all_match git add folder1/a && + test_sparse_match test_must_fail git add folder1/a && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && + test_sparse_unstaged folder1/a && test_all_match git status --porcelain=v2 && # 3. Rename the file to another sparse filename and @@ -595,7 +600,9 @@ test_expect_failure 'cherry-pick/rebase with conflict outside cone' ' # outside of the sparse-checkout cone and does not match an # existing index entry with the SKIP_WORKTREE bit cleared. run_on_all mv folder2/a folder2/z && - test_all_match git add folder2 && + test_sparse_match test_must_fail git add folder2 && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && + test_sparse_unstaged folder2/z && test_all_match git status --porcelain=v2 && test_all_match git $OPERATION --continue && diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index af81b4b6846..678be1acbf9 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -158,6 +158,18 @@ test_expect_success 'do not warn when pathspec matches dense entries' ' git ls-files --error-unmatch dense_entry ' +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 set a && + echo >>sparse_entry && + + git update-index --no-skip-worktree sparse_entry && + test_must_fail git add sparse_entry && + test_sparse_entry_unstaged +' + test_expect_success 'add obeys advice.updateSparsePath' ' setup_sparse_entry && test_must_fail git -c advice.updateSparsePath=false add sparse_entry 2>stderr && From patchwork Sun Sep 12 13:23:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486909 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.8 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 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 E7C45C433FE for ; Sun, 12 Sep 2021 13:23:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFD4361056 for ; Sun, 12 Sep 2021 13:23:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235669AbhILNZA (ORCPT ); Sun, 12 Sep 2021 09:25:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235473AbhILNYw (ORCPT ); Sun, 12 Sep 2021 09:24:52 -0400 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 6265AC061760 for ; Sun, 12 Sep 2021 06:23:38 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id u16so10256262wrn.5 for ; Sun, 12 Sep 2021 06:23:38 -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=GIAGZHRRE09ikVaEMDICaxo0dT+xeD/tpoOh35D8Ju8=; b=Q8EVAJvdj+/Wrwf36eb/nlI8I89hNcpoAzO/+iqj+9zCCCA5jIENcmvz+5b61b/ojh IMQVWu3hl1tMQC+p7qyY+qyq5slbYFOrt1iOAgPopI+CzBoO+UGmEHXEFL+aj+qn7YDO RPrR3++OmcMWUEDNxrNkjYzGIFtx27HVyQKtZRhHS3t72Uwp8DcCw/F5eUm826oJMcrq 5e8mlK9ZHI2kqUQJw2Vhx2YUnzTCVprIEcE+nBxHOlJNq1KeAuMahrnuVQxvhjkdCwki 3Pw8wA5yS3QK5/Zvt+ScYqIM1NAl0mlgCFbzRavi5OtugTExASW9RchC2a/jHa9K+dXR XLHQ== 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=GIAGZHRRE09ikVaEMDICaxo0dT+xeD/tpoOh35D8Ju8=; b=SDiGwLoIMqFNKZTKwzLDw9pZAJpQaC30+nsrFevHDC976TARp04UzLWfM2SkAfWVr9 0lC9l9Zi3JkqondTTSKt0xLDOV11legzizXbPzMrUBgV7Uc0Vce21Pf+1r0juF3sQ6NL Oz00jJ3F5x1T7S6ksf9LfEEWyQDpbOQ8rNw2Uu5KiPjXCnu3pjobgc2DygP35ff3ij1u 8a38pKPT3rtZdIAfDELNZcU0VfCVDAiuAyCBTrCx55b8YepEFqRe71yTXPqO/XT9wE/l vKxHjLNhxrWPArp+BJBEEKggbETKKho+yixbbRy25bf6oNLIP267GdCms/tAVk24imKj IYKA== X-Gm-Message-State: AOAM531ALuFxf++r2bOFTKaS+B6KJbATCyBMR+iF7NvgKX9BANi5CH6V Fx9xTYe6fs+RVyMUwFGRy9y0i8E0iAI= X-Google-Smtp-Source: ABdhPJzKr2mnODNqBabueY4k8m64z4KZpqB+FORQyV/iQmmLu33w0J3wSTvvwx0nk5s+rU1Sdb51rg== X-Received: by 2002:adf:fe08:: with SMTP id n8mr3616649wrr.246.1631453016987; Sun, 12 Sep 2021 06:23:36 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i5sm3865347wmq.17.2021.09.12.06.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:36 -0700 (PDT) Message-Id: <944ae2cffa8ff175cd1cee0b3a25060ec5599973.1631453010.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:24 +0000 Subject: [PATCH v2 08/14] add: implement the --sparse option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee We previously modified 'git add' to refuse updating index entries outside of the sparse-checkout cone. This is justified to prevent users from accidentally getting into a confusing state when Git removes those files from the working tree at some later point. Unfortunately, this caused some workflows that were previously possible to become impossible, especially around merge conflicts outside of the sparse-checkout cone. These were documented in tests within t1092. We now re-enable these workflows using a new '--sparse' option to 'git add'. This allows users to signal "Yes, I do know what I'm doing with these files," and accept the consequences of the files leaving the worktree later. We delay updating the advice message until implementing a similar option in 'git rm' and 'git mv'. Signed-off-by: Derrick Stolee --- Documentation/git-add.txt | 9 +++++++- builtin/add.c | 12 +++++++---- t/t1092-sparse-checkout-compatibility.sh | 27 ++++++++---------------- t/t3705-add-sparse-checkout.sh | 17 ++++++++++++++- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index be5e3ac54b8..bb79016d2ca 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -9,7 +9,7 @@ SYNOPSIS -------- [verse] 'git add' [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p] - [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]] + [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]] [--sparse] [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--renormalize] [--chmod=(+|-)x] [--pathspec-from-file= [--pathspec-file-nul]] [--] [...] @@ -79,6 +79,13 @@ in linkgit:gitglossary[7]. --force:: Allow adding otherwise ignored files. +--sparse:: + Allow updating index entries outside of the sparse-checkout cone. + Normally, `git add` refuses to update index entries whose paths do + not fit within the sparse-checkout cone, since those files might + be removed from the working tree without warning. See + linkgit:git-sparse-checkout[1] for more. + -i:: --interactive:: Add modified contents in the working tree interactively to diff --git a/builtin/add.c b/builtin/add.c index 09c3fad6321..f8e3930608d 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -30,6 +30,7 @@ static int patch_interactive, add_interactive, edit_interactive; static int take_worktree_changes; static int add_renormalize; static int pathspec_file_nul; +static int include_sparse; static const char *pathspec_from_file; static int legacy_stash_p; /* support for the scripted `git stash` */ @@ -46,7 +47,7 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only) struct cache_entry *ce = active_cache[i]; int err; - if (ce_skip_worktree(ce)) + if (!include_sparse && ce_skip_worktree(ce)) continue; if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL)) @@ -95,7 +96,7 @@ static void update_callback(struct diff_queue_struct *q, struct diff_filepair *p = q->queue[i]; const char *path = p->one->path; - if (!path_in_sparse_checkout(path, &the_index)) + if (!include_sparse && !path_in_sparse_checkout(path, &the_index)) continue; switch (fix_unmerged_status(p, data)) { @@ -383,6 +384,7 @@ static struct option builtin_add_options[] = { OPT_BOOL( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")), OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")), OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")), + OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")), OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x", N_("override the executable bit of the listed files")), OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo, @@ -461,7 +463,8 @@ static int add_files(struct dir_struct *dir, int flags) } for (i = 0; i < dir->nr; i++) { - if (!path_in_sparse_checkout(dir->entries[i]->name, &the_index)) { + if (!include_sparse && + !path_in_sparse_checkout(dir->entries[i]->name, &the_index)) { string_list_append(&matched_sparse_paths, dir->entries[i]->name); continue; @@ -646,7 +649,8 @@ int cmd_add(int argc, const char **argv, const char *prefix) if (seen[i]) continue; - if (matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) { + if (!include_sparse && + matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) { string_list_append(&only_match_skip_worktree, pathspec.items[i].original); continue; diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 0fdc5c7098c..7d64d9deb22 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -343,11 +343,7 @@ test_expect_success 'commit including unstaged changes' ' test_all_match git status --porcelain=v2 ' -# NEEDSWORK: Now that 'git add folder1/new' fails, the changes being -# attempted here fail for the sparse-checkout and sparse-index repos. -# We must enable a way for adding files outside the sparse-checkout -# done, even if it is by an optional flag. -test_expect_failure 'status/add: outside sparse cone' ' +test_expect_success 'status/add: outside sparse cone' ' init_repos && # folder1 is at HEAD, but outside the sparse cone @@ -375,15 +371,16 @@ test_expect_failure 'status/add: outside sparse cone' ' test_sparse_match test_must_fail git add folder1/new && test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/new && + test_sparse_match git add --sparse folder1/a && + test_sparse_match git add --sparse folder1/new && - # NEEDSWORK: behavior begins to deviate here. - test_all_match git add . && + test_all_match git add --sparse . && test_all_match git status --porcelain=v2 && test_all_match git commit -m folder1/new && test_all_match git rev-parse HEAD^{tree} && run_on_all ../edit-contents folder1/newer && - test_all_match git add folder1/ && + test_all_match git add --sparse folder1/ && test_all_match git status --porcelain=v2 && test_all_match git commit -m folder1/newer && test_all_match git rev-parse HEAD^{tree} @@ -527,12 +524,7 @@ test_expect_success 'merge, cherry-pick, and rebase' ' done ' -# NEEDSWORK: This test is documenting current behavior, but that -# behavior can be confusing to users so there is desire to change it. -# Right now, users might be using this flow to work through conflicts, -# so any solution should present advice to users who try this sequence -# of commands to follow whatever new method we create. -test_expect_failure 'merge with conflict outside cone' ' +test_expect_success 'merge with conflict outside cone' ' init_repos && test_all_match git checkout -b merge-tip merge-left && @@ -555,9 +547,6 @@ test_expect_failure 'merge with conflict outside cone' ' # 3. Rename the file to another sparse filename and # accept conflict markers as resolved content. run_on_all mv folder2/a folder2/z && - # NEEDSWORK: This mode now fails, because folder2/z is - # outside of the sparse-checkout cone and does not match an - # existing index entry with the SKIP_WORKTREE bit cleared. test_sparse_match test_must_fail git add folder2 && test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder2/z && @@ -569,7 +558,7 @@ test_expect_failure 'merge with conflict outside cone' ' test_all_match git rev-parse HEAD^{tree} ' -test_expect_failure 'cherry-pick/rebase with conflict outside cone' ' +test_expect_success 'cherry-pick/rebase with conflict outside cone' ' init_repos && for OPERATION in cherry-pick rebase @@ -592,6 +581,7 @@ test_expect_failure 'cherry-pick/rebase with conflict outside cone' ' test_sparse_match test_must_fail git add folder1/a && test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/a && + test_all_match git add --sparse folder1/a && test_all_match git status --porcelain=v2 && # 3. Rename the file to another sparse filename and @@ -603,6 +593,7 @@ test_expect_failure 'cherry-pick/rebase with conflict outside cone' ' test_sparse_match test_must_fail git add folder2 && test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder2/z && + test_all_match git add --sparse folder2 && test_all_match git status --porcelain=v2 && test_all_match git $OPERATION --continue && diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 678be1acbf9..0f7e03b5326 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -167,7 +167,13 @@ test_expect_success 'git add fails outside of sparse-checkout definition' ' git update-index --no-skip-worktree sparse_entry && test_must_fail git add sparse_entry && - test_sparse_entry_unstaged + test_sparse_entry_unstaged && + + # Avoid munging CRLFs to avoid an error message + git -c core.autocrlf=input add --sparse sparse_entry 2>stderr && + test_must_be_empty stderr && + test-tool read-cache --table >actual && + grep "^100644 blob.*sparse_entry\$" actual ' test_expect_success 'add obeys advice.updateSparsePath' ' @@ -178,4 +184,13 @@ test_expect_success 'add obeys advice.updateSparsePath' ' ' +test_expect_success 'add allows sparse entries with --sparse' ' + git sparse-checkout set a && + echo modified >sparse_entry && + test_must_fail git add sparse_entry && + test_sparse_entry_unchanged && + git add --sparse sparse_entry 2>stderr && + test_must_be_empty stderr +' + test_done From patchwork Sun Sep 12 13:23:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486907 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.8 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 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 7A84EC433F5 for ; Sun, 12 Sep 2021 13:23:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 637FE61056 for ; Sun, 12 Sep 2021 13:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235653AbhILNY7 (ORCPT ); Sun, 12 Sep 2021 09:24:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235477AbhILNYx (ORCPT ); Sun, 12 Sep 2021 09:24:53 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C622CC061762 for ; Sun, 12 Sep 2021 06:23:38 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id u19-20020a7bc053000000b002f8d045b2caso4696151wmc.1 for ; Sun, 12 Sep 2021 06:23:38 -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=BzJtR2tKaZqh8MfQ9ZcYL3o8pZUvjNp8K0z781ytOeY=; b=dd/m2/voYJKUoIDmO8VqbOlZB2civM84ABGg/oCIJs7PJAwVcRWQ9trnNHRxXDu+7K WdG2wngYz/vAVh+vyuC1IT1+NgHJZ64IH8FUK4H7Bk1Ol3qA3jYA1pNd8aZR40HX2NF8 /Yg5qePkDh5+DeDpk5NcvdSsXH1s+0K4Fdt8Q6vLcNi9ga46cNNRDSHkKBoOuQ4pvwA9 3Ci/bs8xz84WPitMhq/fA4WaHHCXvd9Pl8j8YtkbaNqvRkm1fLx5SI8fwJwFZfbTLoJc 6Sj4ODC0a1U3FtesLeYL+tFeEJEdaLSgQh+D2YQpKNg4NQsPJ8KkNIdXnsQkWJgqqd2A X3LA== 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=BzJtR2tKaZqh8MfQ9ZcYL3o8pZUvjNp8K0z781ytOeY=; b=DdqPWo1dH2sfTBphAxJQselryZjCzhsa1/v/B7YrOHeNfoMY0Tkb52g+qIobhn7n+q yUzistw3DCbUXJpkKI7qxQNvLyhLKLo4thAwwYUY0Ti37D+fiaRyav0ahkcxKoGQ/OgD OZbTiPti1Q9sjKVWwtUeb3NV6i/Hqzpdi4LGDMyJKysI14F1Hp8CeMd6t/VqKEnA2rCr OzbYcz4c5CvxF9tb6CZ+UBujUsKEYutXnB3+wxDMb7D1SMKW4i3boKgoLxxxT+4NU5Nt fnUZWeqAFM4iqm20ugIZtxsjM0HhRB/HCZ1bb640jiwrtqz+OajjYo+GLcMwe0+FPbVz SrCA== X-Gm-Message-State: AOAM533ImW2giMdT5NaYwuW67oE+2m3qdFreyLr0wMezIL8i+oMuRoNU yQ1fk7Mk3XP7tYmzu17B/eDXIYh+wt8= X-Google-Smtp-Source: ABdhPJw/6NlX0q/H4q/T99bGdjwHdJ6sGXugK9QP6KDHov2/DIDWMlKKeEyeTvrZLtGk2wKwUnkIBw== X-Received: by 2002:a05:600c:35c4:: with SMTP id r4mr6929078wmq.194.1631453017493; Sun, 12 Sep 2021 06:23:37 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c2sm4520744wrs.60.2021.09.12.06.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:37 -0700 (PDT) Message-Id: <7ace030c7093f6a0822fe45389d88df39df4d66b.1631453010.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:25 +0000 Subject: [PATCH v2 09/14] add: update --chmod to skip sparse paths Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee We added checks for path_in_sparse_checkout() to portions of 'git add' that add warnings and prevent staging a modification, but we skipped the --chmod mode. Update chmod_pathspec() to ignore cache entries whose path is outside of the sparse-checkout cone (unless --sparse is provided). Add a test in t3705. Signed-off-by: Derrick Stolee --- builtin/add.c | 4 +++- t/t3705-add-sparse-checkout.sh | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index f8e3930608d..f87b8134b67 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -47,7 +47,9 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only) struct cache_entry *ce = active_cache[i]; int err; - if (!include_sparse && ce_skip_worktree(ce)) + if (!include_sparse && + (ce_skip_worktree(ce) || + !path_in_sparse_checkout(ce->name, &the_index))) continue; if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL)) diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 0f7e03b5326..6fc49a1845f 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -39,7 +39,7 @@ setup_gitignore () { test_sparse_entry_unstaged () { git status --porcelain >actual && - ! grep "^M sparse_entry\$" actual + ! grep "^M[ M] sparse_entry\$" actual } test_expect_success 'setup' " @@ -169,11 +169,19 @@ test_expect_success 'git add fails outside of sparse-checkout definition' ' test_must_fail git add sparse_entry && test_sparse_entry_unstaged && + test_must_fail git add --chmod=+x sparse_entry && + test_sparse_entry_unstaged && + # Avoid munging CRLFs to avoid an error message git -c core.autocrlf=input add --sparse sparse_entry 2>stderr && test_must_be_empty stderr && test-tool read-cache --table >actual && - grep "^100644 blob.*sparse_entry\$" actual + grep "^100644 blob.*sparse_entry\$" actual && + + git add --sparse --chmod=+x sparse_entry 2>stderr && + test_must_be_empty stderr && + test-tool read-cache --table >actual && + grep "^100755 blob.*sparse_entry\$" actual ' test_expect_success 'add obeys advice.updateSparsePath' ' From patchwork Sun Sep 12 13:23:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486911 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.8 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 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 283D6C433F5 for ; Sun, 12 Sep 2021 13:23:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 103FE61056 for ; Sun, 12 Sep 2021 13:23:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235757AbhILNZB (ORCPT ); Sun, 12 Sep 2021 09:25:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235498AbhILNYx (ORCPT ); Sun, 12 Sep 2021 09:24:53 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68E64C061767 for ; Sun, 12 Sep 2021 06:23:39 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id v20-20020a1cf714000000b002e71f4d2026so3648675wmh.1 for ; Sun, 12 Sep 2021 06:23:39 -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=OD0DF47tv0H5WlRb1hRZ7B8WyzsT+wEwZ+5J6dglwUE=; b=qcw1LEJT/r2LrvDN4XwJGKTqpHAL/2LjcxbMj83BDM/MoMy9BKVEp0IrGdvyorljZV Qq2n+0kkjtWe5G7I3RwU3Uq1uJdKWywaY0YrtSuQlaOPj1KxhQOq9BCn8Jp+rdRubacR evB7vVMnooLUjH6c9EgTGzhC3MOYbTr5Si89kbYPOq+b/fWlnt3YqWhwumAe3BRl7jT+ dNpoSaL1gL+CPryrjYh4gptyDYZpq7IDkVNl7E4bfNV7ZFeKc8tEYyjMrNIkcjcXrVwU onFTmvWYY+SZZ99ZgXiJplEi+Jryze6WnPzrCACkfRXk4BABOTEISvT6obWDZQNqezyu fPrg== 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=OD0DF47tv0H5WlRb1hRZ7B8WyzsT+wEwZ+5J6dglwUE=; b=ZiD1/70MJF8gfsQYftMauVJSahjx8Uk7rYSc9AS7CCEFuMC0dVn7RLmIAqAQXxXPYP YEROPdzeamR7gmXsGScqrbLy2uQG9XgVTEx0wHZevUf6DwFwr91U+xNlsYW86Hfw3Nrs jMjEtkkeJa1h+skiTnQLEcJDnSTy/xi1FyCBZPaa8mrMkVNJ4vO0wJhWkboesG3wVyZl uj/vjq7NyjuuGWgJ2KmY5B4vL34mq4gvCK3EM8pCY+unaKrnzgfgOCe0YhU7e6I+RSc3 B2Ba4y+o4/KmJIJaciqI+Wypuup3Z9zJjNujl/C5aKxdsfsVVJxvmD3fa88uQhk+2VL0 dvIA== X-Gm-Message-State: AOAM533Hdn7ZoNjNPGFyzCKZBnRuWDf75iWNk4RXENZ24TeHCmov/MFQ N5V3cquCuYGHlApToL9l/M/RkBLK8EE= X-Google-Smtp-Source: ABdhPJysnWCdfzd/siSuoK9rgH5J4lLt2j8ZjXtUUxDn2V490nCEk8+GgB4Uc44VDoLPJi4wrSeZOw== X-Received: by 2002:a1c:a913:: with SMTP id s19mr6582056wme.26.1631453018070; Sun, 12 Sep 2021 06:23:38 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r25sm4534562wra.76.2021.09.12.06.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:37 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:26 +0000 Subject: [PATCH v2 10/14] add: update --renormalize to skip sparse paths Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee We added checks for path_in_sparse_checkout() to portions of 'git add' that add warnings and prevent stagins a modification, but we skipped the --renormalize mode. Update renormalize_tracked_files() to ignore cache entries whose path is outside of the sparse-checkout cone (unless --sparse is provided). Add a test in t3705. Signed-off-by: Derrick Stolee --- builtin/add.c | 4 +++- t/t3705-add-sparse-checkout.sh | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index f87b8134b67..f8f0dfa4046 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -154,7 +154,9 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags) for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; - if (ce_skip_worktree(ce)) + if (!include_sparse && + (ce_skip_worktree(ce) || + !path_in_sparse_checkout(ce->name, &the_index))) continue; if (ce_stage(ce)) continue; /* do not touch unmerged paths */ diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 6fc49a1845f..cf2ccb87cf2 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -172,6 +172,9 @@ test_expect_success 'git add fails outside of sparse-checkout definition' ' test_must_fail git add --chmod=+x sparse_entry && test_sparse_entry_unstaged && + test_must_fail git add --renormalize sparse_entry && + test_sparse_entry_unstaged && + # Avoid munging CRLFs to avoid an error message git -c core.autocrlf=input add --sparse sparse_entry 2>stderr && test_must_be_empty stderr && @@ -181,7 +184,14 @@ test_expect_success 'git add fails outside of sparse-checkout definition' ' git add --sparse --chmod=+x sparse_entry 2>stderr && test_must_be_empty stderr && test-tool read-cache --table >actual && - grep "^100755 blob.*sparse_entry\$" actual + grep "^100755 blob.*sparse_entry\$" actual && + + git reset && + + # This will print a message over stderr on Windows. + git add --sparse --renormalize sparse_entry && + git status --porcelain >actual && + grep "^M sparse_entry\$" actual ' test_expect_success 'add obeys advice.updateSparsePath' ' From patchwork Sun Sep 12 13:23:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486913 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.8 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 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 BBD4DC433EF for ; Sun, 12 Sep 2021 13:23:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2BD0610CE for ; Sun, 12 Sep 2021 13:23:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235433AbhILNZD (ORCPT ); Sun, 12 Sep 2021 09:25:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235513AbhILNYy (ORCPT ); Sun, 12 Sep 2021 09:24:54 -0400 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 0A41FC061574 for ; Sun, 12 Sep 2021 06:23:40 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id t18so10317354wrb.0 for ; Sun, 12 Sep 2021 06:23:39 -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=S+9e4DSe77dvVgiDAcpgdRbCJzwJrdluslPwAilivOc=; b=OP2isgEJ9XIvcPD6sEFvy8pcg2q8bcjOr1B5aRM9PW3K9pH3OYYdgHbs/8VuRJP4t+ bmp0X3I+Ljct5q/njakoFAAaUf+ojdZGTjlOcs/ROJHynyYcmizvDVJfj0BolHwu9+QS UAb9DC3cLxZDAB7viaYWz7kW94MGFTSGOZ5fFf1qbb8SJaXM16e3CjOoaMxMtwhDyYt8 qLzkPjXo+Lytp64+EVnDQbqC75WtEDC2WUtHnj9g5Q/eOQfQBrX7qJlrM1q+kOFhWaTU +jEV2WbX3YnTFZMsJCnd4lZsXDLJX46FqWyLVhnY2ErRuXCjEHLCLUvNC76wacfOjZRW Rlxg== 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=S+9e4DSe77dvVgiDAcpgdRbCJzwJrdluslPwAilivOc=; b=wpBOlZfKprOhdpI6UqIMElpivMgKuDjcedqmp+7rDTdM1HHaxkP7nf3C3Qz+WtxDa2 TjS9CTkAX3TTvOkKiGhVuQ7YjwhKsBKCxGPkuRg84nD9/ydTiXlIg9EGySeiSmCAElAM IB1tBVau1KrI4GhGLp+nIsG7JXVCpIJuoc9N9FRS2ty5Xrf8mEAJae32xnm6U3RGqZE1 L+XrOF19zWOLyNQ7piJ1V04Rrqpu5BYWAjbCx/Cgh2pNWtjhyXPcrmuIi8Nda4FH1lyL zmiJCYUjofruf88mHeBWaMDztcfuImd+Kqb5nwqD6tmldJfhTH3Hj467vz7EpnI7kK68 5ymg== X-Gm-Message-State: AOAM53012q2TsIeKKsizECTKN1QL/xGJ62AOthDdkORzuuwA2pszrmbX XD0OGrIdJhO/d1qGjMcRPQihAgBH6wo= X-Google-Smtp-Source: ABdhPJxgmljMw9OflUNuiMtqBsVpGP5vPKIFZD7zoz7wCcrf19wzNZNIaahD3tqWaLISExKgpzoIow== X-Received: by 2002:a5d:47a4:: with SMTP id 4mr7668311wrb.329.1631453018706; Sun, 12 Sep 2021 06:23:38 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h18sm4603376wrb.33.2021.09.12.06.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:38 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:27 +0000 Subject: [PATCH v2 11/14] rm: add --sparse option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee As we did previously in 'git add', add a '--sparse' option to 'git rm' that allows modifying paths outside of the sparse-checkout definition. The existing checks in 'git rm' are restricted to tracked files that have the SKIP_WORKTREE bit in the current index. Future changes will cause 'git rm' to reject removing paths outside of the sparse-checkout definition, even if they are untracked or do not have the SKIP_WORKTREE bit. Signed-off-by: Derrick Stolee --- Documentation/git-rm.txt | 6 ++++++ builtin/rm.c | 8 ++++++-- t/t3602-rm-sparse-checkout.sh | 12 ++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt index 26e9b284704..81bc23f3cdb 100644 --- a/Documentation/git-rm.txt +++ b/Documentation/git-rm.txt @@ -72,6 +72,12 @@ For more details, see the 'pathspec' entry in linkgit:gitglossary[7]. --ignore-unmatch:: Exit with a zero status even if no files matched. +--sparse:: + Allow updating index entries outside of the sparse-checkout cone. + Normally, `git rm` refuses to update index entries whose paths do + not fit within the sparse-checkout cone. See + linkgit:git-sparse-checkout[1] for more. + -q:: --quiet:: `git rm` normally outputs one line (in the form of an `rm` command) diff --git a/builtin/rm.c b/builtin/rm.c index 8a24c715e02..4208f3f9a5f 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -237,6 +237,7 @@ static int check_local_mod(struct object_id *head, int index_only) static int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0; static int ignore_unmatch = 0, pathspec_file_nul; +static int include_sparse; static char *pathspec_from_file; static struct option builtin_rm_options[] = { @@ -247,6 +248,7 @@ static struct option builtin_rm_options[] = { OPT_BOOL('r', NULL, &recursive, N_("allow recursive removal")), OPT_BOOL( 0 , "ignore-unmatch", &ignore_unmatch, N_("exit with a zero status even if nothing matched")), + OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")), OPT_PATHSPEC_FROM_FILE(&pathspec_from_file), OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul), OPT_END(), @@ -298,7 +300,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix) ensure_full_index(&the_index); for (i = 0; i < active_nr; i++) { const struct cache_entry *ce = active_cache[i]; - if (ce_skip_worktree(ce)) + + if (!include_sparse && ce_skip_worktree(ce)) continue; if (!ce_path_match(&the_index, ce, &pathspec, seen)) continue; @@ -322,7 +325,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix) seen_any = 1; else if (ignore_unmatch) continue; - else if (matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) + else if (!include_sparse && + matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) string_list_append(&only_match_skip_worktree, original); else die(_("pathspec '%s' did not match any files"), original); diff --git a/t/t3602-rm-sparse-checkout.sh b/t/t3602-rm-sparse-checkout.sh index e9e9a15c74c..493c8f636b8 100755 --- a/t/t3602-rm-sparse-checkout.sh +++ b/t/t3602-rm-sparse-checkout.sh @@ -43,6 +43,18 @@ test_expect_success 'recursive rm does not remove sparse entries' ' test_cmp expected actual ' +test_expect_success 'recursive rm --sparse removes sparse entries' ' + git reset --hard && + git sparse-checkout set "sub/dir" && + git rm --sparse -r sub && + git status --porcelain -uno >actual && + cat >expected <<-\EOF && + D sub/d + D sub/dir/e + EOF + test_cmp expected actual +' + test_expect_success 'rm obeys advice.updateSparsePath' ' git reset --hard && git sparse-checkout set a && From patchwork Sun Sep 12 13:23:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486917 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.8 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 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 92F0DC433EF for ; Sun, 12 Sep 2021 13:23:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76BAA610F9 for ; Sun, 12 Sep 2021 13:23:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235514AbhILNZG (ORCPT ); Sun, 12 Sep 2021 09:25:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235531AbhILNYz (ORCPT ); Sun, 12 Sep 2021 09:24:55 -0400 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 9273BC0613CF for ; Sun, 12 Sep 2021 06:23:40 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id t8so5232366wrq.4 for ; Sun, 12 Sep 2021 06:23:40 -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=Nh2RD3Yg/rudV33Lfw2h4WjGPfRbyKyvhLRmZNtCiNE=; b=FwARVdagbi6bHGlNS7mgsydgnnDdMRReb9mdwObqVcY2ff07O2RRuXtrlZTjdm849C aMzq8xIUOA1KY9I8heiSaCdDpFsK4jmNASuu8pjDzVN7PlBnCGdSSL6K+/e6tJAfrjOQ Al8/yivHv/C3ZJ4YZlOq9mAHNG6wkv23tjVvooW17OCoal5bqlFmvPtQQIIYPiwoOosZ 5+YOJwQ6PBF1uS1c7M4jJtsR6FHXpqpdTpfeBNNO507ikp95TGkO8oMponis0g+GCEx7 qQBK9pxookqWtCWUGvvCFXZ30H+GUio6bOaDvQVfvO9jKSLgZ8aimBg3yekwUsFCV6kr yTFA== 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=Nh2RD3Yg/rudV33Lfw2h4WjGPfRbyKyvhLRmZNtCiNE=; b=P40vuaRIMQNKTZnxS4+ovg9C8sbP0BgIT3u7F69tZ03R5FN/PyxVoivc3MRa7vudho 0LWnRo/XsUNqoxRlFXhDHzUL9oahYyvqciNgW2BI3ycfkvBLF7bC+a0TkSNqRQ1Lp9Go FSkVQd1IyAtjsF17nhI2KRp/IQDw3EAxHHFNIst6E8ubSzqtg+ZNe8Ql41l1TBE6ACPJ /dOiuq6OffBpvuOE6IXI13omeWdKmaVJANW7he3QXsc62kH3sBXyF3HJSf7VLvsjbPiA b9rp00s3ZGmxEP6qItEyEp9ROxJgKsR8wLe9XG9jHFyU68glSLsUc1gvkGOKcb2/Ixd/ /JMg== X-Gm-Message-State: AOAM530b8E8mhv8Pakwj3jV8kiest40ADEQUe7b/QyBE/WH3HRmqA1Nl JPLfvXXjJPBu2BZ85jhlAwvyhlQnHlw= X-Google-Smtp-Source: ABdhPJzhLSLj3NsFVQ1JP/Fqepr5r+vMx03Ny+xpRg7qMbPoBkZDBg7qL3B0I+UyclPjIzEtzXTBKg== X-Received: by 2002:adf:c501:: with SMTP id q1mr7523845wrf.150.1631453019227; Sun, 12 Sep 2021 06:23:39 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m18sm4461807wrn.85.2021.09.12.06.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:38 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:28 +0000 Subject: [PATCH v2 12/14] rm: skip sparse paths with missing SKIP_WORKTREE Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee If a path does not match the sparse-checkout cone but is somehow missing the SKIP_WORKTREE bit, then 'git rm' currently succeeds in removing the file. One reason a user might be in this situation is a merge conflict outside of the sparse-checkout cone. Removing such a file might be problematic for users who are not sure what they are doing. Add a check to path_in_sparse_checkout() when 'git rm' is checking if a path should be considered for deletion. Of course, this check is ignored if the '--sparse' option is specified, allowing users who accept the risks to continue with the removal. This also removes a confusing behavior where a user asks for a directory to be removed, but only the entries that are within the sparse-checkout definition are removed. Now, 'git rm ' will fail without '--sparse' and will succeed in removing all contained paths with '--sparse'. Signed-off-by: Derrick Stolee --- builtin/rm.c | 4 +++- t/t3602-rm-sparse-checkout.sh | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/builtin/rm.c b/builtin/rm.c index 4208f3f9a5f..a6da03da2be 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -301,7 +301,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix) for (i = 0; i < active_nr; i++) { const struct cache_entry *ce = active_cache[i]; - if (!include_sparse && ce_skip_worktree(ce)) + if (!include_sparse && + (ce_skip_worktree(ce) || + !path_in_sparse_checkout(ce->name, &the_index))) continue; if (!ce_path_match(&the_index, ce, &pathspec, seen)) continue; diff --git a/t/t3602-rm-sparse-checkout.sh b/t/t3602-rm-sparse-checkout.sh index 493c8f636b8..5f92b60a56a 100755 --- a/t/t3602-rm-sparse-checkout.sh +++ b/t/t3602-rm-sparse-checkout.sh @@ -37,9 +37,13 @@ done test_expect_success 'recursive rm does not remove sparse entries' ' git reset --hard && git sparse-checkout set sub/dir && - git rm -r sub && + test_must_fail git rm -r sub && + git rm --sparse -r sub && git status --porcelain -uno >actual && - echo "D sub/dir/e" >expected && + cat >expected <<-\EOF && + D sub/d + D sub/dir/e + EOF test_cmp expected actual ' @@ -87,4 +91,15 @@ test_expect_success 'do not warn about sparse entries with --ignore-unmatch' ' git ls-files --error-unmatch b ' +test_expect_success 'refuse to rm a non-skip-worktree path outside sparse cone' ' + git reset --hard && + git sparse-checkout set a && + git update-index --no-skip-worktree b && + test_must_fail git rm b 2>stderr && + test_cmp b_error_and_hint stderr && + git rm --sparse b 2>stderr && + test_must_be_empty stderr && + test_path_is_missing b +' + test_done From patchwork Sun Sep 12 13:23:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486919 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.8 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 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 39662C433EF for ; Sun, 12 Sep 2021 13:23:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 23C4661056 for ; Sun, 12 Sep 2021 13:23:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235848AbhILNZJ (ORCPT ); Sun, 12 Sep 2021 09:25:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235552AbhILNYz (ORCPT ); Sun, 12 Sep 2021 09:24:55 -0400 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 2FC47C0613D8 for ; Sun, 12 Sep 2021 06:23:41 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id g16so10301228wrb.3 for ; Sun, 12 Sep 2021 06:23: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=CHuU91yH6kh+CD5Uo0bNvdZ4oWb+wQY5zc7hR6FDZdA=; b=ii1HFtxwweY4s9BmOFrTHDK3E7CjXuX6xbk68L5IKv9/cGX87h3n9zFlTCPhPx0C+w eB9vxKpJR6krCsdXY8GZnzmi1601iUyetFWzqVYQ44KYK9riHGV52Y8sKzrtNTcSGjc2 3C5ML2zLdm/5SIcmCWXS8PHjh3U8HCMNiA/z9bJ4qR9mjnoHnCDtCsXWHk4eiCCaHMgI V06XyJqIsbrfjwMOuqINpWDRxVvjcyiJY1J4GKOB/dH4RFkQKUrV8aJ9peMK2Pc7NtL3 X/q/ekdfnenZcaYVQhjxGC6QjBE6r3+m6zYe/VgXFa4R7YciCmxJS2WajQLNtJGu1VeN pUtg== 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=CHuU91yH6kh+CD5Uo0bNvdZ4oWb+wQY5zc7hR6FDZdA=; b=o3xk/LSv5TgDkuRM8GYVBCaE2QuQ34+6vLvZL/PGRfdyY8QZF/hOaySLiy5a+JV1Do E8dc6NllCpzBQk1OU1P0AI/YYZlLtXRi4yeiHumPkenbVgHDpbjQZzMQghG02xZpWnGx T7rsIheh5KwSo9bJG/US1280PXliIXMqwfg3TLveR9jd+qwkZ5DEZnzad1p2vdKxg1CM hMmBMcgtOdc5npvu1D2sltSB8oHHFptvxA8QSO4etYl3wHkxffrPHj5uWN3AVeWYh8ye 2w1Z/j73XlABFQGd2NJdOQs22vRquItmgD+cYG8NzBPbwUJaR2vLjwrb41iOMfCmYFE1 uYUg== X-Gm-Message-State: AOAM530QDX6AblL4ODpgArFStvVlVG0V2Uq62m/T6Fvr6tPvok1QuAqj Gr6lYpIZiX2BnPZXxfhqErMG4N/jJ2s= X-Google-Smtp-Source: ABdhPJwjdhJH1t52oyJhxHk77oKk2UBulHBfQ8zQumqLrM8Ap1sXDlFzqIGX0VFrnpyAmYoFVR7Umg== X-Received: by 2002:adf:fac7:: with SMTP id a7mr7483565wrs.341.1631453019785; Sun, 12 Sep 2021 06:23:39 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r27sm4479726wrr.70.2021.09.12.06.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:39 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:29 +0000 Subject: [PATCH v2 13/14] mv: refuse to move sparse paths Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Since cmd_mv() does not operate on cache entries and instead directly checks the filesystem, we can only use path_in_sparse_checkout() as a mechanism for seeing if a path is sparse or not. Be sure to skip returning a failure if '-k' is specified. To ensure that the advice around sparse paths is the only reason a move failed, be sure to check this as the very last thing before inserting into the src_for_dst list. The tests cover a variety of cases such as whether the target is tracked or untracked, and whether the source or destination are in or outside of the sparse-checkout definition. Helped-by: Matheus Tavares Bernardino Signed-off-by: Derrick Stolee --- builtin/mv.c | 52 ++++++++-- t/t7002-mv-sparse-checkout.sh | 186 ++++++++++++++++++++++++++++++++++ 2 files changed, 229 insertions(+), 9 deletions(-) create mode 100755 t/t7002-mv-sparse-checkout.sh diff --git a/builtin/mv.c b/builtin/mv.c index c2f96c8e895..83a465ba831 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -118,21 +118,23 @@ static int index_range_of_same_dir(const char *src, int length, int cmd_mv(int argc, const char **argv, const char *prefix) { int i, flags, gitmodules_modified = 0; - int verbose = 0, show_only = 0, force = 0, ignore_errors = 0; + int verbose = 0, show_only = 0, force = 0, ignore_errors = 0, ignore_sparse = 0; struct option builtin_mv_options[] = { OPT__VERBOSE(&verbose, N_("be verbose")), OPT__DRY_RUN(&show_only, N_("dry run")), OPT__FORCE(&force, N_("force move/rename even if target exists"), PARSE_OPT_NOCOMPLETE), OPT_BOOL('k', NULL, &ignore_errors, N_("skip move/rename errors")), + OPT_BOOL(0, "sparse", &ignore_sparse, N_("allow updating entries outside of the sparse-checkout cone")), OPT_END(), }; const char **source, **destination, **dest_path, **submodule_gitfile; - enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes; + enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX, SPARSE } *modes; struct stat st; struct string_list src_for_dst = STRING_LIST_INIT_NODUP; struct lock_file lock_file = LOCK_INIT; struct cache_entry *ce; + struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP; git_config(git_default_config, NULL); @@ -176,14 +178,17 @@ int cmd_mv(int argc, const char **argv, const char *prefix) const char *src = source[i], *dst = destination[i]; int length, src_is_dir; const char *bad = NULL; + int skip_sparse = 0; if (show_only) printf(_("Checking rename of '%s' to '%s'\n"), src, dst); length = strlen(src); - if (lstat(src, &st) < 0) - bad = _("bad source"); - else if (!strncmp(src, dst, length) && + if (lstat(src, &st) < 0) { + /* only error if existence is expected. */ + if (modes[i] != SPARSE) + bad = _("bad source"); + } else if (!strncmp(src, dst, length) && (dst[length] == 0 || dst[length] == '/')) { bad = _("can not move directory into itself"); } else if ((src_is_dir = S_ISDIR(st.st_mode)) @@ -212,11 +217,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix) dst_len = strlen(dst); for (j = 0; j < last - first; j++) { - const char *path = active_cache[first + j]->name; + const struct cache_entry *ce = active_cache[first + j]; + const char *path = ce->name; source[argc + j] = path; destination[argc + j] = prefix_path(dst, dst_len, path + length + 1); - modes[argc + j] = INDEX; + modes[argc + j] = ce_skip_worktree(ce) ? SPARSE : INDEX; submodule_gitfile[argc + j] = NULL; } argc += last - first; @@ -244,14 +250,36 @@ int cmd_mv(int argc, const char **argv, const char *prefix) bad = _("multiple sources for the same target"); else if (is_dir_sep(dst[strlen(dst) - 1])) bad = _("destination directory does not exist"); - else + else { + /* + * We check if the paths are in the sparse-checkout + * definition as a very final check, since that + * allows us to point the user to the --sparse + * option as a way to have a successful run. + */ + if (!ignore_sparse && + !path_in_sparse_checkout(src, &the_index)) { + string_list_append(&only_match_skip_worktree, src); + skip_sparse = 1; + } + if (!ignore_sparse && + !path_in_sparse_checkout(dst, &the_index)) { + string_list_append(&only_match_skip_worktree, dst); + skip_sparse = 1; + } + + if (skip_sparse) + goto remove_entry; + string_list_insert(&src_for_dst, dst); + } if (!bad) continue; if (!ignore_errors) die(_("%s, source=%s, destination=%s"), bad, src, dst); +remove_entry: if (--argc > 0) { int n = argc - i; memmove(source + i, source + i + 1, @@ -266,6 +294,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix) } } + if (only_match_skip_worktree.nr) { + advise_on_updating_sparse_paths(&only_match_skip_worktree); + if (!ignore_errors) + return 1; + } + for (i = 0; i < argc; i++) { const char *src = source[i], *dst = destination[i]; enum update_mode mode = modes[i]; @@ -274,7 +308,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) printf(_("Renaming %s to %s\n"), src, dst); if (show_only) continue; - if (mode != INDEX && rename(src, dst) < 0) { + if (mode != INDEX && mode != SPARSE && rename(src, dst) < 0) { if (ignore_errors) continue; die_errno(_("renaming '%s' failed"), src); diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh new file mode 100755 index 00000000000..07dbfeb6d17 --- /dev/null +++ b/t/t7002-mv-sparse-checkout.sh @@ -0,0 +1,186 @@ +#!/bin/sh + +test_description='git mv in sparse working trees' + +. ./test-lib.sh + +test_expect_success 'setup' " + mkdir -p sub/dir sub/dir2 && + touch a b c sub/d sub/dir/e sub/dir2/e && + git add -A && + git commit -m files && + + cat >sparse_error_header <<-EOF && + The following pathspecs didn't match any eligible path, but they do match index + entries outside the current sparse checkout: + EOF + + cat >sparse_hint <<-EOF + hint: Disable or modify the sparsity rules if you intend to update such entries. + hint: Disable this message with \"git config advice.updateSparsePath false\" + EOF +" + +test_expect_success 'mv refuses to move sparse-to-sparse' ' + test_when_finished rm -f e && + git reset --hard && + git sparse-checkout set a && + touch b && + test_must_fail git mv b e 2>stderr && + cat sparse_error_header >expect && + echo b >>expect && + echo e >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + git mv --sparse b e 2>stderr && + test_must_be_empty stderr +' + +test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' ' + test_when_finished rm -f b c e && + git reset --hard && + git sparse-checkout set a && + + # tracked-to-untracked + touch b && + git mv -k b e 2>stderr && + test_path_exists b && + test_path_is_missing e && + cat sparse_error_header >expect && + echo b >>expect && + echo e >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + + git mv --sparse b e 2>stderr && + test_must_be_empty stderr && + test_path_is_missing b && + test_path_exists e && + + # tracked-to-tracked + git reset --hard && + touch b && + git mv -k b c 2>stderr && + test_path_exists b && + test_path_is_missing c && + cat sparse_error_header >expect && + echo b >>expect && + echo c >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + + git mv --sparse b c 2>stderr && + test_must_be_empty stderr && + test_path_is_missing b && + test_path_exists c +' + +test_expect_success 'mv refuses to move non-sparse-to-sparse' ' + test_when_finished rm -f b c e && + git reset --hard && + git sparse-checkout set a && + + # tracked-to-untracked + test_must_fail git mv a e 2>stderr && + test_path_exists a && + test_path_is_missing e && + cat sparse_error_header >expect && + echo e >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + git mv --sparse a e 2>stderr && + test_must_be_empty stderr && + test_path_is_missing a && + test_path_exists e && + + # tracked-to-tracked + rm e && + git reset --hard && + test_must_fail git mv a c 2>stderr && + test_path_exists a && + test_path_is_missing c && + cat sparse_error_header >expect && + echo c >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + git mv --sparse a c 2>stderr && + test_must_be_empty stderr && + test_path_is_missing a && + test_path_exists c +' + +test_expect_success 'mv refuses to move sparse-to-non-sparse' ' + test_when_finished rm -f b c e && + git reset --hard && + git sparse-checkout set a e && + + # tracked-to-untracked + touch b && + test_must_fail git mv b e 2>stderr && + cat sparse_error_header >expect && + echo b >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + git mv --sparse b e 2>stderr && + test_must_be_empty stderr +' + +test_expect_success 'recursive mv refuses to move (possible) sparse' ' + test_when_finished rm -rf b c e sub2 && + git reset --hard && + # Without cone mode, "sub" and "sub2" do not match + git sparse-checkout set sub/dir sub2/dir && + + # Add contained contents to ensure we avoid non-existence errors + mkdir sub/dir2 && + touch sub/d sub/dir2/e && + + test_must_fail git mv sub sub2 2>stderr && + cat sparse_error_header >expect && + cat >>expect <<-\EOF && + sub/d + sub2/d + sub/dir/e + sub2/dir/e + sub/dir2/e + sub2/dir2/e + EOF + cat sparse_hint >>expect && + test_cmp expect stderr && + git mv --sparse sub sub2 2>stderr && + test_must_be_empty stderr && + git commit -m "moved sub to sub2" && + git rev-parse HEAD~1:sub >expect && + git rev-parse HEAD:sub2 >actual && + test_cmp expect actual && + git reset --hard HEAD~1 +' + +test_expect_success 'recursive mv refuses to move sparse' ' + git reset --hard && + # Use cone mode so "sub/" matches the sparse-checkout patterns + git sparse-checkout init --cone && + git sparse-checkout set sub/dir sub2/dir && + + # Add contained contents to ensure we avoid non-existence errors + mkdir sub/dir2 && + touch sub/dir2/e && + + test_must_fail git mv sub sub2 2>stderr && + cat sparse_error_header >expect && + cat >>expect <<-\EOF && + sub/dir2/e + sub2/dir2/e + EOF + cat sparse_hint >>expect && + test_cmp expect stderr && + git mv --sparse sub sub2 2>stderr && + test_must_be_empty stderr && + git commit -m "moved sub to sub2" && + git rev-parse HEAD~1:sub >expect && + git rev-parse HEAD:sub2 >actual && + test_cmp expect actual && + git reset --hard HEAD~1 +' + +test_done From patchwork Sun Sep 12 13:23:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12486915 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.8 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 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 B2A7DC433F5 for ; Sun, 12 Sep 2021 13:23:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FC6B610CE for ; Sun, 12 Sep 2021 13:23:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235606AbhILNZE (ORCPT ); Sun, 12 Sep 2021 09:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235361AbhILNY4 (ORCPT ); Sun, 12 Sep 2021 09:24:56 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A73F0C061760 for ; Sun, 12 Sep 2021 06:23:41 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id u15so4212244wru.6 for ; Sun, 12 Sep 2021 06:23: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=+y2AAdAhEyZsmUIO9HanjQPgDeAly1FBHzUsSpXC6ic=; b=ImJa1iW9uPhRAhK8JOxl0pQ+YS8jO5LpJ7zAmOJ3wV6GSsKzxUYL0aejMyIl7yy2Z4 9gBJjmfHfvDMve+fWTSPznV2XqvAOgL9ceTiJmOwaQicd7QrZ/FjW9FypONAiBN2mvqv bnvHdkgAC78LRiC+Cu5xwfsdqrTVqutPpEMi/BvmLtMjT4dbL8WyDHlGe6RvHOrt29SS YIrG+LBNEg1k5Lt7/8xsohkBUbcffMG672T5Gsxw/3+PV0oFoKoJarUFaluqzNmiR1ju DhYE+FHQW51ZMbtKNH1r2YTj875LNE2FWdOT75pUW7sabb0KKbMKyWfuY99wpsynmAOU YIKQ== 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=+y2AAdAhEyZsmUIO9HanjQPgDeAly1FBHzUsSpXC6ic=; b=vCmhkENOVS2jUBxHh7zGHOqF5NCp8kSx61d/6js6kYs4+iyC0JrKgOYKRoF7wF3kdT e8neh9uky5kBVpEiEeI3casIdYHEjjpvy2zyOw5NitBt47imH+7wVo0mYX95wT6pEwpS msBOGNkaRT8bd8tlJgLcgSqc3sCsp4Z05RNZe1zA7hBz64h2Ksuk4eEv0RlcrzPDeVj/ TT1Lynna+Ly0aO0tHCulKz0+iuY3o0n/3q8olFkkBmu2hTODAR+CSnLVkKxZe8UaUMiq MPtaDuzDeVzWmhybVu/YhJ/axaaM32vOo24y6xOgXOIl4Rg6/MpdELISMX4PkH3A7JG3 o24Q== X-Gm-Message-State: AOAM531SF0laaKdfbvn+1GvBnGux/fnAwWfgNlvVil7mSGp2VVEcncGq KDhyP22ijtFV8IHWMK6ri0Asf1U1jbg= X-Google-Smtp-Source: ABdhPJyUhkuTRYteDxS99mId11CwpodBQmwOFerz6ItRxISlUZoDqzRUILm04ivlKrVXgRARq0zVkQ== X-Received: by 2002:a5d:59ae:: with SMTP id p14mr7327786wrr.278.1631453020335; Sun, 12 Sep 2021 06:23:40 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v17sm4418605wrr.69.2021.09.12.06.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 06:23:40 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sun, 12 Sep 2021 13:23:30 +0000 Subject: [PATCH v2 14/14] advice: update message to suggest '--sparse' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The previous changes modified the behavior of 'git add', 'git rm', and 'git mv' to not adjust paths outside the sparse-checkout cone, even if they exist in the working tree and their cache entries lack the SKIP_WORKTREE bit. The intention is to warn users that they are doing something potentially dangerous. The '--sparse' option was added to each command to allow careful users the same ability they had before. To improve the discoverability of this new functionality, add a message to advice.updateSparsePath that mentions the existence of the option. The previous set of changes also modified the purpose of this message to include possibly a list of paths instead of only a list of pathspecs. Make the warning message more clear about this new behavior. Signed-off-by: Derrick Stolee --- advice.c | 10 ++++++---- t/t3602-rm-sparse-checkout.sh | 6 +++--- t/t3705-add-sparse-checkout.sh | 6 +++--- t/t7002-mv-sparse-checkout.sh | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/advice.c b/advice.c index 0b9c89c48ab..0deaf111795 100644 --- a/advice.c +++ b/advice.c @@ -293,14 +293,16 @@ void advise_on_updating_sparse_paths(struct string_list *pathspec_list) if (!pathspec_list->nr) return; - fprintf(stderr, _("The following pathspecs didn't match any" - " eligible path, but they do match index\n" - "entries outside the current sparse checkout:\n")); + fprintf(stderr, _("The following paths and/or pathspecs matched " + "paths that exist outside of your\n" + "sparse-checkout definition, so will not be " + "updated in the index:\n")); for_each_string_list_item(item, pathspec_list) fprintf(stderr, "%s\n", item->string); advise_if_enabled(ADVICE_UPDATE_SPARSE_PATH, - _("Disable or modify the sparsity rules if you intend" + _("Disable or modify the sparsity rules or" + " use the --sparse option if you intend" " to update such entries.")); } diff --git a/t/t3602-rm-sparse-checkout.sh b/t/t3602-rm-sparse-checkout.sh index 5f92b60a56a..712ddae2b15 100755 --- a/t/t3602-rm-sparse-checkout.sh +++ b/t/t3602-rm-sparse-checkout.sh @@ -11,12 +11,12 @@ test_expect_success 'setup' " git commit -m files && cat >sparse_error_header <<-EOF && - The following pathspecs didn't match any eligible path, but they do match index - entries outside the current sparse checkout: + The following paths and/or pathspecs matched paths that exist outside of your + sparse-checkout definition, so will not be updated in the index: EOF cat >sparse_hint <<-EOF && - hint: Disable or modify the sparsity rules if you intend to update such entries. + hint: Disable or modify the sparsity rules or use the --sparse option if you intend to update such entries. hint: Disable this message with \"git config advice.updateSparsePath false\" EOF diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index cf2ccb87cf2..d51c96f8d72 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -44,12 +44,12 @@ test_sparse_entry_unstaged () { test_expect_success 'setup' " cat >sparse_error_header <<-EOF && - The following pathspecs didn't match any eligible path, but they do match index - entries outside the current sparse checkout: + The following paths and/or pathspecs matched paths that exist outside of your + sparse-checkout definition, so will not be updated in the index: EOF cat >sparse_hint <<-EOF && - hint: Disable or modify the sparsity rules if you intend to update such entries. + hint: Disable or modify the sparsity rules or use the --sparse option if you intend to update such entries. hint: Disable this message with \"git config advice.updateSparsePath false\" EOF diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index 07dbfeb6d17..3db7ddaba9a 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -11,12 +11,12 @@ test_expect_success 'setup' " git commit -m files && cat >sparse_error_header <<-EOF && - The following pathspecs didn't match any eligible path, but they do match index - entries outside the current sparse checkout: + The following paths and/or pathspecs matched paths that exist outside of your + sparse-checkout definition, so will not be updated in the index: EOF cat >sparse_hint <<-EOF - hint: Disable or modify the sparsity rules if you intend to update such entries. + hint: Disable or modify the sparsity rules or use the --sparse option if you intend to update such entries. hint: Disable this message with \"git config advice.updateSparsePath false\" EOF "