From patchwork Tue Aug 24 21:54:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03CBAC4320A for ; Tue, 24 Aug 2021 21:54:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2524613CD for ; Tue, 24 Aug 2021 21:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237947AbhHXVzd (ORCPT ); Tue, 24 Aug 2021 17:55:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237295AbhHXVzd (ORCPT ); Tue, 24 Aug 2021 17:55:33 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42905C061764 for ; Tue, 24 Aug 2021 14:54:48 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso3214938wmi.5 for ; Tue, 24 Aug 2021 14:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=svIO42vGlZwIuflOGzN7ll+SM7YSJGkuU6Z4a3rxGeY=; b=oNMIFh3gOXyRMvAaijnTqjQikaDOIaqwwiTZGnJveeGoQyq638BGBtBIiVSsOybLjX 2Dsg8pCJPclQ4nE73WxUba52pP/7Q6+6lN/ePCplWKV24oTfn1r/ygcWCd3f6RRqC+RY mhIgw+G087b6ocDtVE+Dwff3d7UYyiHBZZRR/lH7Y8+woUxJQXk6oCLgycGQ7Gx3uB1B udfZLWDXbml4XApUia5utJe9g8MDffAdlG1yA6QSNgtjuRnbHoY3JW6DNbmQo/qci+s3 t5RhuL4Gl6c3eRSEUoTC4tWJKVclanFCeqMPOXWU3vR3vJdkxI1hhkdyY9sx8YaB6nH1 4fEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=svIO42vGlZwIuflOGzN7ll+SM7YSJGkuU6Z4a3rxGeY=; b=HhOkndsofOvxIrVwAHneUX/R6nR1uXTodaBNrXM+03oZLxTG/DH7PHmd/qe2eHMAfY e6lR65iDBFmX/C9s0ZocH9KEYc7/yim1T3vJ+674O4KaQrXOFyGqPSxAyHjXezQcYo58 gkDsd/RVXBI9BQRiCnoOjVEYFffLPLP/+F5cm1JveWyJax6HT6KJQbnHdMfSTeNllWt0 Dlbfirdq4KGYNWzf6gFJQ4n5H2hUFkMQA82hxyLk6VAOiX00yV/Wp9vpBU14P/Y+2o1b BJ55ntjXbqslDsvUgDJQl1F0On+NijFz8LrjXja6FURIE2fLEWCRzLYowelGfggMIKP/ h3fA== X-Gm-Message-State: AOAM531LZQmGzPcBzhntXeXbEDiKkuxcidtOsOujb9Jh9I7OsE4bAmb/ EvcVFlbtOZe0zAfmfiB3tZ3Ulgyl4aI= X-Google-Smtp-Source: ABdhPJzXhrUEemVMLYi7m7emKL1VgchmiiY1UAwUVRGghmAdw4Uu7xt5UokSCJm9/NGwEEtC/eZKEg== X-Received: by 2002:a1c:2b04:: with SMTP id r4mr6116091wmr.168.1629842086915; Tue, 24 Aug 2021 14:54:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r4sm3188703wmq.34.2021.08.24.14.54.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:46 -0700 (PDT) Message-Id: <69ca54877b4eac5c85195a1061f0d72ba6fca313.1629842085.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:33 +0000 Subject: [PATCH 01/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, 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 futuer change will make these cases be handled the same way. Signed-off-by: Derrick Stolee --- t/t1092-sparse-checkout-compatibility.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index bbc6de712c4..23bee918260 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -291,6 +291,18 @@ test_expect_success 'add, commit, checkout' ' test_all_match git checkout - ' +# NEEDSWORK: This documents current behavior, but is not a desirable +# behavior (untracked files are handled differently than tracked). +test_expect_success 'add outside sparse cone' ' + init_repos && + + run_on_sparse mkdir folder1 && + run_on_sparse ../edit-contents folder1/a && + run_on_sparse ../edit-contents folder1/newfile && + test_sparse_match test_must_fail git add folder1/a && + test_sparse_match git add folder1/newfile +' + test_expect_success 'commit including unstaged changes' ' init_repos && From patchwork Tue Aug 24 21:54:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8E76C4338F for ; Tue, 24 Aug 2021 21:54:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1748613B1 for ; Tue, 24 Aug 2021 21:54:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238467AbhHXVzi (ORCPT ); Tue, 24 Aug 2021 17:55:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237940AbhHXVzd (ORCPT ); Tue, 24 Aug 2021 17:55:33 -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 DD431C061757 for ; Tue, 24 Aug 2021 14:54:48 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id z4so17725884wrr.6 for ; Tue, 24 Aug 2021 14:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2zkseZDCrX5eQCOfTAj1pziuYCUVx8n+RzgjO8cPYiw=; b=XKUxZZ3boSP7/jEAM+CghcKg56NKPV5nW0JhdHpMakUjlO3dH7GUrg6SrrxTdoSMmi MdxFJb3Go1rhDywe+frjHoE4ysL19DffrhTN11Gg/zKUsAzy4W16hF1M/wo+vRT+G5MF EJsjLi6/W0E7b1ghQHKYavO3c5z2c8+kws2j84DIkzrbvNxkBoCWXlDRMBwu24MK+3N0 OqgU8MIQePH2y5zvtAkV57PaqKynqsgL7b/WcYFedo2J6K035Fj/G4e+qmiw5EzeAt0/ s3ezhJofQio+EcnjGSbtMQ1f0TymkSBNrtRR43R+tVWkgz8sNgQY8EfjrTVq51OE3KO1 tf+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2zkseZDCrX5eQCOfTAj1pziuYCUVx8n+RzgjO8cPYiw=; b=WHeXs+c+eU1nBxXP7KqstsdhOzo39iiOMop2Krd0cwhB/DMkFBr5bmi+Z/HRknLYPY VImF3UE0WhAfAVh1Y3WvFT1h4pyj90zrLR2u/wNfhYhK6HwfQHThDm+B1mnxwOFgwxE9 g3DwWODPI8vQuEj4zHEwd6EOjDpRFSOgcj10V9CrSu3gQth0tsobEdyKs/B+3WRBh/cR 4F7clePXtIz7qBvlw/WJEJZYti/d3+hN6Hi4SY0J21MKn+jr778QgGfa6GUxQjQ/dNpr jD8Bt99hscioOIjZEf2rJVDO4M39X7MtZMZNPtY5KqgnmiXR2sCyI6ix1TpDoHUH265a A4IQ== X-Gm-Message-State: AOAM533bW2woSkgTqnaUnDKKJ81P8zjR5/f7ajnRiVni2TE63uJNKf5z L0vfs9lSNIixzQQr4B8Z3iTnPZsPflw= X-Google-Smtp-Source: ABdhPJyDH7iW0WDMEABL3GOIQAfwyrmQ/LFITuOoI5hVu04Sz35jNfzTEgOCDTmIqmlacnQBYAoXag== X-Received: by 2002:a5d:460a:: with SMTP id t10mr16685919wrq.147.1629842087570; Tue, 24 Aug 2021 14:54:47 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m4sm3512530wml.28.2021.08.24.14.54.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:47 -0700 (PDT) Message-Id: <8cca5bcf405f220ef899ec44d01fee4d588c7a38.1629842085.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:34 +0000 Subject: [PATCH 02/13] dir: extract directory-matching logic Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The last_matching_pattern_from_list() logic performs some checks on the filetype of a path within the index when the PATTERN_FLAG_MUSTBEDIR flag is set. This works great when setting SKIP_WORKTREE bits within unpack_trees(), but doesn't work well when passing an arbitrary path such as a file within a matching directory. This change only rearranges the logic but does not change its functionality. We will expand the path_matches_dir_pattern() method in a following change. Signed-off-by: Derrick Stolee --- dir.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/dir.c b/dir.c index 86afa2eae00..652135df896 100644 --- a/dir.c +++ b/dir.c @@ -1303,6 +1303,19 @@ int match_pathname(const char *pathname, int pathlen, WM_PATHNAME) == 0; } +static int path_matches_dir_pattern(const char *pathname, + int pathlen, + int *dtype, + struct path_pattern *pattern, + struct index_state *istate) +{ + *dtype = resolve_dtype(*dtype, istate, pathname, pathlen); + if (*dtype != DT_DIR) + return 0; + + return 1; +} + /* * Scan the given exclude list in reverse to see whether pathname * should be ignored. The first match (i.e. the last on the list), if @@ -1327,11 +1340,10 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname const char *exclude = pattern->pattern; int prefix = pattern->nowildcardlen; - if (pattern->flags & PATTERN_FLAG_MUSTBEDIR) { - *dtype = resolve_dtype(*dtype, istate, pathname, pathlen); - if (*dtype != DT_DIR) - continue; - } + if ((pattern->flags & PATTERN_FLAG_MUSTBEDIR) && + !path_matches_dir_pattern(pathname, pathlen, + dtype, pattern, istate)) + continue; if (pattern->flags & PATTERN_FLAG_NODIR) { if (match_basename(basename, From patchwork Tue Aug 24 21:54:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FCEDC432BE for ; Tue, 24 Aug 2021 21:54:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6368A613BD for ; Tue, 24 Aug 2021 21:54:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237954AbhHXVzj (ORCPT ); Tue, 24 Aug 2021 17:55:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237295AbhHXVze (ORCPT ); Tue, 24 Aug 2021 17:55:34 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 766CDC061764 for ; Tue, 24 Aug 2021 14:54:49 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id g135so4389395wme.5 for ; Tue, 24 Aug 2021 14:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=IFLBnCb01UTxiG6mjxXgFtXahLMWXCrHCCNfFoecSsw=; b=XS0Rvta8ka8cmh1XPbGnlrTfI+jx75ZibeWg9fM/oToaHZecdFN5pd6YV95NIEDJuM M3jTdvn1dCPEhn4EeqKjkXOmN0sI0qLmqj6J7xxtd0f10W/VhfLnDkB9lIj5G+/vqWqC J2WWMdqsSMtEugj8waoKHXRokwuSfhMRHigiVIgPbLymmijZRxugKi0EWVSU9gqCRzax blei2QblqLIQ1GWl7WySSzDUuiop4XLnKvRtxVInkTzpwWdUHilh1PoHCf6CUOPnavrd P3bV7Codsjuel/TQSjyhJ+BCScc7d4sdIMfL7WfOIQhioiUrBQnZE65pFOlEmFQ0/Nc5 OStw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=IFLBnCb01UTxiG6mjxXgFtXahLMWXCrHCCNfFoecSsw=; b=oL7egimQ/pCs4Gx21/DsZxgaYD4cKytWDyAnYHKIkCNBODAlqUOnYFDQEdM3I8AfQg mKMm+gC6ABpRpfftQjecTywmYOkXXKSsMMb6RZYMlI2SfmZjikW55BxhMeBVce5HD47J 5Ay+QHvVJS6oXjWh8I/A8KQ3wRhP7d+hXY38JPXbV3UucIkHNKMsc6N21lBvxM6G3d8E zDEt74CQnqoEpmGNk/BWr6RS3lmj5LAOhtxSaU89ZM2EwTpMPlh8L1AlCOzzw5LL9P0q SH8dKGmZu8cT8TR/NrCRLe4Et4kzsnQn4PE8KQxRb0Gb4c+dHbGZBoNWmMkV8UYXR7S1 pDbQ== X-Gm-Message-State: AOAM530Ml9LBENFgyMopX5oDxlqzGx1sZwJrEBMHJ06Db9SsxrIMBq7o SuWKyh2pddkK96hWOY/bFikkEE8rupY= X-Google-Smtp-Source: ABdhPJzj4HjIhc4jDKkZOY/pWMbvE4JmhjEeW6/+HqvPpqFEKiwQ4oWyO6iX0aecjIfnC9WHcuVDBQ== X-Received: by 2002:a7b:c756:: with SMTP id w22mr6006896wmk.169.1629842088153; Tue, 24 Aug 2021 14:54:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n10sm18960265wrw.76.2021.08.24.14.54.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:47 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:35 +0000 Subject: [PATCH 03/13] dir: select directories correctly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: newren@gmail.com, gitster@pobox.com, matheus.bernardino@usp.br, stolee@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When matching a path against a list of patterns, the ones that require a directory match previously did not work when a filename is specified. This was fine when all pattern-matching was done within methods such as unpack_trees() that check a directory before recursing into the contained files. However, other commands will start matching individual files against pattern lists without that recursive approach. We modify path_matches_dir_pattern() to take a strbuf 'path_parent' that is used to store the parent directory of 'pathname' between multiple pattern matching tests. This is loaded lazily, only on the first pattern it finds that has the PATTERN_FLAG_MUSTBEDIR flag. If we find that a path has a parent directory, we start by checking to see if that parent directory matches the pattern. If so, then we do not need to query the index for the type (which can be expensive). If we find that the parent does not match, then we still must check the type from the index for the given pathname. Note that this does not affect cone mode pattern matching, but instead the more general -- and slower -- full pattern set. Thus, this does not affect the sparse index. Signed-off-by: Derrick Stolee --- dir.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/dir.c b/dir.c index 652135df896..fe5ee87bb5f 100644 --- a/dir.c +++ b/dir.c @@ -1305,10 +1305,38 @@ int match_pathname(const char *pathname, int pathlen, static int path_matches_dir_pattern(const char *pathname, int pathlen, + struct strbuf *path_parent, int *dtype, struct path_pattern *pattern, struct index_state *istate) { + /* + * Use 'alloc' as an indicator that the string has not been + * initialized, in case the parent is the root directory. + */ + if (!path_parent->alloc) { + char *slash; + strbuf_addstr(path_parent, pathname); + slash = find_last_dir_sep(path_parent->buf); + + if (slash) + *slash = '\0'; + else + strbuf_setlen(path_parent, 0); + } + + /* + * If the parent directory matches the pattern, then we do not + * need to check for dtype. + */ + if (path_parent->len && + match_pathname(path_parent->buf, path_parent->len, + pattern->base, + pattern->baselen ? pattern->baselen - 1 : 0, + pattern->pattern, pattern->nowildcardlen, + pattern->patternlen, pattern->flags)) + return 1; + *dtype = resolve_dtype(*dtype, istate, pathname, pathlen); if (*dtype != DT_DIR) return 0; @@ -1331,6 +1359,7 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname { struct path_pattern *res = NULL; /* undecided */ int i; + struct strbuf path_parent = STRBUF_INIT; if (!pl->nr) return NULL; /* undefined */ @@ -1340,8 +1369,8 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname const char *exclude = pattern->pattern; int prefix = pattern->nowildcardlen; - if ((pattern->flags & PATTERN_FLAG_MUSTBEDIR) && - !path_matches_dir_pattern(pathname, pathlen, + if (pattern->flags & PATTERN_FLAG_MUSTBEDIR && + !path_matches_dir_pattern(pathname, pathlen, &path_parent, dtype, pattern, istate)) continue; @@ -1367,6 +1396,7 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname break; } } + strbuf_release(&path_parent); return res; } From patchwork Tue Aug 24 21:54:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5ADD9C4320A for ; Tue, 24 Aug 2021 21:54:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 467E7613B1 for ; Tue, 24 Aug 2021 21:54:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238550AbhHXVzk (ORCPT ); Tue, 24 Aug 2021 17:55:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237950AbhHXVze (ORCPT ); Tue, 24 Aug 2021 17:55:34 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1773FC0613C1 for ; Tue, 24 Aug 2021 14:54:50 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id x12so33325197wrr.11 for ; Tue, 24 Aug 2021 14:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=NIWHJWvBiXtXaJEPmJtf0dHB0etFMwiF78iEbq7VnQc=; b=IJxxcNVwKhRZzYFesPVptaThtbZpS08tSz7du7aYV1O/Q3WZW+mcqH8usgm2vaKT9I h2Y5aJIpFbOrMfzDAK+wmuAlEuupPJNoNhiIJRnoQwAXcJriR9cRQTQTimpCCgjZh7A7 ep+qsKa/GwCjACM85/B7D55jr3d8MecuccY7dPX/2vQ7lKWitSAFRa6pPN0y2LPE8FVr mqi9UWv/s0I2Q7xRu08Wdv81ZD6TzxSrBFJ2I6i50yJNwj5haX/XN9Re5OIHfj8NazUC 9+3WQ1hss0DaKYTghbLLKfIoJYRww1LXzdg/w3RLYrBOZpmWh94X+JND8zBa+/6b4qbD Ayvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=NIWHJWvBiXtXaJEPmJtf0dHB0etFMwiF78iEbq7VnQc=; b=ntQWbjkz4HG+lYJjfdFwz9ddrk9kA5cYTMIcaAIunWLVpNNPJ6Rk7kqn/Y9y4/D3KP BXBaeRG7EL+SQKcCXhtAhoIQF7W540JhUt2Fgf5LfEsBtJ2dG+9bOBNLDAt2BzUc+6Fp iBugtazxXCR7xU5ODT/hhcamdJ29gxqloKO+UsyPPRayzkRrKXaqxT0k9//cZzblYSYv gh0ULW1fAHZotWL1GIHrcvbPqXDbZCC9/uYvE/7cdFbI5O6vYgmOAU5F2HbcY7htNXj5 lPvQzOEj3Azah7i0/wqvRbWI4XzZ/ZTH79OQ6avjX62XYrNsdvboVe/rvIhqaT+hH/u0 3yTA== X-Gm-Message-State: AOAM5332TiremRfK2Xzmn2P1qRzAH2sNH4KWM9x+O4YuH1uIZwb1hTIa zXIYB6Mln3HKr1LMDe9j14bTyUiOtuM= X-Google-Smtp-Source: ABdhPJy8d/6ihTZ7NTk86V4DsVSV9VCKS98OK2BbGxeKgcyHN8XaGDJkVokPfXukAdH2WcPeqANeXA== X-Received: by 2002:a5d:4311:: with SMTP id h17mr21495490wrq.263.1629842088731; Tue, 24 Aug 2021 14:54:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j17sm2231583wrh.67.2021.08.24.14.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:48 -0700 (PDT) Message-Id: <58e7df44982965234c028174ff108a0abeb9862b.1629842085.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:36 +0000 Subject: [PATCH 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, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Within match_pathname(), one successful matching category happens when the pattern is equal to its non-wildcard prefix. At this point, we have checked that the input 'pathname' matches the pattern up to the prefix length, and then we subtraced that length from both 'patternlen' and 'namelen'. In the case of a directory match, this prefix match should be sufficient. However, the success condition only cared about _exact_ equality here. Instead, we should allow any path that agrees on this prefix in the case of PATTERN_FLAG_MUSTBEDIR. This case was not tested before because of the way unpack_trees() would match a parent directory before visiting the contained paths. This approach is changing, so we must change this comparison. Signed-off-by: Derrick Stolee --- dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dir.c b/dir.c index fe5ee87bb5f..80fd0ad2fc0 100644 --- a/dir.c +++ b/dir.c @@ -1294,7 +1294,7 @@ int match_pathname(const char *pathname, int pathlen, * then our prefix match is all we need; we * do not need to call fnmatch at all. */ - if (!patternlen && !namelen) + if (!patternlen && (!namelen || (flags & PATTERN_FLAG_MUSTBEDIR))) return 1; } From patchwork Tue Aug 24 21:54:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BA48C4338F for ; Tue, 24 Aug 2021 21:54:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 391BF613BD for ; Tue, 24 Aug 2021 21:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238565AbhHXVzl (ORCPT ); Tue, 24 Aug 2021 17:55:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238047AbhHXVzf (ORCPT ); Tue, 24 Aug 2021 17:55:35 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C46C1C0613CF for ; Tue, 24 Aug 2021 14:54:50 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso2860379wmb.2 for ; Tue, 24 Aug 2021 14:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=tDlSdtwCo5GDTbGHI77FRDcgSn8sGkTpZaUHwlUFMDM=; b=jKv0sm+H0f1tCULN/YSduVXFQVdePE6VBhz/sbaZxCi3rLcv1qm3S7xxn+CJDzvH/3 mlIb99chdoNXnR+djqCm6P6LIczC2Jvaxg1ZAM1TvCxEp8ohD73MTLEzVnnf+epPvv7e GYs4H1jbxk0++10XqAcPzDd1W/4T7BYkrCDxfrDXE3xEPykdiuWEQ2+FCYHknVwuQ7tM fZqdZypi4pL9WWIyypVjX4ni0GnhutNVa74zY4JabXgGtoXt3uwBgs7Km5RN3APG8pSc k2IHcEd78z2HxtgAXVhmwKndrw2Wl2EwTEAmd08iinXXNTTt83iWTsycLsKtlrrIRGVe ZM1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=tDlSdtwCo5GDTbGHI77FRDcgSn8sGkTpZaUHwlUFMDM=; b=ZYAArCyV8AT2Pitt8x8S+IMYkQRVLJE9PKDLryCpnVuw338CPzxGJ/lIO0w0FpNhAv APbO3m4DAe349Qk8c0VV2S5L6j5jqPrNFWLkl/bYSdleFRRKUcpUT4JbORWMBnKxB8fD iPPj57pF/Iu5mkTWbh1sR+gGovOpONlGmlsi0noHXH3d5rtcrqCiOi1R+udT0FoqNq09 WAgPzSgrnYu/hONUBTfdmH74P1NNr7XMMw8wPrvrlfWHF5e2h3n6vMRfNzi/utNpcWBY wGXbTcNfuja+O1AtBxdC+4IkD7IeSOdVtY5ThDjppJfuAhbI4jOM6KmHWwuVkrLLEfIQ l68g== X-Gm-Message-State: AOAM530fHeuD/O0w9JCJBZe1nNJwNiiL6xlEE5sCN6AQRSwSQeWkL9Vn ivNOSyDbGjZxb4AU0cRvgQE/QR+JDfs= X-Google-Smtp-Source: ABdhPJwIrwPY+Pjobw17VaIyHod9rWSmgN968lgPLvAy/DXBUeU06Nmvqa3haTRYPxz7/DacU7evdw== X-Received: by 2002:a1c:7ece:: with SMTP id z197mr5818235wmc.141.1629842089367; Tue, 24 Aug 2021 14:54:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m7sm3340448wmq.29.2021.08.24.14.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:49 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:37 +0000 Subject: [PATCH 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, 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 sprase-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 | 33 +++++++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 88a6c0c69fb..3a109276b74 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 only_match_skip_worktree = 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(&only_match_skip_worktree, + 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 (only_match_skip_worktree.nr) { + advise_on_updating_sparse_paths(&only_match_skip_worktree); + exit_status = 1; + } + + string_list_clear(&only_match_skip_worktree, 0); + return exit_status; } diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 23bee918260..962bece03e1 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -291,8 +291,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 && @@ -300,7 +298,7 @@ test_expect_success 'add outside sparse cone' ' run_on_sparse ../edit-contents folder1/a && run_on_sparse ../edit-contents folder1/newfile && test_sparse_match test_must_fail git add folder1/a && - test_sparse_match git add folder1/newfile + test_sparse_match test_must_fail git add folder1/newfile ' test_expect_success 'commit including unstaged changes' ' @@ -331,7 +329,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 @@ -352,10 +354,9 @@ test_expect_success 'status/add: outside sparse cone' ' # Adding the path outside of the sparse-checkout cone should fail. test_sparse_match test_must_fail git add folder1/a && test_sparse_match test_must_fail git add --refresh folder1/a && + test_sparse_match test_must_fail git add 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 && @@ -511,7 +512,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 && @@ -525,12 +526,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 && @@ -539,7 +546,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 @@ -556,11 +563,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 && @@ -638,6 +651,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 && @@ -647,6 +661,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 Tue Aug 24 21:54:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4658EC432BE for ; Tue, 24 Aug 2021 21:55:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AB7E613CD for ; Tue, 24 Aug 2021 21:55:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238593AbhHXVzm (ORCPT ); Tue, 24 Aug 2021 17:55:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238063AbhHXVzg (ORCPT ); Tue, 24 Aug 2021 17:55:36 -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 3D197C0613D9 for ; Tue, 24 Aug 2021 14:54:51 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id e5so16784887wrp.8 for ; Tue, 24 Aug 2021 14:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=8dFQrDagHAvPHfySdjImTPILlQLOjQlQyL3J8ZnSfx4=; b=kSt4uSr8O1NIeyzMuCqJnmbLtJdPp8P5oVbBaOtk0Z2f89wdcxQGpqPgEUtwXGg8P3 mZOsBl44rLTo2qmOJO4j4g+5f5ThX6A7zBJ9LI9QxjAh4Hwxqck0CzWaYOqd3qqzPe/n Z6HxldZaQuNdpSJhoH0LqoGbQ2C5cEvmPufaXd/Qtx2DwJORjFNlJaj/rFnVHsemK37B 79NK5YsAJJoMfxUAuCMgWH9kmtYmcoVzccPkb/ZrKbiKwAI1U7QOoALUnc9fkp5FBcd1 yRegcU1xsOWbA41LYGNzIcrZ0q6iszsy+F7253T/K97SRZeV8OJ3Sm5e45ZWxksewRwu J9rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=8dFQrDagHAvPHfySdjImTPILlQLOjQlQyL3J8ZnSfx4=; b=qDXgYceiqWvNeoGKaEdeK2QOyX2XAL7Xr6ZjU2+quRPoXBOCahH4LxEpPiHZpCTA5Q a65/t9vr4rJQ8DDoHJhK0auBaT9gJxC5XbF2e62rX+3ve0x0SQFCPyWtGpfgA8Rtt2E/ RWRSgg+vkRQtJxIEkyJHSxZaTlRj3/RuGACYy9WB3HPM2UkbhTcbzvwkSTa2y9KdGe0z 0KF3FTuC191aV42biVT0Qaaodte+wm9VKoG5ritMMaSTWGo7IausTlsenbXoDrgyXQzU Ll13qCmbKPCdUEK0DGFzWCZokZnpgzmQW3F0/tLC75JXv+IqVvWfMHbZS5Uczy2+BiNA Uodw== X-Gm-Message-State: AOAM530UxYiw2KETKS4FnYSHTJuGda3cc+ogizHDdlxUTscgXr4v6akZ S5mt4lQz+l57haevEy5xZg6/Fiwq7tE= X-Google-Smtp-Source: ABdhPJyvMhtTz3P/5281FkAIUFh/LBsKef+ioCvc7FgIk2NGVNwDCizHiS34lEH8bqwrtreNjZPtpw== X-Received: by 2002:a5d:4d8e:: with SMTP id b14mr21325368wru.422.1629842089931; Tue, 24 Aug 2021 14:54:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o12sm1345866wro.51.2021.08.24.14.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:49 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:38 +0000 Subject: [PATCH 06/13] add: skip paths that are 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, 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 pathes 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 Signed-off-by: Derrick Stolee --- pathspec.c | 3 ++- t/t1092-sparse-checkout-compatibility.sh | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pathspec.c b/pathspec.c index 44306fdaca2..0e6e60fdc5a 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); } diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 962bece03e1..c2a4eec548d 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -529,7 +529,7 @@ test_expect_failure 'merge with conflict outside cone' ' # NEEDSWORK: Even though the merge conflict removed the # SKIP_WORKTREE bit from the index entry for folder1/a, we should # warn that this is a problematic add. - test_all_match git add folder1/a && + test_sparse_match test_must_fail git add folder1/a && test_all_match git status --porcelain=v2 && # 3. Rename the file to another sparse filename and @@ -538,7 +538,7 @@ test_expect_failure 'merge with conflict outside cone' ' # NEEDSWORK: This mode now fails, because folder2/z is # outside of the sparse-checkout cone and does not match an # existing index entry with the SKIP_WORKTREE bit cleared. - test_all_match git add folder2 && + test_sparse_match test_must_fail git add folder2 && test_all_match git status --porcelain=v2 && test_all_match git merge --continue && @@ -566,7 +566,7 @@ test_expect_failure 'cherry-pick/rebase with conflict outside cone' ' # NEEDSWORK: Even though the merge conflict removed the # SKIP_WORKTREE bit from the index entry for folder1/a, we should # warn that this is a problematic add. - test_all_match git add folder1/a && + test_sparse_match test_must_fail git add folder1/a && test_all_match git status --porcelain=v2 && # 3. Rename the file to another sparse filename and @@ -575,7 +575,7 @@ test_expect_failure 'cherry-pick/rebase with conflict outside cone' ' # outside of the sparse-checkout cone and does not match an # existing index entry with the SKIP_WORKTREE bit cleared. run_on_all mv folder2/a folder2/z && - test_all_match git add folder2 && + test_sparse_match test_must_fail git add folder2 && test_all_match git status --porcelain=v2 && test_all_match git $OPERATION --continue && From patchwork Tue Aug 24 21:54:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1233C4320E for ; Tue, 24 Aug 2021 21:55:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DCE3B613D2 for ; Tue, 24 Aug 2021 21:55:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238595AbhHXVzo (ORCPT ); Tue, 24 Aug 2021 17:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238290AbhHXVzg (ORCPT ); Tue, 24 Aug 2021 17:55:36 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D602BC061764 for ; Tue, 24 Aug 2021 14:54:51 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id n5so21000184wro.12 for ; Tue, 24 Aug 2021 14:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=j4VGYWR9mA/cViJvu3yL7KCsiqk2cVMZlAu7B3NC73M=; b=ceHEL7cc1JVxvf/oGxCfD+KB9U10wVFBAv1LA2R7qSCxVGl/kdijIss5Wh4XIMRr4Q omG/5fwmBo9olilvWfNPgm+JGvA8AbEDxIyx0RcLHrfoVBkUa8S3j1FpbsIe6bkgGmpW LMLULKalpf1LJpKR+cBkCznTz3+ekn344wP4kczAl4cg9Jl5j60hhhIAPxXokqqk1qAc BexPIj9ToldZ3FGNtLLJxzEeFMrF4so0dsxlIhdBZ2LGvGDcPYU0tQBe0uovgCS+XT5A Z4BI4BKWoSMN5UchmwYqr5BUz5dtGW+O0OV3rdfnPiAz1cAb3mTlwaLv1CgdAWgBWzyK yTaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=j4VGYWR9mA/cViJvu3yL7KCsiqk2cVMZlAu7B3NC73M=; b=fLEQYkiX7fpUIPVYEFTHbVTsnPUtXqlPhyUdl1Ob9b73UMMyXhPKSyRGyI3yMyTvrL CmatKoQOvIIBbfZcDllQnbbnbgTRX21OTrXFVohXkW4euC61HndUWiFSo2L2AwSGL443 snNrvX9r6gah3hiucyEp8XiNbMDetLa6iDPa1k6uMvJ1s8iNs1K7KiKChTsEBwIFlZ50 OOuiTGD1LsbmN0DOW9HSP9nFgW353xW4Wh+zN5anLpDRm7HEk4a3IPZ65kMu3miCWLOv 0ELss6q55d7Eqri7r3BMrQIce4P9E2hObCZIM78PM9tekhG05vnRYHsd407r9uJTDcQ7 NoPg== X-Gm-Message-State: AOAM531/aP7wCDVJ+XEe22d8j0/HQoysOZ8KVbB+JB9kH8wM6ZJx5QET AlCIob4j2Rk/gl2wXTIVZ8+SJoZErpY= X-Google-Smtp-Source: ABdhPJwxLZSYdhhvBHWKWrC7zDM9FJm2XOs6ylQThTCZ1TKwwpxO8N1v64WaIHyWRJt4QfxKbZU2JA== X-Received: by 2002:adf:df08:: with SMTP id y8mr21841130wrl.124.1629842090514; Tue, 24 Aug 2021 14:54:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z11sm2646958wrw.53.2021.08.24.14.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:50 -0700 (PDT) Message-Id: <6edadbc2000bd6d2ec76cbeff08b309ae4928b37.1629842085.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:39 +0000 Subject: [PATCH 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, 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 | 10 ++++++--- t/t1092-sparse-checkout-compatibility.sh | 28 ++++++++---------------- t/t3705-add-sparse-checkout.sh | 8 +++++++ 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index be5e3ac54b8..bb79016d2ca 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -9,7 +9,7 @@ SYNOPSIS -------- [verse] 'git add' [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p] - [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]] + [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]] [--sparse] [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--renormalize] [--chmod=(+|-)x] [--pathspec-from-file= [--pathspec-file-nul]] [--] [...] @@ -79,6 +79,13 @@ in linkgit:gitglossary[7]. --force:: Allow adding otherwise ignored files. +--sparse:: + Allow updating index entries outside of the sparse-checkout cone. + Normally, `git add` refuses to update index entries whose paths do + not fit within the sparse-checkout cone, since those files might + be removed from the working tree without warning. See + linkgit:git-sparse-checkout[1] for more. + -i:: --interactive:: Add modified contents in the working tree interactively to diff --git a/builtin/add.c b/builtin/add.c index 3a109276b74..68f2de80594 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)) @@ -379,6 +380,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, @@ -457,7 +459,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(&only_match_skip_worktree, dir->entries[i]->name); continue; @@ -642,7 +645,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 c2a4eec548d..1e7799fd76a 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -329,11 +329,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 @@ -355,15 +351,16 @@ test_expect_failure 'status/add: outside sparse cone' ' test_sparse_match test_must_fail git add folder1/a && test_sparse_match test_must_fail git add --refresh folder1/a && test_sparse_match test_must_fail git add 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} @@ -507,12 +504,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 && @@ -528,17 +520,15 @@ test_expect_failure 'merge with conflict outside cone' ' # 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_sparse_match test_must_fail git add folder1/a && + # warn that this is a problematic add when --sparse is not set. + 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 && + test_all_match git add --sparse folder2 && test_all_match git status --porcelain=v2 && test_all_match git merge --continue && diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 2b1fd0d0eef..99c27dd9fb7 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -152,4 +152,12 @@ 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 && + git add --sparse sparse_entry 2>stderr && + test_must_be_empty stderr +' + test_done From patchwork Tue Aug 24 21:54:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BBDCC43214 for ; Tue, 24 Aug 2021 21:55:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F19E8613B1 for ; Tue, 24 Aug 2021 21:55:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238609AbhHXVzp (ORCPT ); Tue, 24 Aug 2021 17:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238427AbhHXVzh (ORCPT ); Tue, 24 Aug 2021 17:55:37 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EBCEC0613D9 for ; Tue, 24 Aug 2021 14:54:52 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id d26so13020504wrc.0 for ; Tue, 24 Aug 2021 14:54:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=6HCoPYtcBbJ9xM1NNoK+33bRxbv+GCQNtrBdX/Nmx8k=; b=ULe7DZQ1WUZG2X60LzZ0S7qrA7d6kKENVz0AISfXe7KJ/wFDSDt1WXWP+gV5fR+Pxp G2qQF8Qhx9iHgmzixcQwR4MQe8QKvCHkxShNxfaemAm5F/HA4R2jLGKMq1csVIHHpUiV ultYPffxv3oYRj8fchjcFJvFlEjvHj1YyNi2Iz8eEYgqMW1WkMxTwQQXHO0YuXhE27C0 9IxwNzhlyAlEEiuweboHFnbQJB1aWo5Jpm6Z1uesbLPlXThqz7WNyCJUwMJaS3K9S8Cy ECxzMX9T1E+e6Im/mtN/J88UFykVhVjDVU7wPASfLSi3Zbf9123oumev0qm5N1+drfYp PoAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=6HCoPYtcBbJ9xM1NNoK+33bRxbv+GCQNtrBdX/Nmx8k=; b=DJLcmPYmgsNLQ8IjWYhYBMGso+B39MQqL0vvMAs79ufUXpbnnPLKmPDW4PBSfQbmWy cJsoat2a4vN3HTgtgbXjykdRz9gsLPXBC2ZNEgdzIm0cy7mMMssJWiWNBeaOfmHGQInO 9nA352ynaLOLVFSmkofntYkvLw5KjAaPRGM1twla4E2wCP+9Lu/73aBgaerzgGB0PNbp f0HPO/dVED2D8VInHYtr3xm2lVG1rQNptr1+9EDFISJQ8x7Fg6XQ6otdyu3YfnTtAyXQ ahzFogb3Zo/Z6YTqCBGZu7neDU73XiVbiWWs0Ge0z9gR9KKUAVfXdL3B0GRfN0hp5qX1 N+Aw== X-Gm-Message-State: AOAM532DASz/1dnGnNkrv2mIj6gcOd/7whvmnPP4r9BCzfQk9LtqYe1s XA4/Lt+5BV3Wyj0cMOv6v1nooUXxCiE= X-Google-Smtp-Source: ABdhPJwLG3/LbR4E1t9iPApbpI6EOGLYu2U0rAez5SYmqtLJcpYmneD1ZX2v0UA9nwJ8HTQU8NZ/Tw== X-Received: by 2002:adf:e68e:: with SMTP id r14mr21817125wrm.395.1629842091072; Tue, 24 Aug 2021 14:54:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b4sm18621530wro.97.2021.08.24.14.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:50 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:40 +0000 Subject: [PATCH 08/13] add: prevent adding sparse conflict 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, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When a merge results in a conflict outside of the sparse-checkout cone, the conflicted file is written to the working tree and the index entry loses the SKIP_WORKTREE bit. This allows users to add the file to the index without realizing that the file might leave the working tree in a later Git command. Block this behavior, but keep in mind that the user can override the failure using the '--sparse' option. Signed-off-by: Derrick Stolee --- pathspec.c | 2 +- t/t1091-sparse-checkout-builtin.sh | 4 +++- t/t1092-sparse-checkout-compatibility.sh | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pathspec.c b/pathspec.c index 0e6e60fdc5a..ddeeba79114 100644 --- a/pathspec.c +++ b/pathspec.c @@ -71,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 e0f31186d89..b6efdb3c52f 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 1e7799fd76a..65998e664a9 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -518,9 +518,8 @@ 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 when --sparse is not set. + test_sparse_match test_must_fail git add folder1/a && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && test_all_match git add --sparse folder1/a && test_all_match git status --porcelain=v2 && @@ -528,6 +527,7 @@ test_expect_success 'merge with conflict outside cone' ' # accept conflict markers as resolved content. run_on_all mv folder2/a folder2/z && test_sparse_match test_must_fail git add folder2 && + test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err && test_all_match git add --sparse folder2 && test_all_match git status --porcelain=v2 && From patchwork Tue Aug 24 21:54:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57F8AC4320A for ; Tue, 24 Aug 2021 21:55:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C6E06138B for ; Tue, 24 Aug 2021 21:55:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238658AbhHXVzq (ORCPT ); Tue, 24 Aug 2021 17:55:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238439AbhHXVzh (ORCPT ); Tue, 24 Aug 2021 17:55:37 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03AF5C061796 for ; Tue, 24 Aug 2021 14:54:53 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id x2-20020a1c7c02000000b002e6f1f69a1eso2853468wmc.5 for ; Tue, 24 Aug 2021 14:54:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=t4xYg8Az3c2cCDTZ+0YQBXjHrqNP5wx73T5m00T4gv8=; b=bK3fBCyxi37RVtWCjuXR2J69OAloWQOSZhi5tBX1K2Z6QgStlpZ9tz32jL9VyW5mnZ NqO9iwFsRRmaFtRWgP2sJZdCKTQHyQyr+mykify7q0I61f4bpXusyekHa7aCHVzp4F8R dg7pkDkqYRJw3noZHk38jfJzgLLGOF/IBVNN/KuKzRr8bW8Q7LVcD/R1Cv739rac1bLh qSviBYjwykW11qW5UDzr7RZNZ991IIA7ujpsbL/J27jmuaGoZJkQP1/SVvvvbBUWjilc kdGtY0WA+pD2pXU7UIFMhty30O5PrwUhxyoT4KszhD2V+zhK1qDy0c+mnM7s1fhOhjNH khOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=t4xYg8Az3c2cCDTZ+0YQBXjHrqNP5wx73T5m00T4gv8=; b=rwLGY/zeE0Yew4Wq6iqmzP+WvIfYMhVTa161nRjS2EHjXCveq7Oyv0JpUeZsvpxLuU 3WKHJz7HVzLbCepp1YJuCAlrfgP1YCOD3Dzn9fKnuIku1VSGsniNi6AM+8fQnPrVd4GC QZoLSfLNcfY6EFbX5/E5oN6ZJDRYrUdD1og1g1T6OENLWgfOHhuHZkOZgGI8E3XA89Sj +3k9RxQGfBbRdEWtE82G38tlUdZCX5eZIpmGVIeudsT2sh72sJtBjEkmhdTrKL8LjbXC j3nqAKYhyUR+jI2vWcpGAPO/+JB5D/Jl0wQHtkuBMI/FCRNjF3AZbnLrc+5SSV5kMenb JbKA== X-Gm-Message-State: AOAM5313YPz6u4XEey8eFMgDfK6Ml3kb2CvwOJ/ECmA2/BIrygC/hBww BUu+X3+YgakNpdTqYTuFf8absKe8e/0= X-Google-Smtp-Source: ABdhPJzfBXv6O/GwhVgKZhFNkBc0yj5A4kJW1MCThcfLKwQLF8pBdkimKphIQzOg4cknN9tU94H76w== X-Received: by 2002:a1c:80c3:: with SMTP id b186mr5747527wmd.105.1629842091680; Tue, 24 Aug 2021 14:54:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n15sm3140214wmq.7.2021.08.24.14.54.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:51 -0700 (PDT) Message-Id: <6c9c986ff43fe7f065c27e61468534007e70d2a7.1629842085.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:41 +0000 Subject: [PATCH 09/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, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Signed-off-by: Derrick Stolee --- Documentation/git-rm.txt | 6 ++++++ builtin/rm.c | 8 ++++++-- t/t3602-rm-sparse-checkout.sh | 14 +++++++++++++- 3 files changed, 25 insertions(+), 3 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..a34b978bfd8 100755 --- a/t/t3602-rm-sparse-checkout.sh +++ b/t/t3602-rm-sparse-checkout.sh @@ -36,13 +36,25 @@ done test_expect_success 'recursive rm does not remove sparse entries' ' git reset --hard && - git sparse-checkout set sub/dir && + git sparse-checkout set sub/dir/ && git rm -r sub && git status --porcelain -uno >actual && echo "D sub/dir/e" >expected && 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 Tue Aug 24 21:54:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5513C43216 for ; Tue, 24 Aug 2021 21:55:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE203613BD for ; Tue, 24 Aug 2021 21:55:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238710AbhHXVzr (ORCPT ); Tue, 24 Aug 2021 17:55:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238474AbhHXVzi (ORCPT ); Tue, 24 Aug 2021 17:55:38 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E4BCC061757 for ; Tue, 24 Aug 2021 14:54:53 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id e5so16784962wrp.8 for ; Tue, 24 Aug 2021 14:54:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=IqUFbOHd+GmBlHz4kSGwrATqMDgKd8EWpt8BWJr4eEU=; b=gykNgV4UbRLPTnukdlQf53eLAmD6nW/FA82FWC9uPlNk7sTITXgPmk3VNApgwOnn1k Vww6PnXqFR7TNqDAv1PpE39Fs2P2QqUB+U7Nx/m5mHRx6IrI4pEO3uLPFbFGWQGYoajF rA8wQ/eb7Y5vLCeihFyTlXSZCEAiZ42wttJtVOvVUMaESWqLoM1jOWdlsmeNSjKwq8/Z LNPBw4c7Ohxfmb4cLmmweNemvJYi2zeHG+AkLcwsmk3mtY2RbI/pHnZWxkIDqhwCOS9r oJlGDoKK66U6U1nTtwcFxLE3yTUKpPDeAFfwZK1D5jbE0nyHQBKH5VBB28mOs3k3YOmF uX8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=IqUFbOHd+GmBlHz4kSGwrATqMDgKd8EWpt8BWJr4eEU=; b=k3rucJJY0P+Ob5H4To/yBkQavkA04fu8h92Z9F5iIcROmJcUKQF+Dk93oMEJv4vq9p 7nUSn4SxNa5/RcoouW6I0EtX45GpYxygKrpDgS671T+GzAPmpLUgSonYo/iF2AIt48i3 R1gYaYtrqijwSkFv4WeVjmyeUcojUEm/Qf0HHQ3tfp8l1PTnrm6evXzCjwlZvo5aUKJg 6VncHvhFeEAthxw/XV6UITyfoVHw/0mP957SL8Ylq+sdmUTqm7pto88QvZWwERVkL+7n AMk7SKDTo1Vkmxuhiddyv9U6yJPLvtR7Da+S4ReagYZr5V3spA2ohXvIYKUx2t1yaPiC DMMg== X-Gm-Message-State: AOAM5306j3njikoD7Os9QSzk9n8dkXtnBHYsbtVEJLqLoUvp1TWSij9n eHTM3ynOFNoXgROsqGD/pmxbqEYYwHY= X-Google-Smtp-Source: ABdhPJzXOi0FxnCcKKGSkx+1FfEqqpBGgC5jUnrPYy8vOMup8EVU5qraCDWO0vhRCP9DYQFnfUY2cw== X-Received: by 2002:adf:f3c4:: with SMTP id g4mr1471078wrp.409.1629842092211; Tue, 24 Aug 2021 14:54:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q9sm3831657wrs.3.2021.08.24.14.54.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:51 -0700 (PDT) Message-Id: <5153accded46c8ced8784ec135dbc77d5bc1a306.1629842085.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:42 +0000 Subject: [PATCH 10/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, 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. Signed-off-by: Derrick Stolee --- builtin/rm.c | 4 +++- t/t3602-rm-sparse-checkout.sh | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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 a34b978bfd8..44f3e923164 100755 --- a/t/t3602-rm-sparse-checkout.sh +++ b/t/t3602-rm-sparse-checkout.sh @@ -87,4 +87,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 Tue Aug 24 21:54:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455991 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F14EFC4338F for ; Tue, 24 Aug 2021 21:55:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD0456138B for ; Tue, 24 Aug 2021 21:55:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235603AbhHXVzt (ORCPT ); Tue, 24 Aug 2021 17:55:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238094AbhHXVzi (ORCPT ); Tue, 24 Aug 2021 17:55:38 -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 1E0BEC06179A for ; Tue, 24 Aug 2021 14:54:54 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id q11so6408146wrr.9 for ; Tue, 24 Aug 2021 14:54:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=SRL4Mqvbh7uOsuJTajy9S2zELRleSoolNi7hNuwdKlU=; b=LJnOvO3eVPCvMTgmr8jgKUHIaCnRvV90js3FKCIGhWB0Od9l5S3l1VcojvJHpQ16gb K9lMV3qq1qbv4qyDafttezcxRPfh/clAGNgpTpprW+y6shsyi9bkRJHNmTnFYvdAhEVk 8I8gDjYECpypTRd1QTRMkM3OhSQw/IEBNlub/g1zGK9JJt4L/RXW5EP/bKfI8CXBoMX9 0nH/1Y7qaJCJrgUucbSbJONTEZuZhAwrJU0i8tikOkvFkIlI8Xebacz7LRkHGV7ro/Lu 6UKE1ggevwTAlb9kV8TCNGEFHLDhMOWyMtzcmfDLi5CeLMfuaqZlA8xYlgOk7YEJIrw2 sIjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=SRL4Mqvbh7uOsuJTajy9S2zELRleSoolNi7hNuwdKlU=; b=GWMB+olticXi74g+h9T2nII06rlBdq8I/ZeK3SxGm8GTttRus97UMzkd3reEZF0KeL tevSqB5+U6BYp2t2xv0WJZzOR4/OIBbn2i4pT4P1jVrO0kcPylVRbd2hGcmCQGqOJZN0 Nnp9qxtjypZ8vSXLLeOMzJ7qs9JpWHvAzh0EtKNidNZ6GzUewyz3HUieQeVgNI+qP76W aQUcIids9qncEbJVd0fP0zlPEfnIuc+LsSZ/YO0AgsypfW3WefVmFxx7ie5gxBzWXex/ GT04Pjt3BrntwKtKGqD3oEfVuhESBNH4/vKtenk6gPR3u3Dse9u0BcUT1irD/FpG9e7N JI8A== X-Gm-Message-State: AOAM530gSGjHSse2F1JB8txuNk02dmYAIWUQMKBb8wfqDzCcOpbgosGd FgQgrR7DciAQchSu2VJexfNUETn/+AQ= X-Google-Smtp-Source: ABdhPJx1zm9o4AXJ+phAFrTCB4iTIJhgcXiePJ2sQDVK8h5z/AbqIN/ZRsgezYvAOaZTufOW+STDjw== X-Received: by 2002:a5d:4c89:: with SMTP id z9mr11072106wrs.290.1629842092806; Tue, 24 Aug 2021 14:54:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o17sm3260856wmp.13.2021.08.24.14.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:52 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:43 +0000 Subject: [PATCH 11/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, 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. Signed-off-by: Derrick Stolee --- builtin/mv.c | 19 +++++++ t/t7002-mv-sparse-checkout.sh | 99 +++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100755 t/t7002-mv-sparse-checkout.sh diff --git a/builtin/mv.c b/builtin/mv.c index c2f96c8e895..b58fd4ce5ba 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -133,6 +133,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) 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,10 +177,22 @@ 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); + if (!path_in_sparse_checkout(src, &the_index)) { + string_list_append(&only_match_skip_worktree, src); + skip_sparse = 1; + } + if (!path_in_sparse_checkout(dst, &the_index)) { + string_list_append(&only_match_skip_worktree, dst); + skip_sparse = 1; + } + if (skip_sparse) + continue; + length = strlen(src); if (lstat(src, &st) < 0) bad = _("bad source"); @@ -266,6 +279,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]; diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh new file mode 100755 index 00000000000..5397c6d07bd --- /dev/null +++ b/t/t7002-mv-sparse-checkout.sh @@ -0,0 +1,99 @@ +#!/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' ' + 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 +' + +test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' ' + rm -f e && + git reset --hard && + git sparse-checkout set a && + touch b && + git mv -k b e 2>stderr && + cat sparse_error_header >expect && + echo b >>expect && + echo e >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr +' + +test_expect_success 'mv refuses to move non-sparse-to-sparse' ' + rm -f e && + git reset --hard && + git sparse-checkout set a && + test_must_fail git mv a e 2>stderr && + cat sparse_error_header >expect && + echo e >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr +' + +test_expect_success 'mv refuses to move sparse-to-non-sparse' ' + rm -f e && + git reset --hard && + git sparse-checkout set a e && + 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 +' + +test_expect_success 'recursive mv refuses to move (possible) sparse' ' + rm -f e && + git reset --hard && + # Without cone mode, "sub" and "sub2" do not match + git sparse-checkout set sub/dir sub2/dir && + test_must_fail git mv sub sub2 2>stderr && + cat sparse_error_header >expect && + echo sub >>expect && + echo sub2 >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr +' + +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 && + test_must_fail git mv sub sub2 2>stderr && + cat sparse_error_header >expect && + echo sub/dir2/e >>expect && + echo sub2/dir2/e >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr +' + +test_done From patchwork Tue Aug 24 21:54:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8580C4320A for ; Tue, 24 Aug 2021 21:55:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF7886138B for ; Tue, 24 Aug 2021 21:55:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238596AbhHXVzw (ORCPT ); Tue, 24 Aug 2021 17:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238339AbhHXVzj (ORCPT ); Tue, 24 Aug 2021 17:55:39 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2DA6C0613C1 for ; Tue, 24 Aug 2021 14:54:54 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id k20-20020a05600c0b5400b002e87ad6956eso1566962wmr.1 for ; Tue, 24 Aug 2021 14:54:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=36kJNonbXo/64agdD8fpLIv3/3HvGVknzEl/5at4bAs=; b=P7GKIkG3/cpja8upecmM3h9/zKGOJnolktDrvkimLQ76w/VfnCbcC1as9rMcz0jGiB rndF5cU2/Xy/Fb5iZZnVNmGsLGNyTfl+ZJt0SZCmAWhZMccpHQ4oZQ4WkoQyiOJ2uZap pIK8BXYyw49MhV18XBfHNyn3Z5OUFtZl7hOfmKwE/xFZZ8G4ppiazoQTVP6G5PQ6S1PR VqXnlla6ElHfBjy2qREFbLz55YvnwOPwENxfW0m+rD6CEGG78EffuOXvJOzHOm4tuV+f CeSA/pFwyZxuYPBVGVD1tW6Qp5Roy3cW8881gn0kLh54eFfPVorJxkvJVWEGsRTSjxRl 6KGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=36kJNonbXo/64agdD8fpLIv3/3HvGVknzEl/5at4bAs=; b=NCi0YLADhfC/7qOYeRnMMGj6BqUlk7/p+8JMPaw5QVHe55Di5M/nT8zczTUcpnej0s 1wKVkXNnQrtBFhmNb9umVy9Zx0ihE9rWoVNW/+MyHPIzWaxTCrpkSa3Wp5aqgGWcguSR k96GV8NjOf/8vPzaCfu75gGpE6fmQTYyV6dqO1nEXckSAfVNPzIjMzrqcyWHD/JivsrO mVCZE/7R50AAX7uMwwHSuBiwOXxL9TlhWYUmJQyQn1olLoJCDYqOeD/UOdXFY7miSOB7 9NBmQ9GX493MKViNIn67ki5ZUYFfQb9bka4T/DPUgTQjRuJLqoxBeJgqJFjdcFTvJrpB FJ8A== X-Gm-Message-State: AOAM533IALXduO8LqitEBSkpUFi42lvmSGyxAXCvMsuAl6oOYKa4M08+ I167Vw8DUjp/fnCCkjl+/XrUDykcviE= X-Google-Smtp-Source: ABdhPJxT6SujB94TmJcv8LYuaO/Kzj9cSi43n5QpI9De/1w/Wc7q/7sHK+z+dOkG/nwdcI9NVUFoEg== X-Received: by 2002:a05:600c:4304:: with SMTP id p4mr5064806wme.18.1629842093424; Tue, 24 Aug 2021 14:54:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c25sm3453512wmr.15.2021.08.24.14.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:53 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:44 +0000 Subject: [PATCH 12/13] mv: add '--sparse' option to ignore sparse-checkout 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, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Users can get into strange situations if 'git mv' allows moving files into, out of, or around the sparse-checkout cone. However, some users may still want to do it. Allow knowledgeable users to do so via a new '--sparse' option. There are some special cases that occur in this change, such as the case of a directory that doesn't match the sparse-checkout cone, but exists in the working tree because a subset of its contents do match. We need to communicate that index entries with the SKIP_WORKTREE bit are not expected to be in the working directory and hence are not needed when moving the contents. This is only a check for the existence of the source file. The call to rename_cache_entry_at() still changes the index appropriately in these cases. Signed-off-by: Derrick Stolee --- builtin/mv.c | 24 ++++++++++++++---------- t/t7002-mv-sparse-checkout.sh | 34 ++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/builtin/mv.c b/builtin/mv.c index b58fd4ce5ba..92ea9f0ca37 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -118,17 +118,18 @@ 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; @@ -182,11 +183,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (show_only) printf(_("Checking rename of '%s' to '%s'\n"), src, dst); - if (!path_in_sparse_checkout(src, &the_index)) { + if (!ignore_sparse && !path_in_sparse_checkout(src, &the_index)) { string_list_append(&only_match_skip_worktree, src); skip_sparse = 1; } - if (!path_in_sparse_checkout(dst, &the_index)) { + if (!ignore_sparse && !path_in_sparse_checkout(dst, &the_index)) { string_list_append(&only_match_skip_worktree, dst); skip_sparse = 1; } @@ -194,9 +195,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix) continue; 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)) @@ -225,11 +228,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; @@ -293,7 +297,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 index 5397c6d07bd..517fd587fa8 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -31,7 +31,9 @@ test_expect_success 'mv refuses to move sparse-to-sparse' ' echo b >>expect && echo e >>expect && cat sparse_hint >>expect && - test_cmp expect stderr + 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' ' @@ -44,7 +46,9 @@ test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' ' echo b >>expect && echo e >>expect && cat sparse_hint >>expect && - test_cmp expect stderr + test_cmp expect stderr && + git mv --sparse -k b e 2>stderr && + test_must_be_empty stderr ' test_expect_success 'mv refuses to move non-sparse-to-sparse' ' @@ -55,7 +59,9 @@ test_expect_success 'mv refuses to move non-sparse-to-sparse' ' cat sparse_error_header >expect && echo e >>expect && cat sparse_hint >>expect && - test_cmp expect stderr + test_cmp expect stderr && + git mv --sparse a e 2>stderr && + test_must_be_empty stderr ' test_expect_success 'mv refuses to move sparse-to-non-sparse' ' @@ -67,7 +73,9 @@ test_expect_success 'mv refuses to move sparse-to-non-sparse' ' cat sparse_error_header >expect && echo b >>expect && cat sparse_hint >>expect && - test_cmp expect stderr + 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' ' @@ -80,7 +88,14 @@ test_expect_success 'recursive mv refuses to move (possible) sparse' ' echo sub >>expect && echo sub2 >>expect && cat sparse_hint >>expect && - test_cmp expect stderr + 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' ' @@ -93,7 +108,14 @@ test_expect_success 'recursive mv refuses to move sparse' ' echo sub/dir2/e >>expect && echo sub2/dir2/e >>expect && cat sparse_hint >>expect && - test_cmp expect stderr + 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 Tue Aug 24 21:54:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12455995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0735C4338F for ; Tue, 24 Aug 2021 21:55:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91EE9613CD for ; Tue, 24 Aug 2021 21:55:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238740AbhHXVzx (ORCPT ); Tue, 24 Aug 2021 17:55:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238501AbhHXVzk (ORCPT ); Tue, 24 Aug 2021 17:55:40 -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 69D76C061796 for ; Tue, 24 Aug 2021 14:54:55 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id n5so21000321wro.12 for ; Tue, 24 Aug 2021 14:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=zu1GxVrVYR7vuo/zV/03WGPmO61qj4th90I6raORv0Q=; b=TZfbA5Y47VLqgSHVjnD11hGdQAGrUicBjiUSTo0q26M3nBUYTVIPSRvwv72EsVrr1E HLNtPBLPtdY42iRo1t2RPBgLNJK7JNXKpWbE8O3IjMmwptWOyfuc7OdINVMgioS4QWok OQNuFYV5Hmlmeh+q4y8/AwzEoPLEJ8U2Xz0/3dHVwL9FJVbdnfDSleAMy3l8/lY4h2WX jEqGp8e1sniJLujArAYXlcwfEYsbZKKOnZrWhT1O9Izjwcb3OjalTdvmInFOeVC9iS7D 7f0GZk1OOF2m712eRdgrJHh0y37ZwLs3hzk+sx/mNMy4iNjG0jE14pH8M06zbqBfu3Kq YIyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=zu1GxVrVYR7vuo/zV/03WGPmO61qj4th90I6raORv0Q=; b=lPfcMhm2vYAcTr1bMYoNdPpFuDo4ZZ5K8ZrN8Hy2fB0tctdsrm0XsxDDNTBda7IMyP I2/f0LDPH+N4rP8t02bd9QLOKGnUksqsFRvrkPrShC51ws+LbHKEDLu0XNX95+6/LEDX /ECQoxI/mGCDhGKPFXznhi38gUsHoytwUvFTtRCiibg8YIAbD+86voFYKlYN6oo9GWDy YEVoFwz4gBgTNel5uep931eUiR6usU4pt5zD1D3MZxg4UEpY3c1USPbkxKCYPvc9hezJ FyZKg83A/eEG3aqO863F8YyLBIxAn/xHZTOHHcJOhfw1qDz+4EeqrM1MCPl0QPBTG6mA 42ww== X-Gm-Message-State: AOAM530xAN6JzjMcC3L4zGGRpKfhqnbfgBY3eFMq4q8OKBHU5zTfX6oc caL+BQpjxpFCzxQshpKuiL+y/0CEipE= X-Google-Smtp-Source: ABdhPJwnFZWT9NDxAPc6B2H6vQzow3Iu7bXemmRXAMqSH+1xIzUCTV++6++8miyExElNVZQsUiTI3A== X-Received: by 2002:a5d:534e:: with SMTP id t14mr21766741wrv.109.1629842094049; Tue, 24 Aug 2021 14:54:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c7sm3222142wmq.13.2021.08.24.14.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 14:54:53 -0700 (PDT) Message-Id: <7749a69a38faeceadc7a8735fb3d0edd359c954c.1629842085.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Aug 2021 21:54:45 +0000 Subject: [PATCH 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, 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. Signed-off-by: Derrick Stolee --- advice.c | 3 ++- t/t3602-rm-sparse-checkout.sh | 2 +- t/t3705-add-sparse-checkout.sh | 2 +- t/t7002-mv-sparse-checkout.sh | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/advice.c b/advice.c index 0b9c89c48ab..695693e5fa8 100644 --- a/advice.c +++ b/advice.c @@ -300,7 +300,8 @@ void advise_on_updating_sparse_paths(struct string_list *pathspec_list) fprintf(stderr, "%s\n", item->string); advise_if_enabled(ADVICE_UPDATE_SPARSE_PATH, - _("Disable or modify the sparsity rules if you intend" + _("Disable or modify the sparsity rules or" + " use the --sparse option if you intend" " to update such entries.")); } diff --git a/t/t3602-rm-sparse-checkout.sh b/t/t3602-rm-sparse-checkout.sh index 44f3e923164..22170feef62 100755 --- a/t/t3602-rm-sparse-checkout.sh +++ b/t/t3602-rm-sparse-checkout.sh @@ -16,7 +16,7 @@ test_expect_success 'setup' " EOF cat >sparse_hint <<-EOF && - hint: Disable or modify the sparsity rules if you intend to update such entries. + hint: Disable or modify the sparsity rules or use the --sparse option if you intend to update such entries. hint: Disable this message with \"git config advice.updateSparsePath false\" EOF diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 99c27dd9fb7..0a8071370d3 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -43,7 +43,7 @@ test_expect_success 'setup' " EOF cat >sparse_hint <<-EOF && - hint: Disable or modify the sparsity rules if you intend to update such entries. + hint: Disable or modify the sparsity rules or use the --sparse option if you intend to update such entries. hint: Disable this message with \"git config advice.updateSparsePath false\" EOF diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index 517fd587fa8..b6e9ea0b2c8 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -16,7 +16,7 @@ test_expect_success 'setup' " EOF cat >sparse_hint <<-EOF - hint: Disable or modify the sparsity rules if you intend to update such entries. + hint: Disable or modify the sparsity rules or use the --sparse option if you intend to update such entries. hint: Disable this message with \"git config advice.updateSparsePath false\" EOF "