From patchwork Mon Jul 20 18:45:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11674465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4FA0F1392 for ; Mon, 20 Jul 2020 18:46:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3477522B51 for ; Mon, 20 Jul 2020 18:46:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QNUcdM3e" 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_=C3=85gren?= To: Elijah Newren Cc: Andreas Schwab , Elijah Newren via GitGitGadget , git@vger.kernel.org, Martin Melka , =?utf-8?q?SZEDER_G=C3=A1bor?= , Samuel Lijin , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , 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 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