From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796112048; b=zPK5pOjs5SIhnfxMGYPnbAer4V8xAYQAi861+T/veAJAdpf9s3ri6Mw2etZZAfjiosmA 2ScyEiIzxt6MygssL9Tnh1eRYY5pR9afPaqLztMAebPyCmuHW08l6/oXsZ5jjyK+u4Qt7 of/1UNl8g2dDxdGQGkGXTHDFDzx9Vl3Lx6YJr31wXozqxNBzcgYg446S9Uf4uX4m4khKC tcYRAVUPo0qWeL/VeYRv94eg/xnBbrJx9KVgIaVpJg0yZ3ssFZWeC6nSbKf6jj8+PC4Ed jST6JMoej7KjrTsMV24kFhXBBHHEdgv4h6Cvm5MFjF2W8kzngKRPwbGMZDQ9Yw8NG7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796112048; 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=8aAmW5RsLtF9ubD9rkZzE1Ro9i8cO9ZKeZchkX12ajg=; b=FhPfEM1pVCkV8Clj65La0ePqpwlLEcpPndzcUgiZG86sA2ZfNjzHx+tLNqMESmGNBdJX na7pfN2iz7WLbgl+tcxA/z9bEhszeNYF4ykwc4WeRcFSpn3AwDGfJ5zPNIf2Z5ur0ECLM aDLuMqHgHN8AAn65uVJGjtInD4fPOGyZhhmB40Vo34boDYgZo8EueP1wPSNlx4Ra/44jx Kc8sUKWkp4X8sV6vR7oi5+cuTS6a8TYXRMy5Fep0UKi4sljnXfGeJ3ahpLHBT33pKmlJz SNNdgfGlD5z0mpLAcsTFFrCgUAgvA2kSJI+ZsgsZXEOToh36JnJr/bKKLmftVJsltuw== 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=aMvmUdsq; arc=none smtp.remote-ip=209.85.210.173 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 95F1D606A31A for ; Tue, 1 Dec 2026 08:00:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 95F1D606A31A 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=aMvmUdsq Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-8b2382bf051so5992500b3a.3 for ; Tue, 01 Dec 2026 00:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796112047; x=1796716847; 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=8aAmW5RsLtF9ubD9rkZzE1Ro9i8cO9ZKeZchkX12ajg=; b=aMvmUdsqq6rJzqwSassUSaoHS9qQKM9mrAOM0MybpTi4LUBRDhPRE3ZB9XW91oipIk 5FKitTzyf1yHAIRciCmSdmzt+13l5lOmPYQ5pD2G2NUSs/tCIWFrziRtGmcWfn//fnY+ Hgs3ug9LctKQsDngGLVSZJlU48SGDrD4I/1ZjoWxS1a6kAKJwBnuZPcBYACp2PhEsSb3 RUqc7TxJt1kNhF/9S7O3kfGjdxARH6plYTuRj98uyTvCnJ5iJAQ398TFGx9toneGhVW9 dCyl/OfZ441mKOJzbP367y1ZmhEUbmokDt7Lq43gmmiSRwXr87a9z5EdAZ8weceeah2h a4sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796112047; x=1796716847; 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=8aAmW5RsLtF9ubD9rkZzE1Ro9i8cO9ZKeZchkX12ajg=; b=HQ+nspYolAxEZj3lp8UdqKuaBWWgu9XGRAEzZfzNbLRBf+pxQsKO/MALgZjblRqIaL RbVa/QEy82vCu0LJrBPNwPhx4l0kWmzlBhxzSV7wM+k7WPqg9+L8yMiezindZTrUkEMR /KfjbcChjS7URKmAs53eHdXYuD5PDFAOg2HV9PTGvj5G7bGZAE1wmo5qG+dfPlrwE/s9 gRuczDNH3pt8XtKo3E1Ldl3VjnMY6SpVaexJ8wuC26fEpDjOyDaZBcaHjCskMuv4cLCB kTHHTL/vmc0ImfZQYEIJWNAKNF58maryCKxxBVzYXmogINPwEnx/9HM8n8ragP40qpH8 ZKlg== X-Gm-Message-State: APuU4Z/vdD0Nng0f7S0+vac3r7EUBSBRo6hY2FkshyBy4okTjnI5tUS4 kmrMZWRRuAl9A36IwLeUEbzUl6qerMa7cBxmiNvnG9tLfWFgGYk7G/UJP9HYDt6Ve40= X-Gm-Gg: AZFdTZcEFRKRZRVkmxxq8l5A/jduX8ssbJBN1CQ3udreuN8B/FweReeDtGUiHnr2qZO YcdxWMSZ9CGFZGo6AV1MKQikBTduaCE0x9K4+phg9vBZ7lYFFQ1ShivZknHHJYmceyO0YGoX8dC 1ZsmHh/mJuUqv0Swvk9qtSK7GSkYYnuHfVLpQtRg1EuE41QTS1UAQes1HD9dITsnsZzljlMH1xD C29q86Gr5Jazr0d7A3CyJY4LiAR+3NU8i3anJGqomqLel7tywD8W9v6OMagHBFYZwxSyOXWin+b 5c0LXoIPHLrqF8SFRJfs2BLuHyLcuiVG433kRJYqyF6FNxhoWQG/8l5yt63nYntCa+dAUk+K+Zg hLuubUOnv7Ox27SKwqMB8xT+BWUZZhWLtzJUpzANrj21sehfRxaki4Z0mBUOhQ/pmX1YJfy856L 1iqSuNyeaf9y/imkwqipfusjSqdwiXAJAMWaV28DGq+24qMHIexRzo1eOEZXZpqfAcgauYY07A5 EF4C9ZM1qrzUq46/GJ56UvKwW+oyh3D7wSrC5y716h9RQG63l14ukEbIcXWCLA2V9vuJM0ujiFZ vYHwBgbdtionkNarcEmUKsQnI/iTVOhJizCGy6lmlkcSg8PrWNfvrepx+kbMUfSF1rhiK3CWKnI +lTSsmrbna41CL1VwK3awdA== X-Received: by 2002:a05:6a00:3491:b0:899:53a9:1dd9 with SMTP id d2e1a72fcca58-8c87d519a66mr32414477b3a.57.1796112046583; Tue, 01 Dec 2026 00:00:46 -0800 (PST) Received: from localhost.localdomain ([103.25.231.125]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c873442863sm19585533b3a.43.2026.12.01.00.00.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 00:00:46 -0800 (PST) From: Aniket Gupta To: git@vger.kernel.org Cc: Junio C Hamano , Matt Hunter , Mike Beaton , Phillip Wood Subject: [PATCH v3] dir: ignore CRLF-empty and space-only lines in pattern files Date: Tue, 1 Dec 2026 13:30:40 +0530 Message-ID: <20261201080040.47247-1-aniketgupta3001@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261129060057.74590-1-aniketgupta3001@gmail.com> References: <20261106182945.1316297-1-aniketgupta3001@gmail.com> <20261129060057.74590-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 argument 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. Reported-by: Mike Beaton Signed-off-by: Aniket Gupta --- Changes in v3: - Say "path argument" instead of "path" and drop "like before" in the log message (Matt). 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)