From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 8A0AB1F5AE for ; Mon, 20 Jul 2020 18:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729390AbgGTSqG (ORCPT ); Mon, 20 Jul 2020 14:46:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728466AbgGTSqF (ORCPT ); Mon, 20 Jul 2020 14:46:05 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39B57C061794 for ; Mon, 20 Jul 2020 11:46:05 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id q4so21434382lji.2 for ; Mon, 20 Jul 2020 11:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q72ldy3aS585EgXFRgQHJGhyIClWksBE+2ct16n4CGA=; b=QNUcdM3eJI4C3mjiEYQxEId1hqTt/+Dn9Bgbdo2shD6SrAkA7WS/zPM5pqvkw53bxA po5zkCLb0HBHHXXWPbpr6p8+HsskPFojX2a1eOR+EfoT5doLPOGa0lbiRAs9Qyd4jLLq SSB86CTPkJW9GGTuLuNqDJMiPMSBBzyMQU41sVS2vthG19lsqDPMbFkxDc52rQDfJyck cEW+VFA/B1c3IdMK1KO/cADgklDD+VApbDOLIefvCDRAHzlxOEjZw9GYJ3BxtrDsgL3F /veIDzVt0gw8PH/xPJpxfHj8rksHVPP1IXmV2GoAhSB2fIXFEMwgitFYxYEJUaI4ROs1 K7Fg== 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=Q72ldy3aS585EgXFRgQHJGhyIClWksBE+2ct16n4CGA=; b=HYT7hVfjx3LdkzBkxAmogEuxngs2fa9XEo8h2Ad6IG/MkGpWOZzb5NFxStb2VVOu3M ajIgBEiwrdMNHb6ZzGt/HB/q15X7hMD5PKFg0jlhP8VVPWrvGgs+/XGdp2JXu7xl/mW2 c+/h7N4GUjuvSPa3arf2sX1YkwrZLFrxPKJ6Qf0df0sIFZzh91QuD3q/FJcQSt312c8M xoFveYj9OCd+6ujJ4xzdpRUxO3fmaJ8epKju+HFuwSZ8mrEBCI+5im0ui1S1bXQ+4dlm hhaTzZN4SHkroYIVncrhdy0jYL1OhJRhzv/IqZjs6VL034UoK1T/uwIkQcLm+iZbxDkG Lpxg== X-Gm-Message-State: AOAM533rsp6zT+APaCOrRVakgwFinLQNBiEMdvtgaRMVXR/E1GtMIt4Q zCVyPsV2DcEzDtZ3XEbftwE= X-Google-Smtp-Source: ABdhPJyfmq7q0ANXfZqoFq5cmDcOEU9QqOV/Y5E2plenjxJmUPrCx4OJoeEAv4LNvRNmG8C4Ho/DUQ== X-Received: by 2002:a2e:a58a:: with SMTP id m10mr138086ljp.76.1595270763735; Mon, 20 Jul 2020 11:46:03 -0700 (PDT) Received: from localhost.localdomain (92-33-153-30.customers.ownit.se. [92.33.153.30]) by smtp.gmail.com with ESMTPSA id v11sm3371948ljh.119.2020.07.20.11.46.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 11:46:03 -0700 (PDT) From: =?UTF-8?q?Martin=20=C3=85gren?= To: Elijah Newren Cc: Andreas Schwab , Elijah Newren via GitGitGadget , git@vger.kernel.org, Martin Melka , =?UTF-8?q?SZEDER=20G=C3=A1bor?= , Samuel Lijin , =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= , Derrick Stolee Subject: [PATCH] dir: check pathspecs before returning `path_excluded` Date: Mon, 20 Jul 2020 20:45:29 +0200 Message-Id: <20200720184529.22449-1-martin.agren@gmail.com> X-Mailer: git-send-email 2.28.0.rc1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Mon, 20 Jul 2020 at 17:25, Elijah Newren wrote: > > Awesome, thanks Andreas for the bisected report and Martin for finding > and fixing the bug. As for the reason that the old patch injected the > pathspec check between the path_excluded and the path_untracked cases, > that appears to me to just be "I'm good at making boneheaded > mistakes". Your changes here are the right fix. Ok, here it is as a proper patch. > Reviewed-by: Elijah Newren Thanks. I've included your reviewed-by below. The log message is obviously new, but the diff is identical to what I posted earlier. BTW, this bug first appeared in v2.27.0, so this is not a regression during the v2.28.0 cycle. Martin -- >8 -- In 95c11ecc73 ("Fix error-prone fill_directory() API; make it only return matches", 2020-04-01), we taught `fill_directory()`, or more specifically `treat_path()`, to check against any pathspecs so that we could simplify the callers. But in doing so, we added a slightly-to-early return for the "excluded" case. We end up not checking the pathspecs, meaning we return `path_excluded` when maybe we should return `path_none`. As a result, `git status --ignored -- pathspec` might show paths that don't actually match "pathspec". Move the "excluded" check down to after we've checked any pathspecs. Reported-by: Andreas Schwab Reviewed-by: Elijah Newren Signed-off-by: Martin Ă…gren --- dir.c | 4 ++-- t/t7061-wtstatus-ignore.sh | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/dir.c b/dir.c index 1045cc9c6f..fe64be30ed 100644 --- a/dir.c +++ b/dir.c @@ -2209,13 +2209,13 @@ static enum path_treatment treat_path(struct dir_struct *dir, baselen, excluded, pathspec); case DT_REG: case DT_LNK: - if (excluded) - return path_excluded; if (pathspec && !match_pathspec(istate, pathspec, path->buf, path->len, 0 /* prefix */, NULL /* seen */, 0 /* is_dir */)) return path_none; + if (excluded) + return path_excluded; return path_untracked; } } diff --git a/t/t7061-wtstatus-ignore.sh b/t/t7061-wtstatus-ignore.sh index e4cf5484f9..2f9bea9793 100755 --- a/t/t7061-wtstatus-ignore.sh +++ b/t/t7061-wtstatus-ignore.sh @@ -30,6 +30,31 @@ test_expect_success 'same with gitignore starting with BOM' ' test_cmp expected actual ' +test_expect_success 'status untracked files --ignored with pathspec (no match)' ' + git status --porcelain --ignored -- untracked/i >actual && + test_must_be_empty actual && + git status --porcelain --ignored -- untracked/u >actual && + test_must_be_empty actual +' + +test_expect_success 'status untracked files --ignored with pathspec (literal match)' ' + git status --porcelain --ignored -- untracked/ignored >actual && + echo "!! untracked/ignored" >expected && + test_cmp expected actual && + git status --porcelain --ignored -- untracked/uncommitted >actual && + echo "?? untracked/uncommitted" >expected && + test_cmp expected actual +' + +test_expect_success 'status untracked files --ignored with pathspec (glob match)' ' + git status --porcelain --ignored -- untracked/i\* >actual && + echo "!! untracked/ignored" >expected && + test_cmp expected actual && + git status --porcelain --ignored -- untracked/u\* >actual && + echo "?? untracked/uncommitted" >expected && + test_cmp expected actual +' + cat >expected <<\EOF ?? .gitignore ?? actual -- 2.28.0.rc1