From patchwork Fri Sep 24 15:39:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77F57C433F5 for ; Fri, 24 Sep 2021 15:39:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CFD961241 for ; Fri, 24 Sep 2021 15:39:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347231AbhIXPk7 (ORCPT ); Fri, 24 Sep 2021 11:40:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347183AbhIXPku (ORCPT ); Fri, 24 Sep 2021 11:40:50 -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 82471C061613 for ; Fri, 24 Sep 2021 08:39:17 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id d6so28619154wrc.11 for ; Fri, 24 Sep 2021 08:39:17 -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=yVuKsZPqLiD2f7SnVIfjQHCr8IGVg+GERk3ix01BkMo=; b=GL+EQdJRyBURTalQy+3UUI+Cfe/XS9hae9zvxRE5SlrtBPQ/IvdAiw/zEdU+vACRgd Plxzu+EiRLUg2v3tPD3RIw36JTgiOqC/X8mMYncqj5/pAf1WxoYB2lrxCtS3av5Lf8zq rF3s7cLE3JkH0dRGjyt4UmNtYR1Tli2LIH2SZeSsxuc1jtTbWCu/I/hh00ewVtErKHJs R2X4mqhgPRhYWv64NNiqzh3tLQNcA5vbUOBTMskAW783PPK9VveYNouf0BWdONlVpYEq 08Ai0vvafSZcnAU6m/wrMncYOL6wn0X0YWwtJAt1dVZ77mghwZcdf9wWTiHb6LYQEW75 no4A== 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=yVuKsZPqLiD2f7SnVIfjQHCr8IGVg+GERk3ix01BkMo=; b=PCT1LTM78LVznh5Gzqm1KeumT/9MXiDJy3BhDUCFurEpZwrR+LGARNG8cJhSvua02M R7oCOOIlA6PCFRVEiMoGVFiq+kpWDPGdE+LFUiqdJdult7nJw948wz0EWBQY90/+AyJD YY2owKec0VfzvLNP1Ao1gtFxTp/+kFV1KwKPF5ABEw5cDfXESPrz9+4JQK6m3MXzAi4F sEfxIskEcm7vz+hz5MIK1YZ/Z7KqnKKYF0YIr9FLOaLDFfHWrkoWp1byccBlm9dg0ktt PIz+v1qR5bkooAI8YOOnwqWu43qZrdrEEwj5fABEN/Zl6weE2dCxOd379TIiTQqxW+Vl oR3g== X-Gm-Message-State: AOAM531vOdY6m1qoQrnh43G4ZeazNpiM3hInZIWRVV37OnUFYsKGR6+s t4j1G3MCQ0PyfP8tI2XOYRlalyAnduI= X-Google-Smtp-Source: ABdhPJwBDYyX8hHJCWP0PvLkssIffMkO0ujt+qAW6gAo+BK6SnvWBX5G26GUhJ4++O9VWmdXOBNJsw== X-Received: by 2002:adf:9d47:: with SMTP id o7mr12436207wre.50.1632497956084; Fri, 24 Sep 2021 08:39:16 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o26sm12648652wmc.17.2021.09.24.08.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:15 -0700 (PDT) Message-Id: <642b05fc0204f2f9f655afd13695f22d30c2fc83.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:02 +0000 Subject: [PATCH v4 01/13] 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..b2d798662ee 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 diff --staged -- sparse_entry >diff && + test_must_be_empty diff +} + 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 Fri Sep 24 15:39:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9651C433FE for ; Fri, 24 Sep 2021 15:39:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C897761242 for ; Fri, 24 Sep 2021 15:39:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347233AbhIXPlA (ORCPT ); Fri, 24 Sep 2021 11:41:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347187AbhIXPkv (ORCPT ); Fri, 24 Sep 2021 11:40:51 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C1FBC06161E for ; Fri, 24 Sep 2021 08:39:18 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id d6so28619219wrc.11 for ; Fri, 24 Sep 2021 08:39:18 -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=TEtjt+Ut+ZPEGjZU8UZf8b6xjgXJsx/g9OCijhwvt5w=; b=CF4oEmu/s2/EnIpscKQdu/JN1PjNrQ/d+nGjd1axKVGHXOJ2d0m8MRzxTXLhJv7yRo RkKnNCjzWvUQTe7FdkmizqobYCYloSqoykwoNob2OYEP94jEemPD5EkPOZ3KfW8nZ2ti dOu71m6i/rAlB9mQmU6/cwmopAQylchhaTC+AixRX7z1ZUiX3+Hp3tndxdo+K8PHb0XE XG6DZ1TgjlgxSKq5uJRnAkyp8dkXEFKvBwz1yH/TDYN+jdGiRF7SIuyP+3VDCni/kMlQ Ib3zLU5qxyg/f7ht9UVoEy0vIpedpL417t9Gg7A79sotx4Fxd78woq5PTDR79gIcL+gx FK+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=TEtjt+Ut+ZPEGjZU8UZf8b6xjgXJsx/g9OCijhwvt5w=; b=QaA2YcT07a5s4zrJ2aKftowP38nv3tQQwOm/ur1yVFu6qXoUoWBxC4fVxFMfoz4gAw lm1ZE+mGZmJN8gFFvWhuKWyHG/kYGC96PRruWYdxuyM/8ePeBixESfso6/TmtnlW7/lj 9M/fB/pRPXkiP2xfB4V+Xx0B2oG4vibuA2qB82e04lKm9WPkILS2Vtc+vekai5B5b84c fwfpWwNa0JQtq3wgGFNFuKs7ZDbWVpf+PZyXXBI6oOnyiKkTXKq4eVUGw1XU9c9SStDs kW4UgzdZ4+4D84aMNTZ56+giygRsXI/sP/PeoyXf6dHtg273zsb4iXK9j2X0zSxrzlPZ C8dA== X-Gm-Message-State: AOAM531pW/Tre8ZVsDg/iJNkPZAbTjpohox5j76wcBK31IrtjO5TYvRN Sg67iGHl6cX5ES0pt3fjH8Up5B6RAaU= X-Google-Smtp-Source: ABdhPJxkXOJrGt2wlQ2amgEacJoTZJNrvauYi87b67HMcP+/Y1lOYrVnyZinXxXRahMWeYHkDSEJag== X-Received: by 2002:a5d:4d4f:: with SMTP id a15mr12275972wru.210.1632497956679; Fri, 24 Sep 2021 08:39:16 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y64sm9568173wmc.38.2021.09.24.08.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:16 -0700 (PDT) Message-Id: <58389edc76ca8f14951ee9387a0067c1ead08f41.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:03 +0000 Subject: [PATCH v4 02/13] 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..7edc2060221 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 + # Skip "unmerged" paths + git -C $repo diff --staged --diff-filter=ACDMRTXB -- "$file" >diff && + test_must_be_empty diff || 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 Fri Sep 24 15:39:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 813C4C433EF for ; Fri, 24 Sep 2021 15:39:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 66FC061242 for ; Fri, 24 Sep 2021 15:39:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347235AbhIXPlA (ORCPT ); Fri, 24 Sep 2021 11:41:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347190AbhIXPkw (ORCPT ); Fri, 24 Sep 2021 11:40:52 -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 B098BC0614ED for ; Fri, 24 Sep 2021 08:39:18 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id w29so28657087wra.8 for ; Fri, 24 Sep 2021 08:39:18 -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=+WMCKwrabJt26VhQfSQ85nboExspuZ/m1PAYcfVaGMw=; b=msfBoSmLoBswdP9v4HNj8WKVxP7P/+5YRftoE9N2bm+EyhdmT5kjZNrFj9+K7Ds+sE UUO8JNaqF43Ji+tDDGqc1UBoEmIBugm3/94q43dexvog+5V1t3pTCQKDwTnrPfYBsTNy sdDOOX22h0hxFm/TmSPGlozAtz9sasP92CdT22KCLqMKBuzSPdct/E/lBvu4RjSZsP4Z xQurfL7i4dOH7mwNsSKtndUUOwF8Zb/PLbCeTgzyVMzQqoz49ff75OyCyaBxKDdM2bht zlN3+CzfDQnWOF0Cfrr1g05F+x/UuLnvFKm1s5qx6J+G3NEFlXnZ3B8QMre5v5YXMntH rkOQ== 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=+WMCKwrabJt26VhQfSQ85nboExspuZ/m1PAYcfVaGMw=; b=dxxb8VaRvhui7+gpg0fQJ9ddeXoDAAg/TDTrK9Lkad6OICW3UPByJdlZu74EkyhAQL kMBg4MJMQHsB/LNIx5pMZk9K8kZRik5NlpytVF6bPF9hqiehPCiZcmdhaWG9nkZ9+VVV 4b6LYfezLoiRrDq/BKL0DrSIWBy97bPW/rL+VqZStwRGFowARQ0aAjzvTvvoCpncRoFH rt+gCniRoy5fnthxrGZYGXxH/Qn5XQcx6CYbpkZ4rv1Vz8DP6/bK1D1+Pg5JjnEUe2xd YG8whMlYO3PqN2Crflz4NWqAyEsjEcdfIuEbQvF7puTJH5UCHRv0+CWASrVRBZHrUwq+ 19SQ== X-Gm-Message-State: AOAM5339R/I7YswXYpiES2WCZfaiRlGs5NXQ1yq+BVYShFWsnJT0AcRO eglWkWJ77Gscnh2lSf/Ngb5vQl+mBs0= X-Google-Smtp-Source: ABdhPJzXl2exXrle50fA3vF6Q3xF8vpyEs4Bw1fe4WsFtnbE/NHjjxU6mprQs2zExM5K1LwP84nq1A== X-Received: by 2002:a05:600c:3b97:: with SMTP id n23mr2819385wms.93.1632497957311; Fri, 24 Sep 2021 08:39:17 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c30sm8546243wrb.74.2021.09.24.08.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:17 -0700 (PDT) Message-Id: <2ebaf8e68c2c46f700f7523d96e7494ebe3fb8cb.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:04 +0000 Subject: [PATCH v4 03/13] 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. 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. We extract the logic around determining the file type, but attempt to avoid checking the filesystem if the parent directory already matches the sparse-checkout patterns. The new path_matches_dir_pattern() method includes a 'path_parent' parameter 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 | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/dir.c b/dir.c index 86afa2eae00..9ea6cfe61cb 100644 --- a/dir.c +++ b/dir.c @@ -1303,6 +1303,44 @@ int match_pathname(const char *pathname, int pathlen, WM_PATHNAME) == 0; } +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; + + 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 @@ -1318,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 */ @@ -1327,11 +1366,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, &path_parent, + dtype, pattern, istate)) + continue; if (pattern->flags & PATTERN_FLAG_NODIR) { if (match_basename(basename, @@ -1355,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 Fri Sep 24 15:39:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCE84C433F5 for ; Fri, 24 Sep 2021 15:39:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6C3460EE9 for ; Fri, 24 Sep 2021 15:39:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347242AbhIXPlD (ORCPT ); Fri, 24 Sep 2021 11:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347193AbhIXPkw (ORCPT ); Fri, 24 Sep 2021 11:40:52 -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 52FD9C06173F for ; Fri, 24 Sep 2021 08:39:19 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id w29so28657163wra.8 for ; Fri, 24 Sep 2021 08:39:19 -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=adm/5uXookwNtOKC6xNU6gRZXZoW2bFPuW/qo8jSjBTvVkJe2ULm19+h877BMKt5Td 03a18uiaK9olD64tv3ezLdfvBnB9Jk5shtJ+FH8Djnevjd3H7XRH95jbGfkX6LLJaVZ3 oQc7dCZsiFzV4Gh7OJmOldFbkvNTYbPFfcok8gMHBE54Ho1PaqlCSdW2COc7PlqsePZn VkRuE4zXQCZGQnTb24o0Vvco2ysP3ieEca+QRKmw8HUk/y+rQwD2JlutvckesPK3qP4D MGc+GIulL8azz6UzxRAsLBRhw0sUvUgz51jUxvz9JKGedE0pqGZ4FORqy4vBr5oL5qu4 gvHg== 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=rk0SOn98/ipkxvdZE4isspCSzSb0LIHpEtTEK9zTmHmDYmGwbu6/6bfwUfzEAIRNsL W1U4cVESh6qIHktsTW/UExzZhJxx+9i0E7gGzP3n9Lfety/7Sj74P4sHSKAn4RuP41U4 5HpMw+DSBVT28XcS1yDJtydU4WCXQxhjcMALeNOBvYxxn8Gf5+j/ULz+Ew2bFJAgCb6F iBj2SGaah5NPvYc/BjHRxWlODzR+lZlTOC0FvV17gOm6I/YZ+NYgMnPdhzsV9vCspics jAlP6cZKRRpfYvPDrDAZjIpxcnsUNwnnSLfXeHzfZINwzbjVAzV59p8JnchxbWU31WPT A1VQ== X-Gm-Message-State: AOAM532dQxG6d9O4RWwM7tCzg9qOD5lkbJ3ZfParvwfhGtWsGRiq3H4h mg44PM+7O3DknyNWlTkmUHBgt9r7sIA= X-Google-Smtp-Source: ABdhPJzGHiVUdaE8Y2lZ1/Fex8Q0kiD2D+/n1/1uzk2PfTB7l0A64NnMEglkq7bPBneRgxfyzg2BUA== X-Received: by 2002:a5d:6a8f:: with SMTP id s15mr12121166wru.15.1632497957971; Fri, 24 Sep 2021 08:39:17 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b187sm13000582wmd.33.2021.09.24.08.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:17 -0700 (PDT) Message-Id: <24bffdab139435173712101aaf72f7277298c99d.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:05 +0000 Subject: [PATCH v4 04/13] 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 Reported-by: Glen Choo 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 Fri Sep 24 15:39:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1CD3C433FE for ; Fri, 24 Sep 2021 15:39:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4BC260EE9 for ; Fri, 24 Sep 2021 15:39:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347244AbhIXPlD (ORCPT ); Fri, 24 Sep 2021 11:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347127AbhIXPkz (ORCPT ); Fri, 24 Sep 2021 11:40:55 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F078DC061760 for ; Fri, 24 Sep 2021 08:39:19 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id w29so28657280wra.8 for ; Fri, 24 Sep 2021 08:39:19 -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=AzidAS6MbWAOoKEfuahayUmddDa6ZB/n3FslfgwPM8U=; b=cuTPzerP/Ddqij2m5tqJfA5RpqUKKzPJdRSyQ/a4nBnLnNi9l+JY0PplNynoGaF226 AYgT/scw44fi0p6ptqQt6ek2FJGLPXc8/kIL/1rsPjSpZ8SWT5KwQzE/aPeGF1BwHvaJ Uljxf0G4EUcAZgdpVlgjjNQD5gQwTUd8Wm1ffpWXsN/SauxBjXyVgQTMLHROXZjJw17H SMXBIVGzPMrP4YHub0bCLQOHTiupRsPzsBXCkHNLWiM9ulLJ/CP3ilXCzhI8Ra+og76M szShF+nnYIc2WkW9d56FhH4vH6Gu2J2gC+eX1f0dWzScha49mwY0xulOHavKXYR7m0FM Z14A== 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=AzidAS6MbWAOoKEfuahayUmddDa6ZB/n3FslfgwPM8U=; b=VsMOtFUw4DajTM7g1k/yZF8UPRj5InY4oVMgeIsDOyMHTVZBji3AcLOk114fo3JhLX OPDQkOnHkMFH8Ua2nsn2cwQ4OPyWtkuW1oOGKaSMR6f4RhKNpzouPeGvNAIaMnyn9HJg lEjVXQzVpptDi1if1u/lnCKc0fVvUu7lhfDuNHF2++gC6CHV9umCIVwT3Z1t0KiIgwCh e8PCxxziO5kxFCP574RLNrG/hjk2kg9E96/eQfGabXap7kBZc0Qi/99kvt0/PSRBlGXp J7VfaYvRZWM97hQl46a3o/91Y9xLdU03Z1SK+mSUWqKUNsVps559ZQHHDb+DgZtGPI3C 7kyw== X-Gm-Message-State: AOAM531HXv3UsgON9LMtEzLU3smHEaMbClGN1NwtS5ZY49SF7/velHxl t7AZfG9REbzmagtp9dBBhzEG6EUxllc= X-Google-Smtp-Source: ABdhPJxMrsRLUv86jIcdVzgG6pZXg0oIFdze5kGAker6ENUM/d+mNRICehRcxPucRMMMW78XeRSs0Q== X-Received: by 2002:a5d:6a08:: with SMTP id m8mr11955025wru.336.1632497958560; Fri, 24 Sep 2021 08:39:18 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v17sm6714843wro.62.2021.09.24.08.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:18 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:06 +0000 Subject: [PATCH v4 05/13] 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 7edc2060221..17525ff13fc 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 Fri Sep 24 15:39:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F84BC433F5 for ; Fri, 24 Sep 2021 15:39:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 834016124F for ; Fri, 24 Sep 2021 15:39:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347250AbhIXPlE (ORCPT ); Fri, 24 Sep 2021 11:41:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347139AbhIXPkz (ORCPT ); Fri, 24 Sep 2021 11:40:55 -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 842BFC061762 for ; Fri, 24 Sep 2021 08:39:20 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id r23so3403501wra.6 for ; Fri, 24 Sep 2021 08:39:20 -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=532IdcFlp9qd27qq2wqz0WCGxlV3AiMKH+CnhnbNt4Q=; b=GlWuasQbdZmmajy/4Ttft7MwDy9lysh74xyKpld+ZOd40s1RN0f2ud84xX66T/yObN eaDg8fSax/5wZwcNJrlW0WcrjdjgIODtd8ZLf6SJMzypv3nYLHxAOI7G9Wb6T+i8SsiJ Ab2wkNcD/SND3DfPxxyliR3Kd/yX60wt81QfWSSmIFmIpy1L14GnskJFM9DQJNcyEvS8 15t8YdScrZjHlKYMTnb04yUZ+qwbt+/YgDlqRjo9IBPno7NBakMtLzEUfFb5Z/s8vWIA Shne0xqooEkw+hS3DCh2CM0kh8U9HQ/J24VbQQz+se+RQ8VL7n5qeQPg8Tx6zXwRdnk+ St/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=532IdcFlp9qd27qq2wqz0WCGxlV3AiMKH+CnhnbNt4Q=; b=tN83hXX21LEd9YNr9QdGFvr0t52Zfj+GXyS1ZuyCFpPtSzkSz8yiHcQMAqac4oMqyj OHSs56wRbSfYLRgLHsTiFFO7bLF+S58vD+XIlM4tA+bIBjYBppDqLOsV+wj5uj4CxofP 6lkCrAe0tIdpaQF9P56NyTKZMN07FmBmZC51JX/yaAB+B9aLMDDptWC8IXtnjY4vDlUJ 0t6B34WYndwfRAa+d8uJOYvzCeN+nYepNtuZYo4ouTqHehD/RyzajQ69rSmy6M5GW1oi yNMxBiuWULdRudqZoggxQieTY4dmIX4BIYcOSctpSKNQr3C6YzYT9F7sqmQXuGZu1F2N k3Bw== X-Gm-Message-State: AOAM53103a1e8pUeJMxHsJXAVaZ2CK2GB5W4gZWM5Wv3f14sr4cMcvZ3 GlgJxLGyWpktirnHf7hPKi7kwn0LJfk= X-Google-Smtp-Source: ABdhPJyOJEh+GWKYMRbu9glbxfKpC5r1QfYrmPPCPrFWA4PYEkpKCEadYI4+FBg4k+qU9uvIExx5/w== X-Received: by 2002:a1c:1d86:: with SMTP id d128mr2820906wmd.142.1632497959131; Fri, 24 Sep 2021 08:39:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a3sm8522672wrt.28.2021.09.24.08.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:18 -0700 (PDT) Message-Id: <2c5c834bc9fb42aeaff7befbba477aec727184c0.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:07 +0000 Subject: [PATCH v4 06/13] 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 17525ff13fc..062b42f2c10 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 b2d798662ee..be6809eed23 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 Fri Sep 24 15:39:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B802C433EF for ; Fri, 24 Sep 2021 15:39:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6097560EE9 for ; Fri, 24 Sep 2021 15:39:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347166AbhIXPlF (ORCPT ); Fri, 24 Sep 2021 11:41:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347196AbhIXPk4 (ORCPT ); Fri, 24 Sep 2021 11:40:56 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53E4EC061764 for ; Fri, 24 Sep 2021 08:39:21 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id g16so28769301wrb.3 for ; Fri, 24 Sep 2021 08:39:21 -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=UDNJ6KiqjxTc8U1CLX6oWVmCZpx8NcJEbNCimeGHWvI=; b=Af6gkRNjQrcvyoRvLQvm0dZ7AR41+naxixVWvGmo3x1wtKPQ7y00d5xjoOnAW2bj3v mpj+zCRyaRmZ5FpKFx65HhLpngV1qf/LyqckvtkQKPx36jyzJ6S5zc9+opLh8L4is2fN S/OSTrAIjqOtePLFksSqO/mjQ6hCI922MWPCBbHygm7/EY1jZ8/BIZByxFfvt2XDElrV t7qudCLxyzNCzruI5zudve+mYM1xQDZ0mHINgTJv0m2ybTXW05drc36sUIipf8Q3Xtmd r+ubuiN59h4XyFxntX/F1eW6tRvhth1paA6lTC4maKUKoubIHlk0c7BJCqhZ2PvQHZX5 Fb/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=UDNJ6KiqjxTc8U1CLX6oWVmCZpx8NcJEbNCimeGHWvI=; b=OLytQeIjsrl9XVwVVqzzjxPw110Ir2pPofmn8Q7j9t+DavkBvpHnHAI2DJQUdHB3Gt T+ezWhBwMcqQ36KCcid0DXCMllwdQH6H05pmyR8++hE8ZkJoi9BLsQCY1i/xFKUDKNex 0AXnCIOGjiuHmnyLNJhv8CHw00h8FibQyWMk8TfO7LYrOKL+/tnGPj+I6WBaImiSDZ6w y5W2dKFYME/bC0TX2RUfqudsT+3p+vwS+2CF6JnXBY34Ql65KntvugdHxbyueUcUhtPb Fjz4pDgEgjZ7FH5KxwvXjgEPxDktf1SrF6FrNb29wKi9r+thqbINQfqwK56/XA1pS1eJ xuGQ== X-Gm-Message-State: AOAM530M0qt9EQCDs92/wDfgtoO8/XMyfOylC8Yd2pmWZ86kp+/JaKE9 GI1Dnw99v3lbTFfDKpjYCUgJYPWiiCA= X-Google-Smtp-Source: ABdhPJwcPVZnE2lgU7UKLewDDWYk2Yf8wjoZXWMpLA2OyVfvcnF2Qqp5A3qbZy7QCZXNCncNON3qUw== X-Received: by 2002:a05:6000:154e:: with SMTP id 14mr11987836wry.53.1632497959724; Fri, 24 Sep 2021 08:39:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 10sm11892175wmi.1.2021.09.24.08.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:19 -0700 (PDT) Message-Id: <430ab44e4f1c7998cee5f034b6a32b065f197900.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:08 +0000 Subject: [PATCH v4 07/13] 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 062b42f2c10..a00e42fa233 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 be6809eed23..3cab82092d4 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 Fri Sep 24 15:39:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ACCFC433FE for ; Fri, 24 Sep 2021 15:39:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 308F761241 for ; Fri, 24 Sep 2021 15:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347264AbhIXPlI (ORCPT ); Fri, 24 Sep 2021 11:41:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347197AbhIXPk4 (ORCPT ); Fri, 24 Sep 2021 11:40:56 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D136C061766 for ; Fri, 24 Sep 2021 08:39:21 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id i23so28833390wrb.2 for ; Fri, 24 Sep 2021 08:39:21 -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=p81KuoHo0hpFPRuL3S/d6BGjmb81vBJTciXyM2X9dQw=; b=Bk/YLmXYLwnQF8qGSg9s5sROFVrL8ZwhCCeyGdIBrAY2kMmcmaIhZln7wcTs41hkUG uNKgKlgH0AFxk0O0EF48fsR0792HW2V4K7fZRGxl6c0yhJz1QQbPplQ2h+id9WEt4bZG TuqUDGHUvDeEK8j4vO0lNwHmGqi/3bmH1HGkOuecM5FoH43q+gEtxJvOnNbNTRnayrt2 s7xt5iPsWfpfpq6YccB2ix/cub+omppO28G3fQ7FaBZK7DU8//uKODzgb4PLDE+XVApf NWJMsehFJyZQ2oYscWJF9C5AgVvvYnvxPPjDOAJiNdJsZNR2FDTKTh4M8Ebeh4YHTj4i wyxA== 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=p81KuoHo0hpFPRuL3S/d6BGjmb81vBJTciXyM2X9dQw=; b=Jmi93W27AS13UTb/JS/CNSInl+blIHN8x3JJpZ0YYmZ3ZR++NakRuKLPCFYWNIGQzQ wroDI5uHrXulR/0VeE9/WlSZLpWgW9Xn9TVluvlmbV96RyMlykd3WRDS3XJHKhe71vMO 3w+7RKOK4ChnUwsFrHhm7eXDfsWf/XzkIhxtBFv5hIpujxaQpYaAx6ZDgd64mS51qvUN /bB/2lREOIHZF6IwGa3/01PhllIw12kfFcpty0k8lzF8Zvt1+GMNK4M4qfiwB2GThAPm 80wZsRQa2TRct0/IZ577BlILbvsodWfhjjmf5lejbcBKqwrITKA260jHgP4E6bXiYrfF MuEw== X-Gm-Message-State: AOAM532B2/zzEufNmkCM46bKbEcXr5gC7PggKULz38McnFqbnE6Hj8E8 30mCAf7qaZR69A3nejDHB+qh5V4j92g= X-Google-Smtp-Source: ABdhPJyKs7SDl5neY53vDnSGGSmnt4iT+vg6fimcPwySEfgHdbHDiYYYB7X+CQmUktiL5vhvYdma/w== X-Received: by 2002:a05:600c:3797:: with SMTP id o23mr2830069wmr.111.1632497960271; Fri, 24 Sep 2021 08:39:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y9sm14921432wmj.36.2021.09.24.08.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:20 -0700 (PDT) Message-Id: <4f7b5cdfa36b2edef666aa12ed8aee87405fc884.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:09 +0000 Subject: [PATCH v4 08/13] 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 3cab82092d4..0ae674a17a9 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 Fri Sep 24 15:39:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 643A5C433EF for ; Fri, 24 Sep 2021 15:39:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D72B61241 for ; Fri, 24 Sep 2021 15:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347278AbhIXPlJ (ORCPT ); Fri, 24 Sep 2021 11:41:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347210AbhIXPk6 (ORCPT ); Fri, 24 Sep 2021 11:40:58 -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 30DBCC061767 for ; Fri, 24 Sep 2021 08:39:22 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id r23so3403699wra.6 for ; Fri, 24 Sep 2021 08:39:22 -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=wOwNNxQQ+mcgo4o3C4W2z+jVMvVl7HqRUJZg2LK5z54=; b=WnY4+XYvxZqOYxbe++i1TenavZOgA5Fwe/y2umWpVWQRhAG+EePJOxi4w0ReFIhEGo U2bGLRb4y+vlKxiSqW4JfEVhc/+2YYbF3NRlI2Dd7QRDBlTSsyPc5InL0idjCgxmNGhi exVQNESLIY0u8GAFEculTikKk5oIKKbgxdCAF3drEV5r3p69qtXqyzU3IzjAcQUv1+sA zbgj/O1D7EBntC9ZL/it/bVy0pZky+Ka4tsgT4SxEZSQmt2V2WUIqTcoDhRsqv8YkY/m eKrc2ZQ2b9YSJ3ytKy0meGIaAYp/DhDhgqHhGEaqb3ks3jslgzTRdfXXF0BaAfzNAqfD 1QEw== 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=wOwNNxQQ+mcgo4o3C4W2z+jVMvVl7HqRUJZg2LK5z54=; b=nhqcnV1a/hKq/syBAiUAbHZm7FHqg0b5J9lrXCi5fqsdoGssjIMlR+aa76P+HXSoCP Xm80W2MMf4f15hEu9uSU0AsLp84awup/1ZwdPuNY7AaMTwMqrE9MLtDG2xPeiXJ05gao fHjIkTKkbPcGHgWLP7QDLk8RBCx8WhICKMP2XXhoerZZz0zyU3tmKfFQjVAjJWpAG1GP +sRnTWSNSqvCOEDgwugslavMyw8/Rx60/DuE9bJhHdqZoNhg8fCSY4roWhEDd16JW/p7 UqkFLfXhV2lm3e7aSB5xMVROGln4t1u5enQEf3Kl9hXPaAweHAHXfFUAT3wON6tbN99H +EGw== X-Gm-Message-State: AOAM5325StLH0uStrh9J0BfOzzLkrzTdVxvjYuaAQOqZz0vHU2aue3JZ GGGdyqv9ka3ZKFo/DBL3OkxUDhuNNYA= X-Google-Smtp-Source: ABdhPJzzptxLYB6GskHeUdG1Hwx/KBG7/vgSFWjD+KRqcPTnSvHKwLgIb5BBcY7fGRcpbCbsQY0Zsg== X-Received: by 2002:a5d:58cd:: with SMTP id o13mr12551243wrf.416.1632497960864; Fri, 24 Sep 2021 08:39:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j21sm9328330wmj.40.2021.09.24.08.39.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:20 -0700 (PDT) Message-Id: <30ec60969399e2d876d34fdf2150e4152bb9438a.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:10 +0000 Subject: [PATCH v4 09/13] 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 0ae674a17a9..339ec0ed2d6 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 Fri Sep 24 15:39:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 701E1C433FE for ; Fri, 24 Sep 2021 15:39:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59E1C6124F for ; Fri, 24 Sep 2021 15:39:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347285AbhIXPlK (ORCPT ); Fri, 24 Sep 2021 11:41:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347221AbhIXPk6 (ORCPT ); Fri, 24 Sep 2021 11:40:58 -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 C9071C061571 for ; Fri, 24 Sep 2021 08:39:22 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id t8so28808509wrq.4 for ; Fri, 24 Sep 2021 08:39:22 -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=DoRbiz+OYsR9Tr2FEAXVigyHH00Wb7F9mAwy3+R+mCCO6y4Mh3v5dvlnsSyMZLYiv2 47Tg4nRidWrrSo/CGnZ89awu8sJZOsJ+c+kMec8z0TNw2AhzjNqXF6I6tHak0pFt/1jp h4CRXXb/pBDf9YG0bTnoiGEHHgoVBd36g+bNlKgHI6K5OI/Pl9PCuusnlwCDelrSqfPB +KpzU+4mtkPI3/7u0oaun+dXY5BmhKXzHiN5qfBkPQvRycWgwt+6ezakTZZwxxMSE3ij yMNxl9BbZ6p8+WsdTEw45ML8c90WfXJTArl8xRO20IfvsXcrvqbM1bXIzaZXiuTG5yih H5Sg== 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=3nGwfu2MdQf/FFlY4L+UF2rINNGHzRo/msTH5rV/8wzNItVzsY7KdwVQvW9EKk2f27 +2pc/gh1XWphuGB57bdqB3t/iMVDcqk03VcIdc1ohuhGzHSFl3L31+bqgOIOWlBhFNSu Di6uiJh3bS07fTEXbTO1g1IqX/it/uq/EPJ8FmgItybY0zxGovHI6xEG1oMJwUvUWwUd iKQd5Vl8uYpw5q+m8Dff+o50JaIhrXCl6AWKAc7jG9CdNtxZbBuOP36VkM5Gjnbt2GNd L2mW3xhRGpZDOIQAMSleUFdjDnxCBTiRwgP5JNQbONLO9O4f/ERKMvr6XM+X2NQx43k5 ldBw== X-Gm-Message-State: AOAM53013oGIclhJnBPPzfVBjXBwaeoME1QhM98TASsmMJzssTJIXQDm UgchmdbxxVNI7gArbvs1Bvt6ffjtyUs= X-Google-Smtp-Source: ABdhPJygs+XujYL/gkrBNwdqaxOdi+cOmtHfnYs/g3fQojReG/ustyGb4IyAF2TOjWnBakHc6TOABA== X-Received: by 2002:adf:dc0d:: with SMTP id t13mr2940691wri.158.1632497961458; Fri, 24 Sep 2021 08:39:21 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m128sm6784893wme.0.2021.09.24.08.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:21 -0700 (PDT) Message-Id: <99d50921ef4b787a0cc67d05a1a92f64a91b25d3.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:11 +0000 Subject: [PATCH v4 10/13] 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 Fri Sep 24 15:39:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4DE5C433EF for ; Fri, 24 Sep 2021 15:39:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91EF161242 for ; Fri, 24 Sep 2021 15:39:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347299AbhIXPlL (ORCPT ); Fri, 24 Sep 2021 11:41:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347225AbhIXPk7 (ORCPT ); Fri, 24 Sep 2021 11:40:59 -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 5BAC0C061768 for ; Fri, 24 Sep 2021 08:39:23 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id g16so28769611wrb.3 for ; Fri, 24 Sep 2021 08:39:23 -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=YS5YoRaAnqVLuQZeG0RkEs+pTLEi4202eOZaP4px3XYMc3m+CC4CFdNU4PHPz3Iffs FJvJPbhEpYpeSo5q9fLfnazwZrgWh3ZXMICt5p8xyXEVhnTQnJDZ7fSBZ4GecL9zfb4A 19c6LUZ6WePnNWaraJQ4zE8P9/rFVE6YafuW/4qUUG98HOMKmL4hKLA+6oV30uqjkm0l r6ZH7dJqdOKo6uDNqyk6rTFuPE3P/7yyh2MNP/vMkxsWQci4DaelueR6G6qgbYf4maRh xAmO7M7pNCzktXdwVxvyTrxNjDIMp7W8782PzQW0kZfxJi9nYKrZ9ScVjA5oui72tr/F Isvg== 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=qL33IYCRIv91XXHntmhH+Rj/ZA7B3ktUH2CDiJrjdf1iyHr4K0cHr24BQOQxnIaOR9 demo4yGatcuJ1XXlVkl6giw9krOygbDH2/anqx6hcFsumWZqfR8VyaFtm0t4PZkuO5od mUS79WaNORyzBJFbSMXrreNWmNUmBTdqVemWLohONMSaEubHojzvmEUHcqvlBxE7VNi2 OOF04eRPJ+NxhlAOuVA6BJKTsA6LlKW6Phdop4RDnDO7+qAyVkihkMp/+AO1zY4CrD+N VGEdAm0aKjxNkxLNK6ioTGUkag0ks7B+AK2QWx6Be/3HWQFlff+NZHvoYwSgpVzhAvyZ DTpw== X-Gm-Message-State: AOAM533aeBULELq5xeLGKhDmchj+AVx54BPrIluW1rRBBBvdxYotZH3x hTUZ8gv1wOHUOhMXM2WAf9WkUTcmz5E= X-Google-Smtp-Source: ABdhPJyAJFqzeHoonPfoBcaj0jrf07OX6ltpfzZtqkPSFRAQ/nS4UyulW9BOoaRz34o8wnbhWX5myQ== X-Received: by 2002:adf:f805:: with SMTP id s5mr11947498wrp.259.1632497961972; Fri, 24 Sep 2021 08:39:21 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m4sm13000263wml.28.2021.09.24.08.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:21 -0700 (PDT) Message-Id: <47a1444115b517b2842f179ba692962a982860cb.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:12 +0000 Subject: [PATCH v4 11/13] 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 Fri Sep 24 15:39:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CA12C433FE for ; Fri, 24 Sep 2021 15:39:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0630C60EE9 for ; Fri, 24 Sep 2021 15:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347245AbhIXPlM (ORCPT ); Fri, 24 Sep 2021 11:41:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347226AbhIXPk7 (ORCPT ); Fri, 24 Sep 2021 11:40:59 -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 11CFAC061613 for ; Fri, 24 Sep 2021 08:39:24 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id g16so28769716wrb.3 for ; Fri, 24 Sep 2021 08:39:23 -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=IMZnZ18YieC+sYkw3vpe74OPJULpBi3r1CckwPojoisY8+7lqXPifVawjcQtDFyaan qHIRFFSLNyGB1Fm6yK/eqKVNxWlwQGmmfo9qn5+QnuUJ9iIo1GuUNtO5kjcmS1u2+CCN X5nvkwSMXV56d2Wc25DdbJ9vTC/d0KXAeho2SgIh8EbXt7t0+PVRfspYFVEouhwWCxxQ WFJqQE29qen0ssrZznnwaLuM4reBaVHogR6GLvtMHuk1ChXHPbNz+2hblA2vYA/Oa1ZJ zrYHmTNT6KC2Wlt1AbmQjc7de9s/M3EKOkX7YmLGAnUXXTxYljjcGkCUGMQAuAgwnxVz cnJA== 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=AgdcydNZkmJFeF8zWSNs/6f32gMNIdYEfmVRUOnpRc7HyQIhaVWTSxqzlG4nGin3Z+ 5ONBCn15ndQrJ7eCYJKnqJG4YnzYDVU9Fl5qLbZ6hZc2kXvVUgiC9fzobmq/DkADKCUF veJv2CevewaXOR7NNJoqt7mwFUra4xoZ0dkdXTkPUBfmf+kl7305hr5fqr5iu4cJojDL j8spZy3RQyCgTmy1TNeCQVmndWoHtTQsmJQg/M4GHLxn2elWaD/g+xxLrMowKMzz/Kt6 Xb9K9BtTHa8tbksM59Pw8p9Wlrig7pVCr7PQNSs2oiFU4HJ1OeC2n/222SmWwJoeNQfj 9duw== X-Gm-Message-State: AOAM5312FErh0FdLNNpfSl6QJkilf1F4Jugx8O8Ck3YmOJ7C0iZ/1Gcc mbltO4m3OSUuhMgnIdhOKompXH2zoL4= X-Google-Smtp-Source: ABdhPJyiyn5JEe6hbuXX6kYjzisWWjBuOJATYsH1uXtaFizsDLRtGPJsbrQLG9Pb25zqA84MIW/PLg== X-Received: by 2002:a05:6000:1284:: with SMTP id f4mr12423551wrx.88.1632497962601; Fri, 24 Sep 2021 08:39:22 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h125sm9037613wmh.9.2021.09.24.08.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:22 -0700 (PDT) Message-Id: <28e703d80d38b5589dc117823d40ca99f8ad7cf3.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:13 +0000 Subject: [PATCH v4 12/13] 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 Fri Sep 24 15:39:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12515865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8C96C433F5 for ; Fri, 24 Sep 2021 15:39:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0A1F6124C for ; Fri, 24 Sep 2021 15:39:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347128AbhIXPlP (ORCPT ); Fri, 24 Sep 2021 11:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347182AbhIXPk7 (ORCPT ); Fri, 24 Sep 2021 11:40:59 -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 902A7C0613E2 for ; Fri, 24 Sep 2021 08:39:24 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id t8so28892038wri.1 for ; Fri, 24 Sep 2021 08:39:24 -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=IqTNWyRXSwlJyMHaVGmitQJJcss5hdQINHnB6QXcZhQ=; b=Aw3T3VOvgZdiDqv4rH50moVmeld0jWoSNyUy1FpvpqYRduIFq9K30UpJUywbPGCx5J ByVj5ywhyjI71RmlhYtRrXNRU9+64vEpxN6jK0DHwYwyNkGrAd5HW+06gL6GqV1Fo69A MkEktTAUh/9Dcqu3MMx9OQB2WUaznKnv5ZXP488xMqWEy8KqjbRxZmrCZIypnnGxfyri 4F3WGcVktY+zEuhaIdCgmHiwRTnPLzePFp12JDpzb5AEKlnQ+YkD56qGvyfSVYBAxRjS J6RNQnAXthwJNwtC3vVaZv1sQSyq641uEZI1pztf7aTTkYkxl0mYzl+k6fVsz9xaCu0c vcDQ== 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=IqTNWyRXSwlJyMHaVGmitQJJcss5hdQINHnB6QXcZhQ=; b=ADMnOyMxvG4QwOOsdDF+7sgiq+MORcZ+H2xvxPnp/vVhA+eR8nKfNpimtGb7Huk4Qv lk2C+Z4M7MWB2lpjNnLzMMxl1kY9pmCkjWeEXWs4XSeHZgRSLYwrV7OKPmzAugBMoRtf lU4O1sAvPSVnPvWnQf5Md7tIOyltnu7fvW4LUG671FGV+cHrPRaVEfe+0riTODUNAe6d DB2NYEjG9eFQIEm/ieyq6IzJ0G2DT8YfA+iajtyJ0ETB+b9i4bfW9DKnT8kAd3Z3L15e 6rDWNDARpZghpOJwCbCjjG62vQJVNVlM4PIOZ3l1ZhDz+plasCMyC5e240HvrNh1Rfej N4ZQ== X-Gm-Message-State: AOAM530xdV1KYIezXaxrPgSeo2KZxW6O/zqT8pkDYrCT4xXOMg8+ymvj sIQlP2IQInDa9IxkpPQmeXwdJ69Z91s= X-Google-Smtp-Source: ABdhPJz7Q5Xz33Ni4CPmWDXEy/nfa/zmLye82X9ShYAycsldyLpJqM47WL/IoEs/vkkgonPAl8w+Hg== X-Received: by 2002:a5d:4d92:: with SMTP id b18mr12019300wru.245.1632497963170; Fri, 24 Sep 2021 08:39:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v10sm9073516wri.29.2021.09.24.08.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:39:22 -0700 (PDT) Message-Id: <9fbc88ee0dab830bdc34575e9808b8f2a04a59e9.1632497954.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 24 Sep 2021 15:39:14 +0000 Subject: [PATCH v4 13/13] 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 339ec0ed2d6..5b904988d49 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 "