From patchwork Wed Feb 17 21:02:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 12092343 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 02C10C433E0 for ; Wed, 17 Feb 2021 21:03:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCC3E64E79 for ; Wed, 17 Feb 2021 21:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232770AbhBQVD0 (ORCPT ); Wed, 17 Feb 2021 16:03:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbhBQVDU (ORCPT ); Wed, 17 Feb 2021 16:03:20 -0500 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE593C061756 for ; Wed, 17 Feb 2021 13:02:40 -0800 (PST) Received: by mail-qk1-x736.google.com with SMTP id x14so58094qkm.2 for ; Wed, 17 Feb 2021 13:02:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XlKzLEa7xdFWXMBcMcWaeCRbNT3v20gR1UMHkOSLheI=; b=DPCOb/cc/DuG3SSMzJFZm7FdhbIlwgfOixBuX24EnEm7MZMJOz4s4GTmFMB65qbndm czuxboRn9AyDHZCvLHlVJxQbrCwAHGQJOvfdlTF/QOSGf9oTgbpm5G5DJEBGzXjZL0JX +P/q4rtlVfXp8Mo6q5N6nO38d8+KkJ6bxYy51lo/WVYQFr9IEi6mfbz0uEbuq/hOEVby PY83FkpfLmpkBAdUctpvdkzHAcACRewp7z6KeEqxXKunmR2YogQNn9ipZ4Nmu6Qjd1Nc t5lFp9Moc3wIyCYO6itM9DIFLSbbhe07+XuUh4M8okbx9aOokNC0Hu3ISFHLB+IHLhbh fOmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XlKzLEa7xdFWXMBcMcWaeCRbNT3v20gR1UMHkOSLheI=; b=kHyYOWiE974AP+2CcyBZKRw9dE61nVUz5vu8XnlixoSEKCCLMp538F7JOb5B1BGxcZ V3fCQ5ej/+40B4ousqc41QVaKpO0z+ujFo2eWRuy93hzVylPYZjG7+dQ5m5R5R0nQvSG wOmhfd+4gVdulexY2dl/6Mwkvf/0BOBa4D1nXKKRdd0/tZjYgSYGgieRaXmLil4MGl8/ PFF6AEcLB7Bi9bws4cklR8j7u31xD7OHP+syPIP8c2V9ElUzJ/9iGLDQN0JYIedjtll+ NFLxdgQcJu7jr9yryjQMyYE6+H4ZeHuObiGgrX7HivP/hpY6iVeVzI0dpttV7H9s0FSj kzrQ== X-Gm-Message-State: AOAM532nrc2r4LG3iJBmjYVNyc0zhTOYo3b6u2PNwXAxGfZ0/x1Vdsge kSsn0xjnSu51DqU3nD6E+/cig4XCrC9M/A== X-Google-Smtp-Source: ABdhPJxIEK/x90QVW6H1HBBknqwYuH91ZM/pPxzup6UAtSzbtDx1wGLi1WcWAnZ7oIgzvHSLj2IKIQ== X-Received: by 2002:a05:620a:1354:: with SMTP id c20mr1161741qkl.104.1613595759604; Wed, 17 Feb 2021 13:02:39 -0800 (PST) Received: from mango.meuintelbras.local ([177.32.118.149]) by smtp.gmail.com with ESMTPSA id o194sm2438459qke.101.2021.02.17.13.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 13:02:39 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: newren@gmail.com, stolee@gmail.com Subject: [RFC PATCH 1/7] add --chmod: don't update index when --dry-run is used Date: Wed, 17 Feb 2021 18:02:24 -0300 Message-Id: <2256132f9de01cc06a001aa8c44e29dc5a218441.1613593946.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org `git add --chmod` applies the mode changes even when `--dry-run` is used. Fix that and add some tests for this option combination. Signed-off-by: Matheus Tavares --- builtin/add.c | 7 ++++--- t/t3700-add.sh | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index a825887c50..f757de45ea 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -38,7 +38,7 @@ struct update_callback_data { int add_errors; }; -static void chmod_pathspec(struct pathspec *pathspec, char flip) +static void chmod_pathspec(struct pathspec *pathspec, char flip, int show_only) { int i; @@ -48,7 +48,8 @@ static void chmod_pathspec(struct pathspec *pathspec, char flip) if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL)) continue; - if (chmod_cache_entry(ce, flip) < 0) + if ((show_only && !S_ISREG(ce->ce_mode)) || + (!show_only && chmod_cache_entry(ce, flip) < 0)) fprintf(stderr, "cannot chmod %cx '%s'\n", flip, ce->name); } } @@ -609,7 +610,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) exit_status |= add_files(&dir, flags); if (chmod_arg && pathspec.nr) - chmod_pathspec(&pathspec, chmod_arg[0]); + chmod_pathspec(&pathspec, chmod_arg[0], show_only); unplug_bulk_checkin(); finish: diff --git a/t/t3700-add.sh b/t/t3700-add.sh index b7d4ba608c..fc81f2ef00 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -386,6 +386,26 @@ test_expect_success POSIXPERM 'git add --chmod=[+-]x does not change the working ! test -x foo4 ' +test_expect_success 'git add --chmod honors --dry-run' ' + git reset --hard && + echo foo >foo4 && + git add foo4 && + git add --chmod=+x --dry-run foo4 && + test_mode_in_index 100644 foo4 +' + +test_expect_success 'git add --chmod --dry-run reports error for non regular files' ' + git reset --hard && + test_ln_s_add foo foo4 && + git add --chmod=+x --dry-run foo4 2>stderr && + grep "cannot chmod +x .foo4." stderr +' + +test_expect_success 'git add --chmod --dry-run reports error for unmatched pathspec' ' + test_must_fail git add --chmod=+x --dry-run nonexistent 2>stderr && + test_i18ngrep "pathspec .nonexistent. did not match any files" stderr +' + test_expect_success 'no file status change if no pathspec is given' ' >foo5 && >foo6 && From patchwork Wed Feb 17 21:02:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 12092345 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 D6314C433E0 for ; Wed, 17 Feb 2021 21:03:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE66864E79 for ; Wed, 17 Feb 2021 21:03:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234427AbhBQVDb (ORCPT ); Wed, 17 Feb 2021 16:03:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231613AbhBQVDW (ORCPT ); Wed, 17 Feb 2021 16:03:22 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9275CC0613D6 for ; Wed, 17 Feb 2021 13:02:42 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id m144so1828qke.10 for ; Wed, 17 Feb 2021 13:02:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BRAlg9W+JJ1LhRAgwzyAQsmT2K2M8iAlrnhIQ/u/Ysg=; b=DPHUKTypQ1GP1zs+NNzYXupdLBUBwJKDwi5HiDr2mJtGWADYxleXN1+7CNxxrBkIg8 6nxw+Gfe/BgpNzA8n1i6JOctkn1eSZR2y0zyJ1dzJDQZ9oXjVgPhoxOm4zzEnT/xE/R+ RBgw9Y9vqJ7qwMkYwObrZwvGp+RHMkqeJEktgrrZ1Mh75HFcZnPsDO9CoJDppvUU+8P/ N6mDXp8kT6+r6SwAhAXo5Q6vJZRSYC/dYaCmvIYVeXY8h17YXhl7KJfmUy0SK3atsSRN D9U2gjH+a8y0ZIr7KsY1hA6Iv0H9eUOjRIll9y6ybAx+/yGyLXr2o37WyoicO57c2fX+ nKUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BRAlg9W+JJ1LhRAgwzyAQsmT2K2M8iAlrnhIQ/u/Ysg=; b=ECnf75z2yChXb5nTcdArmKj8rSPbNo35XmwFeBCQoJc8h+ns0tiYxUxsktU2e6BReW Y0F5xy+yuBIQRbROKr/QaRv02/r3QMBtp0wp/N/ZxCB8DAT+srH73W1qIAy5J3raEGnB kFMQ4hAuOkBd//lrNY5VY4RTavBYtP3FV1QTLakFgRHUS0Z8lbADahne5KOb1A9oMWaL nqLU7NzBIiAwmjfRuY/CO5sO7k0DXLZ54/b6Zais1mwB8hY51hs45IFiMNdd5BWfUHuP NacLTteXLUvTIZtJlrwJImUb6ZYctyo7u5cxI1q0gGEtNsAXHhYRBM3K7/SHXeKY6ia9 JJmg== X-Gm-Message-State: AOAM532RM1NqoXz1aBAu4MgOe+l0ryer10P10A43I/eaNqC25nXURoxp Cl8xuxE13n/fNTrzMBTNfPvlThiAt0aByQ== X-Google-Smtp-Source: ABdhPJxSaVu1I8DXdI7dwLxe34NlF2N7eju5VJvWx9/NzSilk9cr44sykW2U77hy1Yj28iX4N4qvXg== X-Received: by 2002:a37:434c:: with SMTP id q73mr1208687qka.170.1613595761461; Wed, 17 Feb 2021 13:02:41 -0800 (PST) Received: from mango.meuintelbras.local ([177.32.118.149]) by smtp.gmail.com with ESMTPSA id o194sm2438459qke.101.2021.02.17.13.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 13:02:41 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: newren@gmail.com, stolee@gmail.com Subject: [RFC PATCH 2/7] add: include magic part of pathspec on --refresh error Date: Wed, 17 Feb 2021 18:02:25 -0300 Message-Id: <970b7156c2697e65778ec85751733a3adc53c1be.1613593946.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When `git add --refresh ` doesn't find any matches for the given pathspec, it prints an error message using the `match` field of the `struct pathspec_item`. However, this field doesn't contain the magic part of the pathspec. Instead, let's use the `original` field. Signed-off-by: Matheus Tavares --- builtin/add.c | 2 +- t/t3700-add.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/builtin/add.c b/builtin/add.c index f757de45ea..8c96c23778 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -180,7 +180,7 @@ static void refresh(int verbose, const struct pathspec *pathspec) for (i = 0; i < pathspec->nr; i++) { if (!seen[i]) die(_("pathspec '%s' did not match any files"), - pathspec->items[i].match); + pathspec->items[i].original); } free(seen); } diff --git a/t/t3700-add.sh b/t/t3700-add.sh index fc81f2ef00..fe72204066 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -196,6 +196,12 @@ test_expect_success 'git add --refresh with pathspec' ' grep baz actual ' +test_expect_success 'git add --refresh correctly reports no match error' " + echo \"fatal: pathspec ':(icase)nonexistent' did not match any files\" >expect && + test_must_fail git add --refresh ':(icase)nonexistent' 2>actual && + test_i18ncmp expect actual +" + test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unreadable file' ' git reset --hard && date >foo1 && From patchwork Wed Feb 17 21:02:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 12092347 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 DB350C433E0 for ; Wed, 17 Feb 2021 21:03:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B433364E6C for ; Wed, 17 Feb 2021 21:03:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234684AbhBQVDj (ORCPT ); Wed, 17 Feb 2021 16:03:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232521AbhBQVDZ (ORCPT ); Wed, 17 Feb 2021 16:03:25 -0500 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7522BC061786 for ; Wed, 17 Feb 2021 13:02:45 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id c1so10671631qtc.1 for ; Wed, 17 Feb 2021 13:02:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K+OJz8Iv5iYp8p/t2dzMNItfqnDP61/r9KGhG/p85xQ=; b=D1Fne5lraj1+ZrCMUMNEaFAMbh15qdn+0s00cAxtM5vGKxpurq/+3Ozgo915I1nHjX 4pixQh+qkXRmjn3RA4nW6tsaOH8A6lBZATW225MEnR3iGoeO2e+Bw6bxpCa5InnRoYMM cOrS2Xtw4m3Bd4a8zEzgYtv/SXyzzs5XfS5e+5yrPPe3UbfRYDkhOVPz1eeC6PVgHH0W pe01RVdyX2OGU3M6+HjYP8mxeYONH/qNMfzEjHBXTvjIuDp3OnpoIt6leJdanRblfU3O FcXD0CtXVplfiUYvgxvpdpCUaj6Yk5xZmBRDGR4Zr8fRE7Imk85szuBfGi4bpuW/s0Xt kcqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K+OJz8Iv5iYp8p/t2dzMNItfqnDP61/r9KGhG/p85xQ=; b=L069neHz54J3Eqd8DCXDwNgU/wM3t4CYs88jZ24Z+b2KQRX3wl5TuIGzqgvmAjebsk HxfZdLh7tmOh9V7ALjYnONOpol6MqNLqIBLeDSGPWfybwlYC2lpE3JiCIspPvFV9V3SW JgEBI3boo+6jbFTzaI25fFOjem0h2yeQSA+sqVriyymq5KDk4yCtxysBWwy3rQhonWfd bYjZ1YPEfzG6wW9oAukesZwtIE9pstXjCAZk3ckNAN7KFHUDH/czi3K23GcOpbBnqVqR EXBV6V0JNoIW3TfOSL9ZX1wX8LHADZjqOrwwhkIu4emv2S3XezbWQSa60bEGxi2HkBFd 5QoA== X-Gm-Message-State: AOAM533jRhWPMVqhLOsc26RgJ1FKRDXTD2O1KXx913dWg2KOSe8gu95g OH/FiEGp+cbpdukyE1li9gwJDqZiXYdRLg== X-Google-Smtp-Source: ABdhPJxPx43F0RU2rUKUv0QUl1U3b8Y9evBdjJRZond3zeaRb/zA147qRaGQvTQt0dNBP/kFlGe5sQ== X-Received: by 2002:ac8:110d:: with SMTP id c13mr1116980qtj.361.1613595763317; Wed, 17 Feb 2021 13:02:43 -0800 (PST) Received: from mango.meuintelbras.local ([177.32.118.149]) by smtp.gmail.com with ESMTPSA id o194sm2438459qke.101.2021.02.17.13.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 13:02:42 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: newren@gmail.com, stolee@gmail.com Subject: [RFC PATCH 3/7] t3705: add tests for `git add` in sparse checkouts Date: Wed, 17 Feb 2021 18:02:26 -0300 Message-Id: <6e30f133e234ff1d3a29f36423cd3fdca58d8095.1613593946.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We already have a couple tests for `add` with SKIP_WORKTREE entries in t7012, but these only cover the most basic scenarios. As we will be changing how `add` deals with sparse paths in the subsequent commits, let's move these two tests to their own file and add more test cases for different `add` options and situations. This also demonstrates two options that don't currently respect SKIP_WORKTREE entries: `--chmod` and `--renormalize`. Signed-off-by: Matheus Tavares --- t/t3705-add-sparse-checkout.sh | 92 ++++++++++++++++++++++++++++++++ t/t7012-skip-worktree-writing.sh | 19 ------- 2 files changed, 92 insertions(+), 19 deletions(-) create mode 100755 t/t3705-add-sparse-checkout.sh diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh new file mode 100755 index 0000000000..5530e796b5 --- /dev/null +++ b/t/t3705-add-sparse-checkout.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +test_description='git add in sparse checked out working trees' + +. ./test-lib.sh + +SPARSE_ENTRY_BLOB="" + +# Optionally take a string for the entry's contents +setup_sparse_entry() +{ + if test -f sparse_entry + then + rm sparse_entry + fi && + git update-index --force-remove sparse_entry && + + if test "$#" -eq 1 + then + printf "$1" >sparse_entry + else + printf "" >sparse_entry + fi && + git add sparse_entry && + git update-index --skip-worktree sparse_entry && + SPARSE_ENTRY_BLOB=$(git rev-parse :sparse_entry) +} + +test_sparse_entry_unchanged() { + echo "100644 $SPARSE_ENTRY_BLOB 0 sparse_entry" >expected && + git ls-files --stage sparse_entry >actual && + test_cmp expected actual +} + +test_expect_success "git add does not remove SKIP_WORKTREE entries" ' + setup_sparse_entry && + rm sparse_entry && + git add sparse_entry && + test_sparse_entry_unchanged +' + +test_expect_success "git add -A does not remove SKIP_WORKTREE entries" ' + setup_sparse_entry && + rm sparse_entry && + git add -A && + test_sparse_entry_unchanged +' + +for opt in "" -f -u --ignore-removal +do + if test -n "$opt" + then + opt=" $opt" + fi + + test_expect_success "git add$opt does not update SKIP_WORKTREE entries" ' + setup_sparse_entry && + echo modified >sparse_entry && + git add $opt sparse_entry && + test_sparse_entry_unchanged + ' +done + +test_expect_success 'git add --refresh does not update SKIP_WORKTREE entries' ' + setup_sparse_entry && + test-tool chmtime -60 sparse_entry && + git add --refresh sparse_entry && + + # We must unset the SKIP_WORKTREE bit, otherwise + # git diff-files would skip examining the file + git update-index --no-skip-worktree sparse_entry && + + echo sparse_entry >expected && + git diff-files --name-only sparse_entry >actual && + test_cmp actual expected +' + +test_expect_failure 'git add --chmod does not update SKIP_WORKTREE entries' ' + setup_sparse_entry && + git add --chmod=+x sparse_entry && + test_sparse_entry_unchanged +' + +test_expect_failure 'git add --renormalize does not update SKIP_WORKTREE entries' ' + test_config core.autocrlf false && + setup_sparse_entry "LINEONE\r\nLINETWO\r\n" && + echo "sparse_entry text=auto" >.gitattributes && + git add --renormalize sparse_entry && + test_sparse_entry_unchanged +' + +test_done diff --git a/t/t7012-skip-worktree-writing.sh b/t/t7012-skip-worktree-writing.sh index e5c6a038fb..217207c1ce 100755 --- a/t/t7012-skip-worktree-writing.sh +++ b/t/t7012-skip-worktree-writing.sh @@ -60,13 +60,6 @@ setup_absent() { git update-index --skip-worktree 1 } -test_absent() { - echo "100644 $EMPTY_BLOB 0 1" > expected && - git ls-files --stage 1 > result && - test_cmp expected result && - test ! -f 1 -} - setup_dirty() { git update-index --force-remove 1 && echo dirty > 1 && @@ -100,18 +93,6 @@ test_expect_success 'index setup' ' test_cmp expected result ' -test_expect_success 'git-add ignores worktree content' ' - setup_absent && - git add 1 && - test_absent -' - -test_expect_success 'git-add ignores worktree content' ' - setup_dirty && - git add 1 && - test_dirty -' - test_expect_success 'git-rm fails if worktree is dirty' ' setup_dirty && test_must_fail git rm 1 && From patchwork Wed Feb 17 21:02:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 12092349 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 53692C433DB for ; Wed, 17 Feb 2021 21:03:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 300E864E79 for ; Wed, 17 Feb 2021 21:03:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234686AbhBQVDp (ORCPT ); Wed, 17 Feb 2021 16:03:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232915AbhBQVD0 (ORCPT ); Wed, 17 Feb 2021 16:03:26 -0500 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 507DDC061788 for ; Wed, 17 Feb 2021 13:02:46 -0800 (PST) Received: by mail-qt1-x82d.google.com with SMTP id g24so8128704qts.2 for ; Wed, 17 Feb 2021 13:02:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eO79hD/COpmgZFAlN7t0LKYqs92Cya1RLIEpXJaXkQY=; b=x4PYUvFIKZuFWKlVNNN4e1A8AlEbvuMi4v9RBV+lTZke1kvALWhMkjQIpYj7pO+m8s Mtl6FUS9T88FmJdROesQkf6Z2hGf9xk38V7qUKmWZY2A+fAUR0gFE4ZNDZO/vvki3Ss9 a7QlJm2Ueuc5sLIH5813P97cE659XCbQvEjtCU0HMbJ1ipUEa5xG4m1F7q1VUNUi3xVq jgw0c8FSUffSIixQmZ7lM8h3p1yHcTDExgfgSAv3MBotpzil4UpCrYNd0Zz4E0KHjkuD 7JCmg4x6x4Deo0XRH/Z5RGOGMfSX+VicJf4PdI++iKt/49FwllE6ayuRgAJaFd9NsD9g te7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eO79hD/COpmgZFAlN7t0LKYqs92Cya1RLIEpXJaXkQY=; b=kgJaQtRxVYk0YfK+4ExbskAVQIwcfyjTBwhXle2L0RN+04goCAEqhSiujyDmzLNNNO +y5udOKF+YAudx1+8wefOVpz8RiZOk4XM3TAtyTmzmKtYezkjgq5Fx7lU1zu6NiPUuRR cuziZehsmC+Rzwky20qd69LQlgMIiVNeG1guLJT7JtIfEU/bzEtykmW13Y3NnuSBi3DW 4YLLWpmEaEVi5k5+1eVdCkFueOJ2YJOPzKIkRRefNwYdWPeClbLMx8gMsf5IIXwXNdL8 u3+UKpHRu3UrLC3xQzAcTQ9SEJHmcThn+gFbePpmOk61CH1fkDvWC1XF19qV5ggokDY7 FNbQ== X-Gm-Message-State: AOAM533zWDB+CFUyVvyicEhky71pRmSp76qVFjCm+h+BeFFpeCVF0AW6 sWeA2Hbp/fUQA+W40nZIcub966KB6S0uQA== X-Google-Smtp-Source: ABdhPJxHXJNDcJZ75o9blggdfMkNVTOwXcdmFZMHwYE1o/kKga8eIKLu9fFNgiSwwr4Al0tiMafxAg== X-Received: by 2002:ac8:710d:: with SMTP id z13mr1146042qto.165.1613595765183; Wed, 17 Feb 2021 13:02:45 -0800 (PST) Received: from mango.meuintelbras.local ([177.32.118.149]) by smtp.gmail.com with ESMTPSA id o194sm2438459qke.101.2021.02.17.13.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 13:02:44 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: newren@gmail.com, stolee@gmail.com Subject: [RFC PATCH 4/7] add: make --chmod and --renormalize honor sparse checkouts Date: Wed, 17 Feb 2021 18:02:27 -0300 Message-Id: X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Matheus Tavares --- builtin/add.c | 5 +++++ t/t3705-add-sparse-checkout.sh | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 8c96c23778..e10a039070 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -45,6 +45,9 @@ static void chmod_pathspec(struct pathspec *pathspec, char flip, int show_only) for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; + if (ce_skip_worktree(ce)) + continue; + if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL)) continue; @@ -137,6 +140,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags) for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; + if (ce_skip_worktree(ce)) + continue; if (ce_stage(ce)) continue; /* do not touch unmerged paths */ if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode)) diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 5530e796b5..f7b0ea782e 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -75,13 +75,13 @@ test_expect_success 'git add --refresh does not update SKIP_WORKTREE entries' ' test_cmp actual expected ' -test_expect_failure 'git add --chmod does not update SKIP_WORKTREE entries' ' +test_expect_success 'git add --chmod does not update SKIP_WORKTREE entries' ' setup_sparse_entry && git add --chmod=+x sparse_entry && test_sparse_entry_unchanged ' -test_expect_failure 'git add --renormalize does not update SKIP_WORKTREE entries' ' +test_expect_success 'git add --renormalize does not update SKIP_WORKTREE entries' ' test_config core.autocrlf false && setup_sparse_entry "LINEONE\r\nLINETWO\r\n" && echo "sparse_entry text=auto" >.gitattributes && From patchwork Wed Feb 17 21:02:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 12092351 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=-15.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT 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 056FDC433DB for ; Wed, 17 Feb 2021 21:04:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C288B64E79 for ; Wed, 17 Feb 2021 21:04:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234712AbhBQVE0 (ORCPT ); Wed, 17 Feb 2021 16:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231487AbhBQVEB (ORCPT ); Wed, 17 Feb 2021 16:04:01 -0500 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67034C06178A for ; Wed, 17 Feb 2021 13:02:48 -0800 (PST) Received: by mail-qk1-x734.google.com with SMTP id t62so25231qke.7 for ; Wed, 17 Feb 2021 13:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zq+Yi2HL4q2Lmum2IocGaq5/oM1Ro8YZzxVQXhldSNc=; b=xS46RDtulNOLKxcPdkwgFN7ukFuGIGPRV6T0lXuIkICbaeHJHfKvyPRJrsjH4q12Bf x/HDzMp9a4m35QcNZav9BCjghO4z5aSsoZLhJBwGlQXE53kURr66APmmmi+ijwkP3qT4 o2222v4NHWT8PaFeanKTgbpmUpn/ZpAV2Ak0ucusPJ4kfozyoA9Iicgvdhi7q8GHNUA3 FqQMl9UaXwic7n9mdkJOnDT202JY6xnoqtk9o36Ig6jFUqHjWq7sqy7lZkvDzi+R2maT ukWw7p5N7EBaVImjqUcXF4w2QmxH3KR9xuWxEAzI6+uV//DNxdNq2d5sj9yOSg0hkzp/ 90pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zq+Yi2HL4q2Lmum2IocGaq5/oM1Ro8YZzxVQXhldSNc=; b=ql3od24aqXM+Xh7IKa+/bK5dIPuTIBj8f0WMTEot8tplNttPhOCi0uYV+gVViWwjND UHyvXa+T+VlBHVLZy0/5kr1Ft1zXdpjo8BuEAkKWO8Ccr2j6a2eJB9ijzGogQykufxZ4 8QGHSOskLsXwv99o8amMkjr6Jo5EZHQVxnFbTUO4yjLR66Sp9TRp+tqTTZXQZeEIbsBg PG5E5eEql8HrNlm34gT+zHsvgaqF7pFJ/IlncaSMGXYLRatad5v9T4ltVcEFI1BpnIQY 5uLdzMzRY5cT3C/rdlvBx3hDc1JJxrVAdtR/auJhsva/aRLEiqA9uJEPa+ZszFyv3cDe MQsQ== X-Gm-Message-State: AOAM531faN3GBssz7Au7a8T/faUST8thdnhlgwnNvNg0w+8UuKfqeD7a KZso7WE24sRk3V9AI9xvmc50LxqCokeaAg== X-Google-Smtp-Source: ABdhPJxU3I2tnpohHfoomEAUBjmBWEJWeP1kJ+SZJ9D3+0Pk9NjaaZ/zJgQWHMclrB5brIH9tj34Hg== X-Received: by 2002:a37:4a56:: with SMTP id x83mr1136972qka.205.1613595767210; Wed, 17 Feb 2021 13:02:47 -0800 (PST) Received: from mango.meuintelbras.local ([177.32.118.149]) by smtp.gmail.com with ESMTPSA id o194sm2438459qke.101.2021.02.17.13.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 13:02:46 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: newren@gmail.com, stolee@gmail.com Subject: [RFC PATCH 5/7] pathspec: allow to ignore SKIP_WORKTREE entries on index matching Date: Wed, 17 Feb 2021 18:02:28 -0300 Message-Id: <82a3b4247a3635ebef4bb7c5e13f93e71147a98a.1613593946.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add the 'ignore_skip_worktree' boolean parameter to both add_pathspec_matches_against_index() and find_pathspecs_matching_against_index(). When true, these functions will not try to match the given pathspec with SKIP_WORKTREE entries. This will be used in a future patch to make `git add` display a hint when the pathspec matches only sparse paths. Signed-off-by: Matheus Tavares --- builtin/add.c | 4 ++-- builtin/check-ignore.c | 2 +- pathspec.c | 10 +++++++--- pathspec.h | 5 +++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index e10a039070..9f0f6ebaff 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -170,7 +170,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, *dst++ = entry; } dir->nr = dst - dir->entries; - add_pathspec_matches_against_index(pathspec, &the_index, seen); + add_pathspec_matches_against_index(pathspec, &the_index, seen, 0); return seen; } @@ -571,7 +571,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) int i; if (!seen) - seen = find_pathspecs_matching_against_index(&pathspec, &the_index); + seen = find_pathspecs_matching_against_index(&pathspec, &the_index, 0); /* * file_exists() assumes exact match diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 3c652748d5..235b7fc905 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -100,7 +100,7 @@ static int check_ignore(struct dir_struct *dir, * should not be ignored, in order to be consistent with * 'git status', 'git add' etc. */ - seen = find_pathspecs_matching_against_index(&pathspec, &the_index); + seen = find_pathspecs_matching_against_index(&pathspec, &the_index, 0); for (i = 0; i < pathspec.nr; i++) { full_path = pathspec.items[i].match; pattern = NULL; diff --git a/pathspec.c b/pathspec.c index 7a229d8d22..e5e6b7458d 100644 --- a/pathspec.c +++ b/pathspec.c @@ -21,7 +21,7 @@ */ void add_pathspec_matches_against_index(const struct pathspec *pathspec, const struct index_state *istate, - char *seen) + char *seen, int ignore_skip_worktree) { int num_unmatched = 0, i; @@ -38,6 +38,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 (ignore_skip_worktree && ce_skip_worktree(ce)) + continue; ce_path_match(istate, ce, pathspec, seen); } } @@ -51,10 +53,12 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec, * given pathspecs achieves against all items in the index. */ char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, - const struct index_state *istate) + const struct index_state *istate, + int ignore_skip_worktree) { char *seen = xcalloc(pathspec->nr, 1); - add_pathspec_matches_against_index(pathspec, istate, seen); + add_pathspec_matches_against_index(pathspec, istate, seen, + ignore_skip_worktree); return seen; } diff --git a/pathspec.h b/pathspec.h index 454ce364fa..8202882ecd 100644 --- a/pathspec.h +++ b/pathspec.h @@ -151,9 +151,10 @@ static inline int ps_strcmp(const struct pathspec_item *item, void add_pathspec_matches_against_index(const struct pathspec *pathspec, const struct index_state *istate, - char *seen); + char *seen, int ignore_skip_worktree); char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, - const struct index_state *istate); + const struct index_state *istate, + int ignore_skip_worktree); int match_pathspec_attrs(const struct index_state *istate, const char *name, int namelen, const struct pathspec_item *item); From patchwork Wed Feb 17 21:02:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 12092353 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 080F6C433E0 for ; Wed, 17 Feb 2021 21:04:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A62A964E6C for ; Wed, 17 Feb 2021 21:04:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232785AbhBQVEk (ORCPT ); Wed, 17 Feb 2021 16:04:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233311AbhBQVEB (ORCPT ); Wed, 17 Feb 2021 16:04:01 -0500 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF651C06178B for ; Wed, 17 Feb 2021 13:02:50 -0800 (PST) Received: by mail-qt1-x832.google.com with SMTP id o21so10647376qtr.3 for ; Wed, 17 Feb 2021 13:02:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rTFJ70JTy4mtEe2oYpH5DrjWnZPMuMmeBWJI1tKb/h4=; b=RXTzKd8iVy8YUNfKL1YbZdUGVl1XlAoLYrtcLZcuur18Muf6/tIKd+20mvBXS1etAH mKZC/e6BaEbxB5Vs/KXKLaHux0fPYf+Wl77UbWPuZMS2oxAuFHOwFs3uVfXHBU33hJU1 OGDo2FwlawVTI7cLMWQ701mjegfN2JDXc7abT+Al0uRewVk8BNOymBPv0WDh1JQCMBp2 JC8tRkaAF6JHQl26d3d72LGK7mJEYWyFd4PdkPycMVvgnDpFuj36JDyO1OrjdN7pR9IL b6iTThFTtfu3OSB45FsMRwq9Zmt1MqHMZs9N6yOpLqCUGv+5QWToPf7G7d7THWpzpEXG DBaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rTFJ70JTy4mtEe2oYpH5DrjWnZPMuMmeBWJI1tKb/h4=; b=r9S28F4NNxVRWsNdNX4YUARTREl6FmirW7yEukCBvERQ1an+effGbGA5uQDSBn0xE1 q+3qEaU5AGDVwQZSZuMfWTuF8wn6eOZXzz1iYrON2ANKL1M1RhftaB+CwnV+kky3ad+O ZxxhW1l+MvOPqRos6VbQGHkRzLiMO+FOPE/NsfDcRHgb2U0YsgRssMmIOd+Yhw/Js9mN AUUJDCqPlKH5mEScvssTbW0ES+QYTEdYJrEGVQWsqfeW+arxYrOE+O/tUTr4X4jKlBIN amrJbIz/+pXXlPDp0PYH2D67L4Ud4OFiaVxhoE59YXZtB5qoI3PZSyrcc0E0vZ82ad1g 8X2g== X-Gm-Message-State: AOAM530nfDACvdgxrelq5Tt2gHzmOjwgGzpnU3tXUeF25mDeJWwBpu7p QHHTURNSxdHlSsJGe2tcGgFVO+d0lDyC7Q== X-Google-Smtp-Source: ABdhPJzeKZzuS/UtyexWlc4EbAcsOfdA4WLANlV/69Fnqy9McdPbBXusTd8PvUkO5BW97RcW2NSBjA== X-Received: by 2002:ac8:5ad4:: with SMTP id d20mr1210803qtd.224.1613595769123; Wed, 17 Feb 2021 13:02:49 -0800 (PST) Received: from mango.meuintelbras.local ([177.32.118.149]) by smtp.gmail.com with ESMTPSA id o194sm2438459qke.101.2021.02.17.13.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 13:02:48 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: newren@gmail.com, stolee@gmail.com Subject: [RFC PATCH 6/7] add: warn when pathspec only matches SKIP_WORKTREE entries Date: Wed, 17 Feb 2021 18:02:29 -0300 Message-Id: <8f1bc014ae8a34c0bc43d1a2b8c0ebdbe7e47e02.1613593946.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org `git add` already refrains from updating SKIP_WORKTREE entries, but it silently succeeds when a pathspec only matches these entries. Instead, let's warn the user and display a hint on how to update these entries. Note that the warning is only shown if the pathspec matches no untracked paths in the working tree and only matches index entries with the SKIP_WORKTREE bit set. Performance-wise, this patch doesn't change the number of ce_path_match() calls in the worst case scenario (because we still need to check the sparse entries for the warning). But in the general case, it avoids unnecessarily calling this function for each SKIP_WORKTREE entry. A warning message was chosen over erroring out right away to reproduce the same behavior `add` already exhibits with ignored files. This also allow users to continue their workflow without having to invoke `add` again with only the matching pathspecs, as the matched files will have already been added. Note: refresh_index() was changed to only mark matches with no-SKIP-WORKTREE entries in the `seen` output parameter. This is exactly the behavior we want for `add`, and only `add` calls this function with a non-NULL `seen` pointer. So the change brings no side effect on other callers. Signed-off-by: Matheus Tavares --- Documentation/config/advice.txt | 3 ++ advice.c | 19 +++++++++++ advice.h | 4 +++ builtin/add.c | 60 ++++++++++++++++++++++++++------- pathspec.c | 15 +++++++++ pathspec.h | 8 +++++ read-cache.c | 3 +- t/t3705-add-sparse-checkout.sh | 40 +++++++++++++++++++--- 8 files changed, 134 insertions(+), 18 deletions(-) diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt index acbd0c09aa..d53eafa00b 100644 --- a/Documentation/config/advice.txt +++ b/Documentation/config/advice.txt @@ -119,4 +119,7 @@ advice.*:: addEmptyPathspec:: Advice shown if a user runs the add command without providing the pathspec parameter. + updateSparsePath:: + Advice shown if the pathspec given to linkgit:git-add[1] only + matches index entries outside the current sparse-checkout. -- diff --git a/advice.c b/advice.c index 164742305f..cf22c1a6e5 100644 --- a/advice.c +++ b/advice.c @@ -2,6 +2,7 @@ #include "config.h" #include "color.h" #include "help.h" +#include "string-list.h" int advice_fetch_show_forced_updates = 1; int advice_push_update_rejected = 1; @@ -136,6 +137,7 @@ static struct { [ADVICE_STATUS_HINTS] = { "statusHints", 1 }, [ADVICE_STATUS_U_OPTION] = { "statusUoption", 1 }, [ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie", 1 }, + [ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath", 1 }, [ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor", 1 }, }; @@ -284,6 +286,23 @@ void NORETURN die_conclude_merge(void) die(_("Exiting because of unfinished merge.")); } +void advise_on_updating_sparse_paths(struct string_list *pathspec_list) +{ + struct string_list_item *item; + + if (!pathspec_list->nr) + return; + + fprintf(stderr, _("The following pathspecs only matched index entries outside the current\n" + "sparse checkout:\n")); + for_each_string_list_item(item, pathspec_list) + fprintf(stderr, "%s\n", item->string); + + advise_if_enabled(ADVICE_UPDATE_SPARSE_PATH, + _("Disable or modify the sparsity rules if you intend to update such entries.")); + +} + void detach_advice(const char *new_name) { const char *fmt = diff --git a/advice.h b/advice.h index bc2432980a..bd26c385d0 100644 --- a/advice.h +++ b/advice.h @@ -3,6 +3,8 @@ #include "git-compat-util.h" +struct string_list; + extern int advice_fetch_show_forced_updates; extern int advice_push_update_rejected; extern int advice_push_non_ff_current; @@ -71,6 +73,7 @@ extern int advice_add_empty_pathspec; ADVICE_STATUS_HINTS, ADVICE_STATUS_U_OPTION, ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE, + ADVICE_UPDATE_SPARSE_PATH, ADVICE_WAITING_FOR_EDITOR, }; @@ -92,6 +95,7 @@ void advise_if_enabled(enum advice_type type, const char *advice, ...); int error_resolve_conflict(const char *me); void NORETURN die_resolve_conflict(const char *me); void NORETURN die_conclude_merge(void); +void advise_on_updating_sparse_paths(struct string_list *pathspec_list); void detach_advice(const char *new_name); #endif /* ADVICE_H */ diff --git a/builtin/add.c b/builtin/add.c index 9f0f6ebaff..b556c566c3 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -170,24 +170,41 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, *dst++ = entry; } dir->nr = dst - dir->entries; - add_pathspec_matches_against_index(pathspec, &the_index, seen, 0); + add_pathspec_matches_against_index(pathspec, &the_index, seen, 1); return seen; } -static void refresh(int verbose, const struct pathspec *pathspec) +static int refresh(int verbose, const struct pathspec *pathspec) { char *seen; - int i; + int i, ret = 0; + char *skip_worktree_seen = NULL; + struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP; seen = xcalloc(pathspec->nr, 1); refresh_index(&the_index, verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET, pathspec, seen, _("Unstaged changes after refreshing the index:")); for (i = 0; i < pathspec->nr; i++) { - if (!seen[i]) - die(_("pathspec '%s' did not match any files"), - pathspec->items[i].original); + if (!seen[i]) { + if (matches_skip_worktree(pathspec, i, &skip_worktree_seen)) { + string_list_append(&only_match_skip_worktree, + pathspec->items[i].original); + } else { + die(_("pathspec '%s' did not match any files"), + pathspec->items[i].original); + } + } + } + + if (only_match_skip_worktree.nr) { + advise_on_updating_sparse_paths(&only_match_skip_worktree); + ret = 1; } + free(seen); + free(skip_worktree_seen); + string_list_clear(&only_match_skip_worktree, 0); + return ret; } int run_add_interactive(const char *revision, const char *patch_mode, @@ -563,15 +580,17 @@ int cmd_add(int argc, const char **argv, const char *prefix) } if (refresh_only) { - refresh(verbose, &pathspec); + exit_status |= refresh(verbose, &pathspec); goto finish; } if (pathspec.nr) { int i; + char *skip_worktree_seen = NULL; + struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP; if (!seen) - seen = find_pathspecs_matching_against_index(&pathspec, &the_index, 0); + seen = find_pathspecs_matching_against_index(&pathspec, &the_index, 1); /* * file_exists() assumes exact match @@ -585,12 +604,20 @@ int cmd_add(int argc, const char **argv, const char *prefix) for (i = 0; i < pathspec.nr; i++) { const char *path = pathspec.items[i].match; + if (pathspec.items[i].magic & PATHSPEC_EXCLUDE) continue; - if (!seen[i] && path[0] && - ((pathspec.items[i].magic & - (PATHSPEC_GLOB | PATHSPEC_ICASE)) || - !file_exists(path))) { + if (seen[i] || !path[0]) + continue; + + if (matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) { + string_list_append(&only_match_skip_worktree, + pathspec.items[i].original); + continue; + } + + if ((pathspec.items[i].magic & (PATHSPEC_GLOB | PATHSPEC_ICASE)) || + !file_exists(path)) { if (ignore_missing) { int dtype = DT_UNKNOWN; if (is_excluded(&dir, &the_index, path, &dtype)) @@ -601,7 +628,16 @@ int cmd_add(int argc, const char **argv, const char *prefix) pathspec.items[i].original); } } + + + if (only_match_skip_worktree.nr) { + advise_on_updating_sparse_paths(&only_match_skip_worktree); + exit_status = 1; + } + free(seen); + free(skip_worktree_seen); + string_list_clear(&only_match_skip_worktree, 0); } plug_bulk_checkin(); diff --git a/pathspec.c b/pathspec.c index e5e6b7458d..61f294fed5 100644 --- a/pathspec.c +++ b/pathspec.c @@ -62,6 +62,21 @@ char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, return seen; } +char *find_pathspecs_matching_skip_worktree(const struct pathspec *pathspec) +{ + struct index_state *istate = the_repository->index; + char *seen = xcalloc(pathspec->nr, 1); + int i; + + for (i = 0; i < istate->cache_nr; i++) { + struct cache_entry *ce = istate->cache[i]; + if (ce_skip_worktree(ce)) + ce_path_match(istate, ce, pathspec, seen); + } + + return seen; +} + /* * Magic pathspec * diff --git a/pathspec.h b/pathspec.h index 8202882ecd..f591ba625c 100644 --- a/pathspec.h +++ b/pathspec.h @@ -155,6 +155,14 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec, char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, const struct index_state *istate, int ignore_skip_worktree); +char *find_pathspecs_matching_skip_worktree(const struct pathspec *pathspec); +static inline int matches_skip_worktree(const struct pathspec *pathspec, + int item, char **seen_ptr) +{ + if (!*seen_ptr) + *seen_ptr = find_pathspecs_matching_skip_worktree(pathspec); + return (*seen_ptr)[item]; +} int match_pathspec_attrs(const struct index_state *istate, const char *name, int namelen, const struct pathspec_item *item); diff --git a/read-cache.c b/read-cache.c index 29144cf879..cbede4ada3 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1546,7 +1546,8 @@ int refresh_index(struct index_state *istate, unsigned int flags, if (ignore_submodules && S_ISGITLINK(ce->ce_mode)) continue; - if (pathspec && !ce_path_match(istate, ce, pathspec, seen)) + if (pathspec && !ce_path_match(istate, ce, pathspec, + ce_skip_worktree(ce) ? NULL : seen)) filtered = 1; if (ce_stage(ce)) { diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index f7b0ea782e..f66d369bf4 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -32,10 +32,22 @@ test_sparse_entry_unchanged() { test_cmp expected actual } +cat >sparse_entry_error <<-EOF +The following pathspecs only matched index entries outside the current +sparse checkout: +sparse_entry +EOF + +cat >error_and_hint sparse_entry_error - <<-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 "git add does not remove SKIP_WORKTREE entries" ' setup_sparse_entry && rm sparse_entry && - git add sparse_entry && + test_must_fail git add sparse_entry 2>stderr && + test_i18ncmp error_and_hint stderr && test_sparse_entry_unchanged ' @@ -56,7 +68,8 @@ do test_expect_success "git add$opt does not update SKIP_WORKTREE entries" ' setup_sparse_entry && echo modified >sparse_entry && - git add $opt sparse_entry && + test_must_fail git add $opt sparse_entry 2>stderr && + test_i18ncmp error_and_hint stderr && test_sparse_entry_unchanged ' done @@ -64,7 +77,8 @@ done test_expect_success 'git add --refresh does not update SKIP_WORKTREE entries' ' setup_sparse_entry && test-tool chmtime -60 sparse_entry && - git add --refresh sparse_entry && + test_must_fail git add --refresh sparse_entry 2>stderr && + test_i18ncmp error_and_hint stderr && # We must unset the SKIP_WORKTREE bit, otherwise # git diff-files would skip examining the file @@ -77,7 +91,8 @@ test_expect_success 'git add --refresh does not update SKIP_WORKTREE entries' ' test_expect_success 'git add --chmod does not update SKIP_WORKTREE entries' ' setup_sparse_entry && - git add --chmod=+x sparse_entry && + test_must_fail git add --chmod=+x sparse_entry 2>stderr && + test_i18ncmp error_and_hint stderr && test_sparse_entry_unchanged ' @@ -85,8 +100,23 @@ test_expect_success 'git add --renormalize does not update SKIP_WORKTREE entries test_config core.autocrlf false && setup_sparse_entry "LINEONE\r\nLINETWO\r\n" && echo "sparse_entry text=auto" >.gitattributes && - git add --renormalize sparse_entry && + test_must_fail git add --renormalize sparse_entry 2>stderr && + test_i18ncmp error_and_hint stderr && test_sparse_entry_unchanged ' +test_expect_success 'do not advice about sparse entries when they do not match the pathspec' ' + setup_sparse_entry && + test_must_fail git add nonexistent sp 2>stderr && + test_i18ngrep "fatal: pathspec .nonexistent. did not match any files" stderr && + test_i18ngrep ! "The following pathspecs only matched index entries" stderr +' + +test_expect_success 'add obeys advice.updateSparsePath' ' + setup_sparse_entry && + test_must_fail git -c advice.updateSparsePath=false add sparse_entry 2>stderr && + test_i18ncmp sparse_entry_error stderr + +' + test_done From patchwork Wed Feb 17 21:02:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 12092355 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 DD4C1C433E0 for ; Wed, 17 Feb 2021 21:05:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B227464E7A for ; Wed, 17 Feb 2021 21:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231693AbhBQVEz (ORCPT ); Wed, 17 Feb 2021 16:04:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234693AbhBQVEC (ORCPT ); Wed, 17 Feb 2021 16:04:02 -0500 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84E18C061793 for ; Wed, 17 Feb 2021 13:03:09 -0800 (PST) Received: by mail-qk1-x72b.google.com with SMTP id h8so33298qkk.6 for ; Wed, 17 Feb 2021 13:03:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZA/aBBmrTcvTv505cVVfcbJfxu1v1A507x3c1UtuzKI=; b=zRfl3ZUJ274ziDtxctkevEY3QxZEqXKNMQ4IBMY6B+UaP+jrCRvqgAltJF9NAn8u4h tSqF7Z1AK6v9WUDXBLAi+gIDqcO/iaDA8eHiOO0njCEngusdVzIRXcgS+wNxC8yR6FgQ hLYqHfAFrDFFpIXcL2nITENLg40uNvnGFA5zRe2BZA4UW+32Yyr9En4vjhZ1juHhAOuS rRPVR4nF/08qjHxSv2V+vBj48+b2VmnFG3/ZsA+NSZXwEjrrnyM3nzpC4xWZHEDTJwhC 5/Bd8NwUjZQjLZP/hxHTgfzDKPRysaH8KxBTqzXQbVLOu6B4XodHvgTS49zwElV5Eo5+ iIzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZA/aBBmrTcvTv505cVVfcbJfxu1v1A507x3c1UtuzKI=; b=SYlz4lh2GK50L+W2xsX+KqEgN7Pqz+tfWfMWOu+u+9cwl/Cx9MQlhLwiigmQPegZm1 UQzryWNrStGRKAbCJzaQyszQkhr0W/MfwNwhiOKis+xxAOxp+RyC1DS7Bq7m3s5kHkS0 XxRaWTlhL75BxjHDER6nfgk9LeDK0qAitCVe21l9E6cr151PovgVuVOBphZl7iPMa3cq lqil3kqRa9U7NVwswn0ANg2cuD9G3dowNyzP57C+dGJvj0CeFpxZINTrfHlgpc1nGCOv oFC77UwRGVyvKyN6dvX9NMOKtQ0c18KbLQPZ8T7POFZk0RMGunSKHJx46v0B6gR9Vu5M vRYw== X-Gm-Message-State: AOAM531ICn9ffd1P+Ttpqr+SpvSA/sJkOCrE6zgZKhaW6COyl/uiziX5 AcKELt3+W1BSdGD/W4DFDSHhoqXC+4ZxPg== X-Google-Smtp-Source: ABdhPJx2iXNqBfj3Lg22P/hBIuekWQ6SS0RPkR4YHyHVs5kayCc21xPwlubTX6cAbSeJtQzsnCxe4A== X-Received: by 2002:a37:78f:: with SMTP id 137mr1189954qkh.208.1613595788175; Wed, 17 Feb 2021 13:03:08 -0800 (PST) Received: from mango.meuintelbras.local ([177.32.118.149]) by smtp.gmail.com with ESMTPSA id o194sm2438459qke.101.2021.02.17.13.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 13:03:07 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: newren@gmail.com, stolee@gmail.com Subject: [RFC PATCH 7/7] rm: honor sparse checkout patterns Date: Wed, 17 Feb 2021 18:02:30 -0300 Message-Id: <61a77cd5f45ba02c7dff4b7932abdebb17c1667f.1613593946.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org `git add` refrains from adding or updating paths outside the sparsity rules, but `git rm` doesn't follow the same restrictions. This is somewhat counter-intuitive and inconsistent. So make `rm` honor the sparse checkout and advise on how to remove SKIP_WORKTREE entries, just like `add` does. Also add a few tests for the new behavior. Suggested-by: Elijah Newren Signed-off-by: Matheus Tavares --- Documentation/config/advice.txt | 5 +-- Documentation/git-rm.txt | 4 ++- builtin/rm.c | 35 ++++++++++++++------- t/t3600-rm.sh | 54 ++++++++++++++++++++++++++++++++ t/t7011-skip-worktree-reading.sh | 5 --- 5 files changed, 84 insertions(+), 19 deletions(-) diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt index d53eafa00b..bdd423ade4 100644 --- a/Documentation/config/advice.txt +++ b/Documentation/config/advice.txt @@ -120,6 +120,7 @@ advice.*:: Advice shown if a user runs the add command without providing the pathspec parameter. updateSparsePath:: - Advice shown if the pathspec given to linkgit:git-add[1] only - matches index entries outside the current sparse-checkout. + Advice shown if the pathspec given to linkgit:git-add[1] or + linkgit:git-rm[1] only matches index entries outside the + current sparse-checkout. -- diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt index ab750367fd..26e9b28470 100644 --- a/Documentation/git-rm.txt +++ b/Documentation/git-rm.txt @@ -23,7 +23,9 @@ branch, and no updates to their contents can be staged in the index, though that default behavior can be overridden with the `-f` option. When `--cached` is given, the staged content has to match either the tip of the branch or the file on disk, -allowing the file to be removed from just the index. +allowing the file to be removed from just the index. When +sparse-checkouts are in use (see linkgit:git-sparse-checkout[1]), +`git rm` will only remove paths within the sparse-checkout patterns. OPTIONS diff --git a/builtin/rm.c b/builtin/rm.c index 4858631e0f..d23a3b2164 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -5,6 +5,7 @@ */ #define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" +#include "advice.h" #include "config.h" #include "lockfile.h" #include "dir.h" @@ -254,7 +255,7 @@ static struct option builtin_rm_options[] = { int cmd_rm(int argc, const char **argv, const char *prefix) { struct lock_file lock_file = LOCK_INIT; - int i; + int i, ret = 0; struct pathspec pathspec; char *seen; @@ -295,6 +296,8 @@ 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 (ce_skip_worktree(ce)) + continue; if (!ce_path_match(&the_index, ce, &pathspec, seen)) continue; ALLOC_GROW(list.entry, list.nr + 1, list.alloc); @@ -308,24 +311,34 @@ int cmd_rm(int argc, const char **argv, const char *prefix) if (pathspec.nr) { const char *original; int seen_any = 0; + char *skip_worktree_seen = NULL; + struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP; + for (i = 0; i < pathspec.nr; i++) { original = pathspec.items[i].original; - if (!seen[i]) { - if (!ignore_unmatch) { - die(_("pathspec '%s' did not match any files"), - original); - } - } - else { + if (seen[i]) seen_any = 1; - } + else if (ignore_unmatch) + continue; + else if (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); + if (!recursive && seen[i] == MATCHED_RECURSIVELY) die(_("not removing '%s' recursively without -r"), *original ? original : "."); } + if (only_match_skip_worktree.nr) { + advise_on_updating_sparse_paths(&only_match_skip_worktree); + ret = 1; + } + free(skip_worktree_seen); + string_list_clear(&only_match_skip_worktree, 0); + if (!seen_any) - exit(0); + exit(ret); } if (!index_only) @@ -405,5 +418,5 @@ int cmd_rm(int argc, const char **argv, const char *prefix) COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("Unable to write new index file")); - return 0; + return ret; } diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 7547f11a5c..0e5cf945d9 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -907,4 +907,58 @@ test_expect_success 'rm empty string should fail' ' test_must_fail git rm -rf "" ' +test_expect_success 'setup repo for tests with sparse-checkout' ' + git init sparse && + ( + cd sparse && + mkdir -p sub/dir && + touch a b c sub/d sub/dir/e && + git add -A && + git commit -m files + ) && + + cat >sparse_entry_b_error <<-EOF && + The following pathspecs only matched index entries outside the current + sparse checkout: + b + EOF + + cat >b_error_and_hint sparse_entry_b_error - <<-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 'rm should respect sparse-checkout' ' + git -C sparse sparse-checkout set "/a" && + test_must_fail git -C sparse rm b 2>stderr && + test_i18ncmp b_error_and_hint stderr +' + +test_expect_success 'rm obeys advice.updateSparsePath' ' + git -C sparse reset --hard && + git -C sparse sparse-checkout set "/a" && + test_must_fail git -C sparse -c advice.updateSparsePath=false rm b 2>stderr && + test_i18ncmp sparse_entry_b_error stderr + +' + +test_expect_success 'recursive rm should respect sparse-checkout' ' + ( + cd sparse && + git reset --hard && + 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 'do not advice about sparse entries when they do not match the pathspec' ' + test_must_fail git -C sparse rm nonexistent 2>stderr && + test_i18ngrep "fatal: pathspec .nonexistent. did not match any files" stderr && + test_i18ngrep ! "The following pathspecs only matched index entries" stderr +' + test_done diff --git a/t/t7011-skip-worktree-reading.sh b/t/t7011-skip-worktree-reading.sh index 37525cae3a..f87749951f 100755 --- a/t/t7011-skip-worktree-reading.sh +++ b/t/t7011-skip-worktree-reading.sh @@ -141,11 +141,6 @@ test_expect_success 'diff-files does not examine skip-worktree dirty entries' ' test -z "$(git diff-files -- one)" ' -test_expect_success 'git-rm succeeds on skip-worktree absent entries' ' - setup_absent && - git rm 1 -' - test_expect_success 'commit on skip-worktree absent entries' ' git reset && setup_absent &&