From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795932065; b=Qbqz3LFSSOQeBVEnI3rM+4SrIPuQeE7gCOsZFn3UzCdHzKnTsS3uMrr8h49aH8hW6w2v ufD1hePmgbc1jWKJxvAqtVF+sQXVyeE7843jhlj8GqQKN7yhpE9PUUncN5R5cWwCooNs1 A/Q5uj8utg2Kdt/veRhtkunKy41R07sGTclxztnpBKqZsRyWbtmOGdweWIMobb67TvBIa sFUdchExQa7daFbq4PNfH0rUk9Y+rG+QqeaaYnzVYFt7sidav9wgRP7RMruJ2nBNWRx7v YB2pBPLbuyNoVPZQomSz7s4u+Lxf33MCIs8mxzu34WRTeE/1xZZFNAP+2vRvu5WbwZg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795932065; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=+YUObsSmi8Tv9FrxZlFrFnkotLzkUnUi32Y1NGh1KnQ=; b=OEBsLIz05B3q+2eYza9bvRt9sNicd/EE0S/dzXy3jNhrXZqrNzGVfqINdntVDkxO000R CRWqvmzgaP0aEqhQ3kRvJccHv0tvph/1Q3rGe/96Tvvj8wPU89lngFJqievQOJUeEcEsc s5JRFrJ0XYsYQfP5y5cxDVld7nF8qfD1PeHIMvRck+0pr3L7/eI5I4hWkSujrXv23aVQW zKYb1yeQ+xP+xsKKNdPESN5dSeGQHapJSuY2IhKOdjW7xsmCeUPR1tVfZ1/VgDafFzNAJ wscQzouRCwXD6tcaYqt8SuZI7WLjfOgaxYnjSy/wZyMOsPKGD5U4yAz6pfXlK6w6qQg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=issRkgJc; arc=none smtp.remote-ip=209.85.214.178 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DECA1606A31C for ; Sun, 29 Nov 2026 06:01:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DECA1606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=issRkgJc Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2f0426a65e0so54913065ad.3 for ; Sat, 28 Nov 2026 22:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795932064; x=1796536864; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+YUObsSmi8Tv9FrxZlFrFnkotLzkUnUi32Y1NGh1KnQ=; b=issRkgJcHnX3Hlq4yFEMDqosDR6oxyf9JWNRU//bf1zeIZK1ezEUwxbu05kQo8U3OW 2MJ/tyJc6CQy1iJIQNuGFV+lunyMQm1KvV9CVS/FKKb8TrnjbqpT0LfwYzxVIIBdbLaU 4MTvz+wCYb0mbBpKHt+Evmv4Q/YRa8WtwLDQ0iES6eE9YFnhmY2DNzM+ydvXmAFeyYt8 ht8mGdHyxIfeyqMzrW3TQyszxkzwHCK5cr0J5Hwmu1IXxrusRLB5umUv+PCx3EfRxAm4 HNza/6W89EXKvZKRzqvsdxdQ7g4GiKq/PLg08KzT9S2SM24MAKyK5+k/5hoOXNmVP0fa 85vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795932064; x=1796536864; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+YUObsSmi8Tv9FrxZlFrFnkotLzkUnUi32Y1NGh1KnQ=; b=AwtIwjw0DlCT4eV+YiWyboSdt1Yi0ODZ0+H8Q7Y0fqNQPUjNKk6tazfoxDyifwFv28 m/jXrYHIOMsmTDtehbpeFhCXbb0NUKL3DFjTvm0Cf4st/9HSYg3nj6a5LDAD8awp8b7/ T2Nf0HDNj2R3UiiABFd+KMKXATBwYh4eQX91OD3BmbX25yt+CbEgJOAMWpxv0nDTONd7 cXZjN17qq9dNtzLN7QUG5wQTfjsaW77MVvvsaPOngQtX1dW9c+5ZFbYrkSdE1i+ZyWSI KIXUSqTcuUuT35YeNPfnkSMeOllNPCKSuZp6utFEPEdlz7ZuwgxoewFioKZ984xR+h8Q gHwA== X-Gm-Message-State: APuU4Z8uU3zcD91JgMiF3K0ZERGV3D3S4uLemyAemS0mjkS/ug0VHk9g tL7QGMi/5sHZbSQBJBunQq0dIZ1l6POkZaVCQGzcrRzz2oLWmKZOT2LeeMg+PXsJjDY= X-Gm-Gg: AZFdTZcZJdKae2E6S+rQqJuKoOcJ2op6zkyuKwg4k8okI3fYNz3cWNdMTGYBsgMdnH4 Zq6oIZOHGwaX69Zfa/D/XILExgTdwOKm8qUNmlGJW/maQS7DCjY+V83jU6eVQ0ReaDtp4KW4k1K JcDc10UDNbNmss9HJhX5oxcZrwFiTxdyN/UjrdRS6Oy/nYEDZReia6DMN7l8V3ESdoyaDpV7+rD kZdaU1ZfdsGEajtMyAlFR0Tn046pSwPr9/sYszVLNxxfYqtPdDJfRkmmP18pmQOdqBuVTu2bu0q V5NHU+L0PR8u21vdkUuEAwVTxiC6Fg0byo/lyqqNWfGz+rMbAW4wg//L+F7TpFFqPqvzzNn7mjA qRRqVIT/4OUC8oFxl/kJ72scQKlKR3E8o6zv8PoF+p5856O+T83IOC2d+6xryLJw+3iqTI1bqMA RCItjTc6ceVZy0rY0aDxh1DtO0qEoVhXDVQnN2SRO9YwYsu3LelvKaWAjHZOYPVKnpLuSWa8Ddj FCOQMFk1N3GWC+AMzUF6YWO+RPWEvcy0svyjmq4NpXV0Ptsd1tDKJ2b3NMITrV2TGm3NGQuUxPB PuP7FhxZ1cSF8p8m6bg1SVtt+QOS/DuKyKbvg6GWA0MZS3ti9w6aC5IWZdr61fGfQEOLLFqKJic fHMIKGyO9h1libP1CQDQG X-Received: by 2002:a17:902:cec4:b0:2f0:436d:bdc1 with SMTP id d9443c01a7336-2f0436dc431mr270748675ad.33.1795932064109; Sat, 28 Nov 2026 22:01:04 -0800 (PST) Received: from localhost.localdomain ([223.190.82.63]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f15663fsm143553065ad.76.2026.11.28.22.01.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Nov 2026 22:01:03 -0800 (PST) From: Aniket Gupta To: git@vger.kernel.org Cc: Junio C Hamano , Matt Hunter , Mike Beaton , Phillip Wood Subject: [PATCH v2] dir: ignore CRLF-empty and space-only lines in pattern files Date: Sun, 29 Nov 2026 11:30:57 +0530 Message-ID: <20261129060057.74590-1-aniketgupta3001@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261106182945.1316297-1-aniketgupta3001@gmail.com> References: <20261106182945.1316297-1-aniketgupta3001@gmail.com> X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit add_patterns_from_buffer() skips an empty line which starts right at the '\n', before it strips the '\r' or any trailing spaces. A two byte "\r\n" line in a CRLF file, or a line that holds only spaces (with or without the '\r') is not empty at that point. Stripping the '\r' and calling trim_trailing_spaces() reduces it to an empty string, which is then passed to add_pattern(). parse_path_pattern() turns that empty string into a 0 length pattern with PATTERN_FLAG_NODIR. The directory walk checks a directory before it appends the trailing slash. Thus, status and a plain add are not affected. A path that ends in a slash is a different scenario. For eg, with "git check-ignore foo/", the basename is empty and match_basename() matches the 0 length pattern and "check-ignore -v" names that line as the reason foo/ is ignored. Cone-mode sparse-checkout is affected as well. For such a line, add_pattern_to_hashsets() sees a pattern shorter than 2 characters, warns "unrecognized pattern: ''" and disables cone pattern matching. Skip calling add_pattern() when the trimmed line is empty. This follows gitignore(5) which says that trailing spaces are ignored unless quoted with backslash. A file name made of spaces can still be matched by quoting the spaces, like before. Reported-by: Mike Beaton Signed-off-by: Aniket Gupta --- Changes in v2: - Rewrite the log message without the word "blank" (Junio). - Explain in the log message why status and add are not affected, with check-ignore as the example (Matt), and mention that cone-mode sparse-checkout warns on such lines (Junio). - Rename the test and drop the mkdir (Matt). - Keep the fix in add_patterns_from_buffer() instead of moving it into match_basename() as I suggested to Matt. Cone mode warns before any matching runs (Junio), so the line has to be skipped here. Making match_basename() reject empty patterns can be a separate change. Thanks Junio and Matt for the review. 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); } lineno++; entry = buf + i + 1; diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index ed95faf327..9884f67650 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -875,6 +875,13 @@ EOF test_must_be_empty err ' +test_expect_success 'trailing-slash directory is not ignored by CRLF-empty or space-only lines' ' + printf "\r\n \n \r\n" >empty-lines && + test_expect_code 1 git -c core.excludesfile=empty-lines \ + check-ignore dir/ >actual && + test_must_be_empty actual +' + test_expect_success !MINGW 'quoting allows trailing whitespace' ' rm -rf whitespace && mkdir whitespace && base-commit: 03b41523c576f26ad34085378717a0c1b287470f -- 2.54.0 (Apple Git-157)