From patchwork Mon Sep 20 17:45: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: 12506589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 93356C433EF for ; Mon, 20 Sep 2021 23:37:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C46660F48 for ; Mon, 20 Sep 2021 23:37:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241896AbhITXin (ORCPT ); Mon, 20 Sep 2021 19:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243075AbhITXgh (ORCPT ); Mon, 20 Sep 2021 19:36:37 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ED77C0EDAF3 for ; Mon, 20 Sep 2021 10:45:41 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id w29so32028708wra.8 for ; Mon, 20 Sep 2021 10:45: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=KspwnxdSa8Er+jl4dIgKxxwdOBY1RzcdnW/5uRa4oOI=; b=aKmztAC0UW1t1v3TDt+bFVlpiSGgSMNza6L9l9DhOqXLnAtDgoZJqbSCVN84H2JSP9 tOvmk5HC0tRKeOLHiBxsLO4slGrUEBHV25Kh1GGJbRFfagw05cCMfetrjp32qmHxqEKD jJbng5P1tMTBnAgLJN29EKZbSJ0XOZ5MX7zrUsrA9kXwQknBDe9ofd8hXdaQ4VA6Bn2F pfmGlvOE5agA0kYXaKFj/pFVV4aMDyEwYcdULdAz+IUV54Yv21dT53hdwo8wN+7stYiP oqfXg+NnMmlPIAAt+Pp8ZCR6lV/fxtEy9FB9qm2RXVRS3uj1VoXsgiWLjZsQNYBp3tYe c8Vg== 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=KspwnxdSa8Er+jl4dIgKxxwdOBY1RzcdnW/5uRa4oOI=; b=K6edRA8qbLbfiNBahj8T52T2H5WnbLSXqh3B/p+gqBfCW7AXNVlY1eXUrgxiNKwDAi Zx2NyKMrS+gRKPvLpJNybmuPqYHi22dAL83T8wFOlKiaTq75JeKTKMSc67XbCD0/pTVy pddqymaitKE2q52RkVuPo63qEF6/UZbAMlkYVE63Vi6uOl6lW8GfbvgjG9xme5un3SDZ JVvzGBQt6LhBsq+SerhVyPX9Iul6D2qrvJbMycQtjyVCn+3vpU+K0xpRyjtd3XX47E7M 15/dWZaVH8j0/5sROMe/u5W4knI9iQEEw/COHJ5RbVf/pcjBMhTeSM7jUiy6/RYMIE4N 854A== X-Gm-Message-State: AOAM531c8Dd5NJPyJeiAfA/ZOq3J1OUmePc6uBwYRjpPbzaifEjkJ451 DrOk0xKvwBD/bm0M/rsI7UsqO6F25sM= X-Google-Smtp-Source: ABdhPJzVfAphOu3vDdnmzpcBY6IPUV5MZSQiaVxz7hsXKcC/9JtKFJbRAq5M+6Y2b/P0mTzlFV/rCw== X-Received: by 2002:adf:f486:: with SMTP id l6mr29409501wro.375.1632159939808; Mon, 20 Sep 2021 10:45:39 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k17sm858252wmj.0.2021.09.20.10.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:39 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:24 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 and as an entry in the index, but its exact contents are not 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..e202a2ff74a 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 "^[MDARCU][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 Mon Sep 20 17:45: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: 12506587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 B9D74C433F5 for ; Mon, 20 Sep 2021 23:37:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 966D360F48 for ; Mon, 20 Sep 2021 23:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241789AbhITXil (ORCPT ); Mon, 20 Sep 2021 19:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243082AbhITXgh (ORCPT ); Mon, 20 Sep 2021 19:36:37 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7817C0EDAF4 for ; Mon, 20 Sep 2021 10:45:41 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id g16so32044188wrb.3 for ; Mon, 20 Sep 2021 10:45: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=UtU2DmWqyc3//8gFeL1a4W4npwLEnpHhsy3ImlR7lY0=; b=o5cWIHWPZjlNTW3jFAsRX+Jl0HBL+h4InE5iMOWNwvadCSlCprCH78FvRyj6kT4dbf OOEE4OaInT3uzw1l9jvjMvBdXYnY8a2vkVgodL123QbA3WpKll0sSaGbPk8QL68EqISO DukLj3WJydt59eInpLaxUWrx3xjQYGv6e6iWtWSoKjFeRxViGNEW91ma0QKILB00P9Hu 6uKTBaFvKO4svpf4vgu45UozigZeN2VxiWLMq3qaKV3xf8XLlW/XIZfmsnejPdvxPnVS ww7i5zWpM+73nqnTWXdC6hVko8nMMDZU9AgEaY+0v8atedSxCFHNqUPeghj2d47DlcSL iApQ== 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=UtU2DmWqyc3//8gFeL1a4W4npwLEnpHhsy3ImlR7lY0=; b=5eCafby08RwagiJQ6oyWibj2XgLo493UCoBpfp1bLkWBDWsKioyAAB0fS4tNAs9Kk0 cBa1gyRCHx8Ibe0s56NUjUkpC3invGvG5m1znEkKpqrp103p3oVItnEsW9rl1dYixONa xWF8gRH/YjAngx0LwO0XPIofamxocfuKguJXtKPBRZlWtHwJZknA3MzKmJRtas5a6Fwn Vhjdum7QO3Xl9vZ1VDVR7mMN3U2kx1lj+ydgbvbPNfshRPorjXqTki/LTmxR8kYIhww7 ITlBfo778rhZC3lF2OKj/HuWaliNomDV4yKfnRx1NWdnY839/afGxwkRwZ0HHiNTo/Pd 3loQ== X-Gm-Message-State: AOAM5331Tacu1vXjqDTYQm9QTjj1EHBZa2rUZ9m8iciZx2Cc8arT8KQO I1XfF5oPfIl1DuZWiCEO8/wqhQDW5xo= X-Google-Smtp-Source: ABdhPJxK7FwQYYkMxd1QXIj/SRKyWB685rBUn3gtU30pvaTzkec+QsauqTiYBIhmKYiyUpbf4hP9Qg== X-Received: by 2002:a1c:a713:: with SMTP id q19mr288069wme.42.1632159940402; Mon, 20 Sep 2021 10:45:40 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g13sm171932wmh.20.2021.09.20.10.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:40 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:25 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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..3fb764f5eb9 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 && + grep "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 && + grep "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 && + grep "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 Mon Sep 20 17:45: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: 12506591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 D4CB7C433FE for ; Mon, 20 Sep 2021 23:37:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B86D261019 for ; Mon, 20 Sep 2021 23:37:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232608AbhITXio (ORCPT ); Mon, 20 Sep 2021 19:38:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239108AbhITXgi (ORCPT ); Mon, 20 Sep 2021 19:36:38 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7710DC0EDAF5 for ; Mon, 20 Sep 2021 10:45:42 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id q26so31993617wrc.7 for ; Mon, 20 Sep 2021 10:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2zkseZDCrX5eQCOfTAj1pziuYCUVx8n+RzgjO8cPYiw=; b=Pssoo3ciHqM41b3nZ13VGtWUScsdC6+w1gU3nbaYAKqtMQBzUzlTrE6x6k7139AkmO 2oIPVFEMpMA/1TkdL4pndKNQkJfiSwbeHrwzZ90U9vU5qEBXd+oGQ8oVFKshBl/5kHHp J5QA0dT4YKuH1nD8uCa4jUJfYx70isy9LNZ/tkpfiuSrQYGixUGNKOtUCsttu2ZINCYQ pbEJ04d++vtvUh9qC4ImRTDiwu0Sq+ov+H2gApcxybU7Nups97w0+CPc6vgdKmlxSJVr 21gGeg+PTitqpqFy5wga7qFKhxN3qo3YuL8D/7V6vbq5OklTpxCNperpsbR4EpMSNzdK ZOMA== 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=OW6YZgm0re3Ix4sd9/UMH5VSWXhWztFKBtdk4bKFJC2DXw5InKB2rPWqEidL1BLh1c ChMtx2ctz8P8bMfRwhOjtDK+/CokG+MXVIOaO2GoZVFWpQS3gv11WeyvubfkziFKI3qi isqfmJT28FHS8OA/aj3/l2cPT+P2jtWE4j7tCVF8n17+ivODpMvare35EUjmVI1E1RhA TtbMJDpZZLIFSKfkRmOgVkr2GkKkDpPCbzJ3GPuHApyKsJmaEw+GmwfdDcvQEUnp7aqB XR0DYmfOkok0BX4ixoweQOG2oCnlUMUDWRzHmZes06dX0ORYuEAiVEZu0EVRzvyt8Xk7 91FQ== X-Gm-Message-State: AOAM5318eOeB/bQUtSDkHPHZ+N6M+j/CaHt+O+juCuD6W/miyB+qYHV6 jOJnBx+2lDmfOk9IMXbcS678aEtO328= X-Google-Smtp-Source: ABdhPJxolkYQfZeIlSNkw7ZesZKk84JvC0SbMoU207QtOv8/cMRgqVutq80IRHk99cbJtGKyyQznxA== X-Received: by 2002:a05:600c:21c2:: with SMTP id x2mr239778wmj.103.1632159941097; Mon, 20 Sep 2021 10:45:41 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a72sm216555wme.5.2021.09.20.10.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:40 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:26 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 Mon Sep 20 17:45:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 2111CC433F5 for ; Mon, 20 Sep 2021 23:37:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06CCC60F48 for ; Mon, 20 Sep 2021 23:37:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238479AbhITXio (ORCPT ); Mon, 20 Sep 2021 19:38:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239187AbhITXgi (ORCPT ); Mon, 20 Sep 2021 19:36:38 -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 10B3EC0EDAF6 for ; Mon, 20 Sep 2021 10:45:43 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id q26so31993743wrc.7 for ; Mon, 20 Sep 2021 10:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=R+LX9AbeuyjGHg5FPLO2qXiWDcepHFB/ttRN06hA7cg=; b=VnivroiR+yh6q8kfta8AmpWn7w6CyHQyZj8rBmyg9giuSUA+QkzgSOZRzqPwh/RSzS bY0fCT+ToLHDOBoe+uAfrE6VYCtWeX/mOnKxVJXzA2OQzvj9h/MjE9alA4gOwNuzze4s jL1Vf0wtZuxZ4r24YT/xwAkoatf7/oUID2tefuzCPutSEr2ckJ16F5FUob9tsbEVc3F0 EAjd02SoJTuiQJbydBBJNayL7K4zxU/RGoKI79FX8oyyk0AaU3TgYarm9kKkanKgekp+ 2YR482z9IQSd4idzXPqjRyhzN1kkfK9NSGsELLrcbeEh8Pr16/CwHsQScenkITxadMr2 sRLg== 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:mime-version:content-transfer-encoding:fcc:to:cc; bh=R+LX9AbeuyjGHg5FPLO2qXiWDcepHFB/ttRN06hA7cg=; b=E4/oa8dBGmiwJli8FKEYTgkvAnDk+NEohX3TTqNz1iD37zwAhHxyuildoKno8o0ha3 jYt2UB3iXX+ZAWh8zwMkTT0H97g0s6o1cXkZp11QoORryuNd5heWDLNGXEx5/6UOTfox J+xjOTmda9K2wEwojQy68/kyY3ROPtYrqncHgT2xCailYpkHYQ1QxPqXfV/+bMdUJFYb Mf0tkUL5vFUxctrnz040rc5wMecDoAGH6Wkc8P/V2f+a7CdICW80c1HVYo0xpW0IIW80 DFVYuNHVmF3E8cEXtAyhDvLucRgJ0BCTGktkT70i0nXuRs/iiLl9kEGyme/dGgeN6+05 6Alw== X-Gm-Message-State: AOAM533T+InuGprwHf+VPFDnyka8B1A+crut0HG+JEYJGYE/bsYA4TBl whq+GkoxaVXZf0Toq1n0drFZIUne1Ps= X-Google-Smtp-Source: ABdhPJyxLqtNjIq43Doze9qBqN2EBfG0PA38dClMgFJMzQY1GK9JiXzZ465rji4Xnnu24uXJ9c1TDA== X-Received: by 2002:a5d:590a:: with SMTP id v10mr31035825wrd.87.1632159941680; Mon, 20 Sep 2021 10:45:41 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m29sm17776281wrb.89.2021.09.20.10.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:41 -0700 (PDT) Message-Id: <0252c7ee15c3cb364a7610b63d74c193cbda0728.1632159937.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:27 +0000 Subject: [PATCH v3 04/14] dir: select directories correctly MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, vdye@github.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 pointer '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. Helped-by: Ævar Arnfjörð Bjarmason Signed-off-by: Derrick Stolee --- dir.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/dir.c b/dir.c index 652135df896..9ea6cfe61cb 100644 --- a/dir.c +++ b/dir.c @@ -1305,10 +1305,35 @@ 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) { + if (!*path_parent) { + char *slash; + CALLOC_ARRAY(*path_parent, 1); + strbuf_add(*path_parent, pathname, pathlen); + slash = find_last_dir_sep((*path_parent)->buf); + + if (slash) + strbuf_setlen(*path_parent, slash - (*path_parent)->buf); + 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 +1356,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 = NULL; if (!pl->nr) return NULL; /* undefined */ @@ -1340,8 +1366,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 +1393,12 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname break; } } + + if (path_parent) { + strbuf_release(path_parent); + free(path_parent); + } + return res; } From patchwork Mon Sep 20 17:45: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: 12506595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 B8FB8C433EF for ; Mon, 20 Sep 2021 23:37:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A511E61019 for ; Mon, 20 Sep 2021 23:37:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242252AbhITXir (ORCPT ); Mon, 20 Sep 2021 19:38:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238665AbhITXgr (ORCPT ); Mon, 20 Sep 2021 19:36:47 -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 919F4C0EDAF7 for ; Mon, 20 Sep 2021 10:45:43 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id t8so25035276wri.1 for ; Mon, 20 Sep 2021 10:45:43 -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=RBzcbjRmUFju4/2SfeXbRU/+F75G5LRmbXMUpPAFelo=; b=ij7b4RLgEEsm3E24lbhUT8ZjM0pQ3MCvharUpKzmtBGdPCAMHfsgL75mQz+ZtQ+gaW xzK//l7qI6SUeXRg1WUQYjRybABCqI0wiE3jiPmM2X5KqfpilWe3w2uDai/qyZJ+SxK1 IydrhljZEVDgbdQOuFaJn1inHd6uQ4NVeRtW5nBLCfWKny99PmIuGSJgklLRM2xXza1K 42RE/N21VH/wwrxmraw1i7ZYtiS0SMQ1ZHX8ZgFTtIEfXA7WDJXHMi9FeuKl2Vpi2eI5 0D+x1Y2F7T4XY6Y/HSde5MGWc7+VCg9lngCsmKYUvVFE2P0vS7Jnd7cB3jaFWzRIjU0I Uyew== 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=RBzcbjRmUFju4/2SfeXbRU/+F75G5LRmbXMUpPAFelo=; b=u5TH7gmabp67pmb6cxwyNJz3+6uWxgg7pO9MvXTYwiyhTd3hMPM32+WiXnkVRW+A5W K4jJH25uH8PJK3JJ4fCKbxr5CvZryk4tztycDcM6CC+UEXK+q42g17pDxBaBDFmp0dFJ FQxChBx+JBjdk6GoEUnpAQWLzUVfnw5bx/vDHHVpqm7y4F1n3+vUZ0hHYG/ArSFvSu+S kPYmxKWBtgApiHcivjS4huxz1JDfiglRAiUtpVaUqaRJzGovicAdNcxK1aLBv7FhHDVw O8Kr2PlcntJ+OohwbRSYsxCRcdqED3ZytjU5ZqzZDNBscU5PYc9DUvWkPm95bxTjtgpa 51iA== X-Gm-Message-State: AOAM533BoPqfklQyqfrqfaZ+LHdApGC3FnnAjccGRJOmtTPEX6cqyi70 5KqyT08hlA72LdNbvNKGmw4qOwTxDko= X-Google-Smtp-Source: ABdhPJzarZmp9LHlzPNI666q24vopz697uSshHvwIPjlR3NId8ckpujvvwzRAPgKc8IfIkd6p4Jmbw== X-Received: by 2002:a05:600c:3b1b:: with SMTP id m27mr256974wms.15.1632159942281; Mon, 20 Sep 2021 10:45:42 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z79sm204924wmc.17.2021.09.20.10.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:42 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:28 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 9ea6cfe61cb..174d336c30e 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 Mon Sep 20 17:45: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: 12506597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 2597AC433F5 for ; Mon, 20 Sep 2021 23:37:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 079816121D for ; Mon, 20 Sep 2021 23:37:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242409AbhITXis (ORCPT ); Mon, 20 Sep 2021 19:38:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239262AbhITXgr (ORCPT ); Mon, 20 Sep 2021 19:36:47 -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 5D4F7C0EDAF8 for ; Mon, 20 Sep 2021 10:45:44 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id d21so31975982wra.12 for ; Mon, 20 Sep 2021 10:45:44 -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=EZrqH4ayT+B0A6axWS75ToFDBNU6W5z1cjZ4J6M3Wq4=; b=ajU1sijEaXpshIa2ZkCWe3RTZFXxjnvjxiK+3hh1mxwJHa4qfzkZXQkVdh0m5L8GWC rs4G8KqK+Me1TclJ0z5JlNQ0zZrUyN1n21naXnf+ICu7oD7z+EmQq1i/hL1FKmXIaCOY DGS8MEYGdyFDc1iREETJ21MP5RkadCjfU+JUO7m8SK8U/FhVWLtSYf2xTvOFXshkEwSO VwZ3KgRygyhZ75TnTVjB+6soivHybH9a3Wwt62piHdc82rNNsTzyB15lshTi6Y4UWKRH sBNb/IHFgthNsHUkSqPmS8R/Rmb3nK2kH1hiWPxhdZPKKOLpGrLzWu9KsWqIf+8+Xdi7 d8Vw== 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=EZrqH4ayT+B0A6axWS75ToFDBNU6W5z1cjZ4J6M3Wq4=; b=2qynz09FezcDljQwXm1JCk8bTLQ5LD8ni8v6lWAqdSVUJBJ6hkedhf9rma0iQo5Lxe cT+5VYO+sSdh3fohU+hbmKQTUM0ceufhk/sw0AwhGtauwASWoeh/iwwXa2y8VOGGuyRR 4Hx3qdbqVUmBR5lC/Zo3/86Nb7TA2GzWQtOyNnAtizEW1zjfLLRQmx9yAafezKSPdqWj nXK3oARxNo9n4cSSccFdZ/ojh7Zo768YiQm5EaE6t9FvQF66Ti29MqFMZD8Tn4piTElu fYI4bYfU1f2yPxtQh0GQ0sCZ6ju4Uu9t2R0b3S9zxMTbmyx5KWoNvQUMQ1z0JtnHamxN 8QgA== X-Gm-Message-State: AOAM5339HtUMFRVziKyKQ/FHJPivkP+S3ePg1UV6Ry4f/ApaUwsIL2Ku DvpSZbnV+ZvEdXSTvCqy2rIkTWs3fpM= X-Google-Smtp-Source: ABdhPJyQE6w0YBsO44r7E9OUMDl/5J/hkCzL9QgCiXXIHV3JzfZJJnbuvpV511nCKzheESpqK8zmXg== X-Received: by 2002:a7b:cb86:: with SMTP id m6mr298799wmi.4.1632159942932; Mon, 20 Sep 2021 10:45:42 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t1sm16690511wrz.39.2021.09.20.10.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:42 -0700 (PDT) Message-Id: <3dd1d6c228cc8feef95a016fadbda0d620a7caff.1632159937.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:29 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 3fb764f5eb9..be8f6f1399e 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 && grep "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 && + grep "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 && grep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/a && + test_sparse_match test_must_fail git add folder1/new && + grep "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 Mon Sep 20 17:45: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: 12506599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 617FDC433EF for ; Mon, 20 Sep 2021 23:37:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BE3860F48 for ; Mon, 20 Sep 2021 23:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243082AbhITXiw (ORCPT ); Mon, 20 Sep 2021 19:38:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235163AbhITXgu (ORCPT ); Mon, 20 Sep 2021 19:36:50 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0640C0EDAF9 for ; Mon, 20 Sep 2021 10:45:44 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id g16so32044588wrb.3 for ; Mon, 20 Sep 2021 10:45:44 -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=X0Pm/CFSzA9pc11Q83Noz7O4XmovKwzIyujecG2BqZA=; b=diBJwMsF7KlYKyqr+vKO++dNVwnr0oyLO4BdaYq2Hv/raP4L7BnjYPLFNiH7JbtoxZ ZIDFOH/J4xUmSlhmvNtjjeRfww9YantFlzPfVTCKtHOJfhDkAqsHnsK4Ac3K0Z9k8wNK 8WLETRO9RoIK/TpBYWTtt2HP5mlbHpyS/LI1FSyHCjjJV6bQ2YPqJpOhBXtbxyyaG+7k I6t2ET51ydFdDjZBPQZ+akrEDaOBgwBKaFPO8stoaJTsa0YxpCnHoY6x+2i/KXgfjO+/ eZKw9L72AQ4z26XEez59J10tJDfRJEtPAwg1Zx+ZKjhHe3WTe/tLLvEv131paD4KGq7r ktwA== 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=X0Pm/CFSzA9pc11Q83Noz7O4XmovKwzIyujecG2BqZA=; b=4Le/Q584jFsVhCGQ7oMG4FmEqejcM0K8a0nLaZIJOnELYKJikeDRN5gKjERWBcg3Sb oPyJINR3/aJZustx49xhOE+8WFo6lS+TxSBCfjpZrxnSHcv+HNdZUzJON2YUSYGfHOhw JR6UHq3MCa4Ff7RbcY2S0BYTbkMLP6JzmN4y98DE40F6S0cDd2GOFsKvZMtWdRgnc6W1 vVskUDPTvAGkTKYSyE3aC/76QTmFqZhSpIbyCOmfk5Dd+fdod6f1ftj4s8lTSA0+4Pqy bKlfxCuxUaaRPFNH/H9/UgEGq6tUsBKDV4JbKG8ejGARR61GvDuBgqTm0c3CH9QDMyQp cBhQ== X-Gm-Message-State: AOAM531z7ilaANq+Js4xf8jclJhfbtiHnRtjLP3rfoOPtQIB/90etyXC /qn5I78rxmYZjsuAe4vvKvUDiCT6+Ig= X-Google-Smtp-Source: ABdhPJwpAXM8dEJ1XYTcJUfqb7TkqeFxaRn7IEWGiEeUXacfC6l3qgizA2Nm3PQpIaT6NW5SkRJMPQ== X-Received: by 2002:a7b:c959:: with SMTP id i25mr258858wml.55.1632159943552; Mon, 20 Sep 2021 10:45:43 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n186sm176341wme.31.2021.09.20.10.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:43 -0700 (PDT) Message-Id: <15039e031e5252179eb16fb04c02ad91fbbe4952.1632159937.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:30 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 | 19 ++++++++++++------- t/t3705-add-sparse-checkout.sh | 12 ++++++++++++ 5 files changed, 34 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 be8f6f1399e..ba2483732ff 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -546,10 +546,9 @@ 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 && + grep "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 @@ -558,7 +557,9 @@ 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 && + grep "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 merge --continue && @@ -586,7 +587,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 && + grep "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 +598,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 && + grep "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 e202a2ff74a..5899f270d02 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 Mon Sep 20 17:45:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 4EE32C433FE for ; Mon, 20 Sep 2021 23:37:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3098560F48 for ; Mon, 20 Sep 2021 23:37:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239079AbhITXix (ORCPT ); Mon, 20 Sep 2021 19:38:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239553AbhITXgw (ORCPT ); Mon, 20 Sep 2021 19:36:52 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C391EC0EDAFD for ; Mon, 20 Sep 2021 10:45:45 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id q11so32027115wrr.9 for ; Mon, 20 Sep 2021 10:45:45 -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=A8TgwsbfHxO9u2oNd2R9FA5mxbQVoLEmF9HajWMbfbA=; b=H9kuWiM2kVvOd+5A59Sac9k0FpWoREM0aFYAqQrKhLx9zgo3UOtvde7y2zEMbJMnIO BhPJ+/6SteViMfe5Q0i5Jhdh0MEn8wrALFl3Rp9glIIEIcXmO5mynrUy9pXdpmV8F7Me gYzkRDG4BQ1HgVx/l03aq/zv8vxIKBmmHO6H/FCEHbbUeltT8Wr+IfXzjUEnaBdHaLRn XpptoHmjAhx+zn8lpZaxdanUfNBvB+bkqTc1yoNM9MsnIElVWtkCBXaqGfHDkv76Pwcs PNbtXi4yWKkxGw6/ISflBG8w8Wyfx4SUQeBXVjQWW8Ww6NP8IdSJd/K+wMfUX8CL6hUo t0iw== 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=A8TgwsbfHxO9u2oNd2R9FA5mxbQVoLEmF9HajWMbfbA=; b=pwJ2q+ESwd0veQtcLj2/pmR3Zx3uFN82FR5DuhO0E6g4hRgZVmLwhcB7uIy+8O9NDh v+Zh406Oxcxt0u3dFClkCzUmkdSN/j/539SOXJPB7vHLtNi3xtuYNLm51uRGb4+ex3hr jTt+APKNxF7sY86m7d2U4FT0fFFbBPsufzJSFwimTJBXU3/fCcYyD9t3iZD9K0DUa0XD 6xoWCtcSXxQ/tsLMr+IMGZ5Dil+wGjsYUdJkad/J5qFVcY5j5WnOPMcIp13UWu5H+WC4 Bda42r/aj/aYKe7WdkJnzsBsCZ7vuMLW7lSu9IjTGCDs6HuxqOI/kTnpfAzNL2QkMxa2 LoaQ== X-Gm-Message-State: AOAM530+AtWsHEK3vcIljESui3BTTlRAQYx0I26xjhr0sV1sZfwqHBRF ybKd3pR9EbCz2PX573t0TJx2p5eEzMk= X-Google-Smtp-Source: ABdhPJxhVImqTSon5ZA00diq0MJ/cwQFJW1D/Mg7GLtl0XDLrPKp2Zz27sdElgzKkFz5eRuVrnt2Aw== X-Received: by 2002:a05:6000:18ab:: with SMTP id b11mr18041475wri.131.1632159944259; Mon, 20 Sep 2021 10:45:44 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j14sm16822732wrp.21.2021.09.20.10.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:43 -0700 (PDT) Message-Id: <6014ac8ab9ed699065dca21d7dfba059c98b8a52.1632159937.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:31 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 | 29 +++++++++--------------- t/t3705-add-sparse-checkout.sh | 17 +++++++++++++- 4 files changed, 43 insertions(+), 24 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index be5e3ac54b8..11eb70f16c7 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 details. + -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 ba2483732ff..b11fc540415 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 && grep "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 && @@ -549,17 +541,16 @@ test_expect_failure 'merge with conflict outside cone' ' test_sparse_match test_must_fail git add folder1/a && grep "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 # 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 && grep "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 && @@ -567,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 @@ -590,6 +581,7 @@ test_expect_failure 'cherry-pick/rebase with conflict outside cone' ' test_sparse_match test_must_fail git add folder1/a && grep "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 @@ -601,6 +593,7 @@ test_expect_failure 'cherry-pick/rebase with conflict outside cone' ' test_sparse_match test_must_fail git add folder2 && grep "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 5899f270d02..0434cdfd9c6 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 Mon Sep 20 17:45:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 EA506C433F5 for ; Mon, 20 Sep 2021 23:37:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D173E61019 for ; Mon, 20 Sep 2021 23:37:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243140AbhITXiy (ORCPT ); Mon, 20 Sep 2021 19:38:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239559AbhITXgw (ORCPT ); Mon, 20 Sep 2021 19:36:52 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B73CC0EDAFE for ; Mon, 20 Sep 2021 10:45:46 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id t18so32099703wrb.0 for ; Mon, 20 Sep 2021 10:45:46 -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=NI4USuJlvyh9qzP66ETIQecQeOGGa/O6tXtFnDWTMmU=; b=P61QgP+bTpQWq3T0Y0igLVaATYMo3tzD/A1xXEo6Q3+X1JmKnHQotK7VbAR3Pc/cNa Wwx+wBn5Oaxcr1y1WjyCGFNn+duHHqaSawN9odCsKrZCZmXlQp3ZjC4j3op2SdjccshI ax0wM0ZsS1XVs/54xp2CmK5vyEfHHzRkMghtVha7q4rOE4FYClJeOSTqfeH6JDoPH8BP K/UphNBjjay0SgmAEPtBn4lezv8bENuIUCCF/IbSC+B4neSM+6oBjpzvMW9G0y0LnHjX 2BNg/4V5fOvqe2dAUsT4Bh7TkFGVTaf4R5x8bX0qN4gWAzjj991AxoNlrK5RJo5zHRUx /ZfA== 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=NI4USuJlvyh9qzP66ETIQecQeOGGa/O6tXtFnDWTMmU=; b=T8kufCAy7MK0ihD/v1hnqWpP3i1tfhLhrDYvHdoLMcGl8DdVhSPftxOtDDWKp3i6jc LLpPaSo10s7Z2Up+jW5sHOFmSYE1SNDzbtF/LmLE8qYQIB9rdnxXvcH0KPrcDXtCF6P8 COshCP2v4Fwur8R2qgsN3mnqkKPyDGZdykb8K/w5NRL3EE7xfG/kicMUHizLrLpWnCrc mO95Y8sfo01vnaN+PanBjCpOVs6EjPjbHEca78J6wv4XHhT1CPOjN7+1nD25VIIlxLfJ SnAtK1TMuuabCXqK1vpPlay3eO+Wzz+XJm22R7FAjFOR1gp5tR3e80V80nWiXeXatXIv sPIA== X-Gm-Message-State: AOAM531uwhmYqyZl0yLwEWnmZdixVVYrVtrcFE6+/brOZ1IcV8oF6Hh3 GhQG31P7GD3aX2WCOf2zBidE2iBaMuY= X-Google-Smtp-Source: ABdhPJzDETUMM7PBlUynZWerjHkMWn7PM60ZczxvcdLXQyKfhEPaBczmqBjSd6AjUb4CgpxV4YdJ1A== X-Received: by 2002:a1c:a713:: with SMTP id q19mr288407wme.42.1632159944943; Mon, 20 Sep 2021 10:45:44 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g1sm885048wmk.2.2021.09.20.10.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:44 -0700 (PDT) Message-Id: <2bd3448be5f688adecc7ccc2947532b2af26c5e4.1632159937.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:32 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 | 10 +++++++++- 2 files changed, 12 insertions(+), 2 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 0434cdfd9c6..9347705ad1c 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -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 Mon Sep 20 17:45:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506605 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 EEDCCC433EF for ; Mon, 20 Sep 2021 23:37:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8AC061159 for ; Mon, 20 Sep 2021 23:37:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243207AbhITXiz (ORCPT ); Mon, 20 Sep 2021 19:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbhITXgx (ORCPT ); Mon, 20 Sep 2021 19:36:53 -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 DD686C0EFE40 for ; Mon, 20 Sep 2021 10:45:46 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id d21so31976262wra.12 for ; Mon, 20 Sep 2021 10:45:46 -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=+Lk/tCvJ2GLavDDUgLiOQCJkKvagb00pcWxmfnFgwgQ=; b=lv0NqZqGYk0FN07uPhaqY5UtMMdiYPDZaE88Ci7WIyOdij/DPbLpglVHzOLAcWB9Wt 0qhWMVeD7CvNVMySiCEpN4Sg9gYAz33Gp9WeQKJEUi4jl0dNV3bjryFy6W29p3ZSjtBL AYqlyhNbT7B0wplDL2a/UOemMqmG05wFWvEEf5eF99brCucu6nF2f46RCgpZWQCDUmOj LmuTxvt44sbBgxmAtAhdU8UxnuhbcPEkaUdbJ1o8EEkSozhHgsWnOMdKPcaqtfwJLfwX ccfeKF6XGdE3u30YkuWzg4gT53Ra7clQxpNsGAOGJ29ydLX4XLwoW03Gz8bAC2UiYAtv F56Q== 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=+Lk/tCvJ2GLavDDUgLiOQCJkKvagb00pcWxmfnFgwgQ=; b=hcARsqggZwFIDs4LAROsePTQlEMxvV0SJu2xOamBMqmWLjR9dE88kSYQIgZv+dZNrk sTwxPRhIZlSl4wXSpeqFIOdSjgpyw+arXkbLQZQT15EDjKTcC6gKnvRXsC5eLNEWKzon rXq/5J1kp29zzjXO7I1QhUVSV8vCytQSspJisX01wkmBqvQAdAU165XHHmvN5BXKUlzg f7lmSv4aZEG9zf51MmkAev6rFtAzgk/cRWSQ/IRl2+Bt8ZaGRySXTzEUsneRDE3kmGha 6gMTj7rK2dXbTwYgMXKTHvllm0kS4z/cIgHWGu1w9g21jHWd1iXJGDUFrNmq+KJ1dxrO KQ3w== X-Gm-Message-State: AOAM533xnv7d44+qiNK7OppYaXH10znVUy23eq1MZlvFbYAicRJMEXtQ oTNvUvYlq5Vvs6UmIiXBZrrt97O/jWE= X-Google-Smtp-Source: ABdhPJwAaQXx+/yXuEnwg/osdUFeGt85q0csvAVmO3KAZfFzGNKjpyjijWHi/ELlNc71WaKu+KpcgQ== X-Received: by 2002:a1c:7201:: with SMTP id n1mr258990wmc.19.1632159945530; Mon, 20 Sep 2021 10:45:45 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z5sm196460wmp.26.2021.09.20.10.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:45 -0700 (PDT) Message-Id: <131beda1bc32d61b1063a51210048feb26755bb2.1632159937.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:33 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 9347705ad1c..10969efc23e 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 Mon Sep 20 17:45:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 831F0C433F5 for ; Mon, 20 Sep 2021 23:37:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AC3E60F48 for ; Mon, 20 Sep 2021 23:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244041AbhITXjC (ORCPT ); Mon, 20 Sep 2021 19:39:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238967AbhITXhC (ORCPT ); Mon, 20 Sep 2021 19:37:02 -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 84BB7C0EFE41 for ; Mon, 20 Sep 2021 10:45:47 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id x6so31998178wrv.13 for ; Mon, 20 Sep 2021 10:45:47 -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=HJQ1PXDHwhY1PzL6FWcVZk4dLWMjdbqYtonPiPwOWaZxJmNLG92DzZc8+kZp1Jdf6W 2D0HUzXT2de1nRK8wd5B7CQjUrtOQbPH+v+XQFwqVUrXWLscqiYUFxani5nRGZSPpyUJ r8+Glfa26aQsgt0XlJqPwLRbGi7eE41oIAAfivdEh9YB5qNp+QV3yPd3L32R3BYqLf1f mT0LqvesYOa+Y1AysU1qySsk81w1J5jHQkLAaydXG9PazQ2tUYky+JEIsSf9Q9UvoBGI /Es9irJimEsksHTD/Jo9a2li59m5f9mutLgHxPvut8F3sq7MAgt142vNnXeIaW6gtBCr DVhg== 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=w3Vt6gaSl8oijQcLJ6+kYS8710eZODXWt6swqMzUbqJGajLl8mKv+UgzjEQhWRQzSl BrkPN018BM1TF78N1SI5x14yTZlybLEJCCJoy3Tgw56pJa9sowTH9JxBPXE9Ltkg0Bk7 70eHHdnB7Si42hEftX46p+EJ2sNacIV3pnu5kgIvox+7lgc24VDWBs1e8gnW1FoTLT6t MgcYs0cyt5FT6mr9QawMwAGX5BVF1henYTy6m4EIIRe8Lxnq2hAZ1QHiU8JnYlDdMmZK 0ffagfMo5OppUUBdDTXBozjsiMIudv+lnRZYmGYVH5wkmRUZNEBjeAt7hgRUl0gopk29 4KvQ== X-Gm-Message-State: AOAM530P3jER8w5mxGEOChY/DOTmpIJj2Og8Lpf/yTLmBqpcplhQLF9w uICjaVtAbBERrr2bpgb8n6uvwPx5Ee4= X-Google-Smtp-Source: ABdhPJwu29SBF2Piz52fUa4a126gBjUEuDqB3QjN/x+XqAhdzGMCpUyAA4co1iFlWt0J8JYXBgalVw== X-Received: by 2002:adf:d1c4:: with SMTP id b4mr27401066wrd.233.1632159946197; Mon, 20 Sep 2021 10:45:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i27sm172387wmb.40.2021.09.20.10.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:45 -0700 (PDT) Message-Id: <837a93148936d3138be47bff78069373342ce3d8.1632159937.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:34 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 Mon Sep 20 17:45:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 8D160C433EF for ; Mon, 20 Sep 2021 23:39:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7236C61159 for ; Mon, 20 Sep 2021 23:39:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241545AbhITXkj (ORCPT ); Mon, 20 Sep 2021 19:40:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241347AbhITXih (ORCPT ); Mon, 20 Sep 2021 19:38:37 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DCF9C0EFE42 for ; Mon, 20 Sep 2021 10:45:48 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id w29so32029580wra.8 for ; Mon, 20 Sep 2021 10:45:48 -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=qgiNNR9AsuRpB0xfat+tKNXTirFs4kJh0qH0zd7H7gxEJiEkeQWPSJtfgf9dAGNlKC KeVsCPdqZXhpqNvXVY1kJDPw9GOjGkdBIxBqAhsqZr86Y9f5VPfvcxdMAheibMRkVeKp R+1SvyOEtAOX2B/z/aNNcQuX9ttr5NTCmrbaOj6jjT5lWF3N0nZ9dytjNgyo4Lg+j/Wp np18N9S5qajfsJh6VC+SgG7CUhLxad89yoO8t4CJAb6Bw0on0Rb7EcHnfwe1LjkzFRkO N4V1mK4I4reeZYthMLme1RQQqv25jS3+rb3M3CiXOWGuEBqPuJ+Ghgfr3FVvs8T1OmJP 84Fg== 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=3IvAb2I0XC/GBeWg4JSXyY2A6+9PYsOVcUVmfj/ETyiTu1QFYkQBHdN35/2+WJJjG6 3r9W9kir72weZCjUlXRtibCZTcoYUq0DQYAcjdZIgsARTuQ5NONnJ1EXuX3oKNJvF5VY JQ8VGovQjmbGKpQSyVPYe8Fft5rZDWnfuHZZbH97PFGU+w6GLNEEbCgp0bLm7xnMZ9Z7 OJ9m0C4pBHSEVHFxYVf62p36XeZsRqlG96AhQJU39HkC1Llc8tPolOmk0bvh5I93Oucc F+9vfIXwhLr+iIwjud/CT/EJnH3KTDlQsT1s7IXIypax45P2xp/GiBFMuNCOedUgENwK lIeQ== X-Gm-Message-State: AOAM533onZpngiAOvqIBX5ULJc+cmniNhWvVdmdYkEwnQ/CHLO9xYsxS 845+Z0AsqETwNOwg7/o38SIjLvJRhpo= X-Google-Smtp-Source: ABdhPJwSVZH+WF6ZrmrsgZ5BbBjf/ZTfGHjWfvmcsxLvVQPTgnXBm41xhxkW93m5ozmmUz9EsWR42Q== X-Received: by 2002:a5d:6545:: with SMTP id z5mr30032369wrv.51.1632159946768; Mon, 20 Sep 2021 10:45:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h18sm191157wmq.23.2021.09.20.10.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:46 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:35 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 Mon Sep 20 17:45:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 0F574C433F5 for ; Mon, 20 Sep 2021 23:39:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E478161159 for ; Mon, 20 Sep 2021 23:39:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241515AbhITXkk (ORCPT ); Mon, 20 Sep 2021 19:40:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241514AbhITXih (ORCPT ); Mon, 20 Sep 2021 19:38:37 -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 CD0D8C0EFE43 for ; Mon, 20 Sep 2021 10:45:48 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id u15so32046413wru.6 for ; Mon, 20 Sep 2021 10:45:48 -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=LMqPt/aCqmoLdMO9FvTZPZ9quZaJzU6l+AXksivZ1AOD5Ru5lXBh/y10Bdv37vUbUQ /50DQNqRZiROzSJKD/gmGyK6/0Us4dPFDl3zK5AijgKYugSsTXikNqdv6oeyTBGAzBe5 eJ6A2TdQdunGtpOIwavfm3aRmK//UwKOriFNgvFgoC/NJXi/oNHYxWwPbjh2Vo2zEDe5 QNKewTS8+oEJzbmlH7ElpOo7DQ7bKwoVIblRCTy3X3z9+6AoRrLzhRdi8nmqjR2flF3G oYwr7VXHddVWdFe8GOODQxhi2Bh54aCuiZiL4hBjhmwaSnU4O7zhAJUWwnh3BzRiSt/z eRrw== 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=xVA3U9AT0+g2fGGiKlZnoQylbFDx/crKIGIOocVZDlbQuSNJlDjtMGo3Bk1wVkt4wp H0lhdn7OQVi6K71Z5d7zGiZFuWPJLOTQp57Bk+QWdPGMmUepDcGxEZfrrGp9r29Mvq7N u7KO0Waii7+gigCp3RNa++alZYkUQdh+X3Ong2qTrK/UvlzoMXyfj94xFT7SpVF0thvq SFOSloy+v/Rnsx0buQif3SRQEb0AeRA5CXS4jhGaR38klX8k7JubE/83XpRuVJIN/UUF DuJq4SqIxSwr8FKQcRNtOd8D7nYwh4KKZErg/5bnCBfcg/Q2xstdfLBs1BTRXtzQ4HLS QUxg== X-Gm-Message-State: AOAM530ZUFJ08buBgkdci2Hw3GsgLmEr6bxhchiS0ASJ6mp7yNzydICA GGsQsY/ScqlAGeLcCLLexlaFWyJPtR4= X-Google-Smtp-Source: ABdhPJzM2Wcvgrsbr7AYD70tWxFR+NVh6ATlglDhn5GXuKeKJKhBfSiSGnjtWZuIXx6jhl9y1RdOGg== X-Received: by 2002:adf:f683:: with SMTP id v3mr30998357wrp.423.1632159947403; Mon, 20 Sep 2021 10:45:47 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 25sm240476wmo.9.2021.09.20.10.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:47 -0700 (PDT) Message-Id: <63a9cd80ade83d0307374f46516782ee6a89dd30.1632159937.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:36 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 Mon Sep 20 17:45:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12506613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 72D7BC433FE for ; Mon, 20 Sep 2021 23:39:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54BD361159 for ; Mon, 20 Sep 2021 23:39:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233903AbhITXkl (ORCPT ); Mon, 20 Sep 2021 19:40:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241574AbhITXih (ORCPT ); Mon, 20 Sep 2021 19:38:37 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E3F4C0EFE46 for ; Mon, 20 Sep 2021 10:45:49 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id w17so23897363wrv.10 for ; Mon, 20 Sep 2021 10:45:49 -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=6Dn9LtMSl7G8Dsx58rCmmkRzvnmEh9XKceWK9GqPW90=; b=SUVdnWj9rTtFW0CJPwyFT4av6IGDtjEvkey/hvfefAoJ4RkDIdT4zAKC+0HQF47cC7 PqTaKfLrVZadkIUZlH0ooEwdRQxagktugJNdwikcgD+qyyOU34QSJI3M4UQx98dtZw1P i0VMBgRMPZDk//lSBQ9yv3dP6tudvwk54qsi0AoXZLshLgPxJYX9YoolK1m3QCRGsRNf hbRtGgnWK04RNmp/N+L/NMKNYa4QIlyLpIKVoet9iFt39oILaOi1M73a/xCLfTTx2euS /5ZqnmBU90WlRiJvXGGpxdfaqFA6c8+2XdsEmlc5lUOJM1HG6evmIPdIQ9W48okWTYMq y//Q== 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=6Dn9LtMSl7G8Dsx58rCmmkRzvnmEh9XKceWK9GqPW90=; b=Andq4AhNwAVgDrthXZxiUsI/jeuWSal0PoxBPKp4nyAoOxDGywPBhlaJrZ1EEunMhz aTxHKWTfGRekpC2AA6w4AziDJEYX3+opuZAkGzFA9iBGWyyi0fxsmQkLa8Eh0hsA9m/2 SD4tuTXN8DbpI5FzRlduH0NQVFLq13QUduiFCp+SXgqVWotUXfNBybGDjxtxC61KJJtI QnqkwZDw7bj4xcJ/k9iQTljpVfQXOoaO5NOjwyBYX0jl39f/3gL7McSpDjiIEQyoDywq nGRIf83zNKs1jVu9bQ4lfHEbmGWQTxyICIxOlSRxA87OWhxbK6azmo4VBdWoXw3wqX7K g4zg== X-Gm-Message-State: AOAM530STBtPL2jgF3mIlDB78ZLzKeAo8SEK9cFx1BLvwuYTGDyizmUY 3RrF+Qk+L1HpzD4qrcL/H5VulH/LGkk= X-Google-Smtp-Source: ABdhPJxo0caaeYHuS9KJQfCmffWDZREgqg87zzR3YLzjoINVaLBYNKbb+7VA+cd1ilC+PDWP+o1ucw== X-Received: by 2002:a05:6000:1865:: with SMTP id d5mr20911045wri.248.1632159948045; Mon, 20 Sep 2021 10:45:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v8sm16476109wrt.12.2021.09.20.10.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:45:47 -0700 (PDT) Message-Id: <79a3518dc15cbf07991535a779b141e3ccefc6f4.1632159937.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Sep 2021 17:45:37 +0000 Subject: [PATCH v3 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, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 | 11 ++++++----- t/t3602-rm-sparse-checkout.sh | 9 ++++++--- t/t3705-add-sparse-checkout.sh | 9 ++++++--- t/t7002-mv-sparse-checkout.sh | 9 ++++++--- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/advice.c b/advice.c index 0b9c89c48ab..713fff49ee3 100644 --- a/advice.c +++ b/advice.c @@ -293,15 +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\n" + "outside of your sparse-checkout definition, so will not be\n" + "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" - " to update such entries.")); + _("If you intend to update such entries, try one of the following:\n" + "* Use the --sparse option.\n" + "* Disable or modify the sparsity rules.")); } void detach_advice(const char *new_name) diff --git a/t/t3602-rm-sparse-checkout.sh b/t/t3602-rm-sparse-checkout.sh index 5f92b60a56a..ecce497a9ca 100755 --- a/t/t3602-rm-sparse-checkout.sh +++ b/t/t3602-rm-sparse-checkout.sh @@ -11,12 +11,15 @@ 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: If you intend to update such entries, try one of the following: + hint: * Use the --sparse option. + hint: * Disable or modify the sparsity rules. 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 10969efc23e..754b06a9663 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -44,12 +44,15 @@ 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: If you intend to update such entries, try one of the following: + hint: * Use the --sparse option. + hint: * Disable or modify the sparsity rules. 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..545748949aa 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -11,12 +11,15 @@ 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: If you intend to update such entries, try one of the following: + hint: * Use the --sparse option. + hint: * Disable or modify the sparsity rules. hint: Disable this message with \"git config advice.updateSparsePath false\" EOF "