Article View: linux.kernel.git
Article #4016Re: [PATCH] dir: do not turn blank ignore-file lines into patterns
From: "Matt Hunter"
Date: Sat, 28 Nov 2026 05:24
Date: Sat, 28 Nov 2026 05:24
86 lines
11248 bytes
11248 bytes
Hi Aniket, Mike
I've been looking into this patch as well, but have been slow to
respond, sorry. Just a couple of thoughts below.
On Fri Nov 6, 2026 at 1:29 PM EST, Aniket Gupta wrote:
> A blank line in an ignore file matches nothing. But
> add_patterns_from_buffer() only skips a line when it is completely
> empty. A line that holds just a carriage return i.e a blank line in a
> file with CRLF line endings or just spaces, is not empty at that
> point. Once the carriage return and the trailing spaces are removed,
> what is left is an empty pattern, which matches any path that ends in
> a slash. "git check-ignore -v foo/" then names the blank line as the
> pattern that ignores foo/. Skip the line when nothing is left of it
> after trimming and add a test.
Given these two points from gitignore(5):
- A blank line matches no files, so it can serve as a separator
for readability.
- Trailing spaces are ignored unless they are quoted with
backslash ("`\`").
this definitely seems like a bug worth addressing.
Something that initially confused me while attempting to reproduce the
problem was that git-status and git-add behave correctly. Even running
'git add some-directory/' with the trailing slash present, stages the
expected files. I went back to the original bug report and saw that
these details were commented on. It would be helpful to mention in the
commit log message if the problem is specific to check-ignore.
>
> Reported-by: Mike Beaton <mjsbeaton@gmail.com>
> Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
> ---
> dir.c | 3 ++-
> t/t0008-ignores.sh | 7 +++++++
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/dir.c b/dir.c
> index d896e7be4b..5a8a28afef 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -1249,7 +1249,8 @@ int add_patterns_from_buffer(char *buf, size_t size,
> if (entry != buf + i && entry[0] != '#') {
> buf[i - (i && buf[i-1] == '\r')] = 0;
> trim_trailing_spaces(entry);
> - add_pattern(entry, base, baselen, pl, lineno);
> + if (*entry)
> + add_pattern(entry, base, baselen, pl, lineno);
This avoids adding a pattern which becomes empty after stripping a
carriage return and any spaces. I wonder if it is also worth fixing up
the parsing responsible for interpreting such "whitespace only" patterns
to match ".*/"? Either way, I think this patch is an improvement as-is.
> }
> lineno++;
> entry = buf + i + 1;
> diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh
> index ed95faf327..199abbcdf3 100755
> --- a/t/t0008-ignores.sh
> +++ b/t/t0008-ignores.sh
> @@ -875,6 +875,13 @@ EOF
> test_must_be_empty err
> '
>
> +test_expect_success 'blank lines are not patterns' '
Should this test description be more about the spelling of the
(inadvertently) ignored directory? That might better explain the
specific check-ignore assertion that is made.
> + mkdir blank-dir &&
> + printf "\r\n \n \r\n" >blank-ignore &&
> + test_expect_code 1 git -c core.excludesfile=blank-ignore check-ignore blank-dir/ >actual &&
> + test_must_be_empty actual
> +'
> +
> test_expect_success !MINGW 'quoting allows trailing whitespace' '
> rm -rf whitespace &&
> mkdir whitespace &&
Technical Details
Message-ID:
<DN6LDMN4UVPP.ZUG3AO2YOIZG@lfurio.us>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76568-linux-kernel-git=dewy.ruReferences:
<CAHzAAWSi9D1mRL=A5-9GxzqQwo9jJ=45Hmxj3hVAF=8wkNZLmg@mail.gmail.com> <20261106182945.1316297-1-aniketgupta3001@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76568-linux-kernel-git=dewy.ru
From: m@lfurio.us ("Matt Hunter")
Newsgroups: linux.kernel.git
Subject: Re: [PATCH] dir: do not turn blank ignore-file lines into patterns
Date: Sat, 28 Nov 2026 00:24:25 -0500
Organization: Usenet Network
Message-ID: <DN6LDMN4UVPP.ZUG3AO2YOIZG@lfurio.us>
References: <CAHzAAWSi9D1mRL=A5-9GxzqQwo9jJ=45Hmxj3hVAF=8wkNZLmg@mail.gmail.com> <20261106182945.1316297-1-aniketgupta3001@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="887117"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:2X7qWDSIFPXKiQNNgSWCljEkFiY= sha256:KcKdWIlYWekeDQKIJeD2Ri36FVom22cubV4WQ10Q9z0=
sha1:frhgVsqHtLZs/R8ZgryNBDh6W+A= sha256:bVz33f/FqDxZfj++9D99ZZ8/fE/bVr6Kj2vgIQlrnNo=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 7C542125F6F; Sat, 28 Nov 2026 08:25:23 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.05
X-Spam-Status: No, score=-2.05 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
header.d=lfurio.us
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 4Br_KTfwgzAk;
Sat, 28 Nov 2026 08:25:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-76568-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=lfurio.us
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 8D8A6125F6B; Sat, 28 Nov 2026 08:25:06 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 94D2A25945; Sat, 28 Nov 2026 05:25:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795843501;
b=XIggWIjj9tscOmUihZZMnYsOUzvShpjaEg0hqs4GLHSjYevnK4nWsHy48HiLiYIm3KCN
HmFzexrtz2erfCh0+QoSHzWxuxi7WZWzUnSqtqoUie/tPCYcn0xZx2438d5n7IejU9rH/
EPcd7CXwKouXeS8uzdJ3Y3jVRqGX61CxH5LJEkxuGRA7QRbZFQ51JxMR8jDtSyZUNnsgP
GghGWxHXXx+/tDrp1uFNnHmecqI1cAtR9CdY+ooZSW3oUrqzbfi4pvt0hWfLi9eGH3dry
HS5FbjoH+PsKfzWrDcduVHb0e/dK4u04yA3AOHYIaCvGtpRjmWGwg717Ocqprc2aGhQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795843501;
h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:Mime-Version:
Content-Transfer-Encoding:Content-Type:Date:Message-Id:Subject:Cc:To:
From:X-Mailer:References:In-Reply-To;
bh=UhTuH32sMQCiE2Y1Z6OHLI5NDHucmzOtYU+alWW45t8=;
b=vc1oE0jOeJSF63AihNgdeY1riRaXMYGwzJOPNd2NvNd25MpPf9HG0gBpbZ4WuFKRPmCg
+TZhxawdT/1OQL2m4gWXLggKplelEwnBvc/AibChkUMiPW4v6xtT8mC+FuWYeMNKccOuk
vJkXojSIf7VCtO68JkSyF3/7GpEjAFxj30kw03cC+iRN3WK5kqR81b/mgM+CVUM3M3DKX
AyHBGHIe0MSdpPwOEhHPLRpeo8wdsPXYJlVi/40l78FeZPLWJUeGqIbrg9HBmnyb0R+EN
2GnxJvKryi5aq7j2LFRkAXrYSlGhLWOz9TO3/nvv+YPWBbR3FQVYt7UHucjBXlPx83w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=lfurio.us header.i=@lfurio.us header.a=rsa-sha256 header.s=default header.b="hI/BGbjM";
dmarc=pass header.from=lfurio.us;
spf=pass smtp.mailfrom=lfurio.us;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 12ABC606A327;
Sat, 28 Nov 2026 05:25:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (1024-bit key) header.d=lfurio.us header.i=@lfurio.us header.a=rsa-sha256 header.s=default header.b=hI/BGbjM
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=157.230.60.252
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795843500;
b=f5OyZ+Ag7w7pvFhZtsBVFxusdXQmBbVkPEnCKREB1zVUlMwYhi/mxcLcUY8pZL5tF5YP
eiJ4+RNTvU5r9Q/GnykyfNEwqRTPJN/p6T2LPcqbIFXpJAQ0pPBS4uGBhNqfXJEQbbY1b
uo5jaTtXLrt928pioKbEKPc4YT5gpyjD4oWuJMHej4saWWiq8rfYxt9NrVn9F6cy0cGUl
CZBTega7yl2LDalPBPJv4m6magGmnti6yRc4K35G8IAMXATHVwGoTEB4YxDavtO0vYTZR
i18LNvgU9ww14H6KAPfI/JIDt/O/mQ90anQnfssPFyyO+XUPyOdq3PwAj/o8BKfAz3Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795843500;
h=DMARC-Filter:DKIM-Signature:Received:Mime-Version:
Content-Transfer-Encoding:Content-Type:Date:Message-Id:Subject:Cc:To:
From:X-Mailer:References:In-Reply-To;
bh=UhTuH32sMQCiE2Y1Z6OHLI5NDHucmzOtYU+alWW45t8=;
b=2xJCubTc0qGjWoA6/u44C/44USCwsHVBlH1weknD9SFiesxF7+v4sevZurGYeXfUHPp4
vKH5mtEowPShcebKga2Ps5HVO4l/mvJN/STtGEyoJkGZqElIB5ewqHYjkhA071a10SOZ/
Qs/Cjkga7t4DEvfdWPWdfceIaYv2aemoOrZ3FK2fZxkSVqEYSP3SQHh3q/N9voDEIvk0w
SsC8BEwa3JWi3AmPWbFVcMfUq5dER7Fi4eokvMm7qgFSCyICjLRaSTElnQgp8ggtmM2dN
V+V6Hit18dABs54ie5LZTKuGre5oNZ9F1YcU6zrQvqPI4O8Gf67y9rhERAhbX0Dj+Sw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=lfurio.us;
spf=pass smtp.mailfrom=lfurio.us;
dkim=pass header.d=lfurio.us header.i=@lfurio.us header.a=rsa-sha256 header.s=default header.b="hI/BGbjM";
arc=none smtp.remote-ip=157.230.60.252
X-Received: from mail.normalmode.org (h01.normalmode.org [157.230.60.252])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 926E6606A31C
for <git@vger.kernel.org>; Sat, 28 Nov 2026 05:24:59 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 926E6606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lfurio.us
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lfurio.us
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lfurio.us; s=default;
t=1795843491; bh=5oYCRbFMD7CqQtNhkp8Ld41OqTYJeFmyZNZODXyaHwI=;
h=Date:Subject:Cc:To:From:References:In-Reply-To:From;
b=hI/BGbjM+nYI7KxI2Qj/b2fjOGMDy8auGLfQOkJxiS7B1Zld2UCKa7B/no3feD8PP
GxOEIxleCH9xXBH4hD3nBHy8NSwFWhlDZWbphv4oqcU/YY/2797zOIfekMo/6LAmDQ
QQmIeC1cXc2KPdHy6hDxcXuyAh+Nd0yCJY86L+dg=
X-Received: by mail.normalmode.org (Postfix) with ESMTPSA id A1054600E7;
Sat, 28 Nov 2026 05:24:51 +0000 (UTC)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-Cc: "Junio C Hamano" <gitster@pobox.com>, "Mike Beaton"
<mjsbeaton@gmail.com>, "Phillip Wood" <phillip.wood123@gmail.com>
X-Mailer: aerc 0.21.0-0-g5549850facc2
X-In-Reply-To: <20261106182945.1316297-1-aniketgupta3001@gmail.com>