Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 784F52459ED for ; Tue, 4 Nov 2025 02:09:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.155 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762222191; cv=none; b=Y/QZLPnpIUBDer0fwSL0KzFadPKiGhUkuKpFpMOcVCcfWhjCKBaSW2nC1jXjnOfwE7qsEPM52i/6DzC9Mvo/+6cJb5DEhb8kwCEDBCNDLa2u6VWKRFbQsP7LA0N4adSuiFZN2C+5DqThIzJTo1/CdJzR105ObXnovTcKil55I7o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762222191; c=relaxed/simple; bh=9cESc2ouliOrCtsIPzZfmlTUkFjniNsCD/aPkAx3MK8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NYwodE3pddkzPxqwLLMq/2xFd8/3ayQ0WWQPvhZZKww8VhjrU0AKe2iPaLAayKIvOrR7DTRdntxI4KB2EUWcw8eq3noKxm0rd8a04OloVgGJSliGcayZEyTL/B7mSB0Xejlg1/Rq52FQPebQKXmpfRnt57XKPxSxNbH3SX1aV5g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=kjE7u8cu; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=O3kfWSIO; arc=none smtp.client-ip=202.12.124.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="kjE7u8cu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="O3kfWSIO" Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.stl.internal (Postfix) with ESMTP id A3A637A03F6; Mon, 3 Nov 2025 21:09:48 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-12.internal (MEProxy); Mon, 03 Nov 2025 21:09:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1762222188; x= 1762308588; bh=z/N4V+WRCopOqY23QJiydcFNdIobbCKin51yP5oAGXY=; b=k jE7u8cuqz7HVlZo9Hrdbo/K+DIg9gYsHCU+9JTdtFxvYkIGWGM25t4TRm+QjqkJO ijffljTaPUiOBFd7zPhSXqaHTSK3fXDIhOFW45zlrh8jlyamdNm69LurNfF4aXQU QLGt0u05pgFdVWk/PeyIKFxk3feggkORsdpTW2mw4HP/+ksh1aRtc452P8OPX3S5 WCLr8IAJMsKK7LEs6/fE7N18cWoUpMYWtfqNQEOkB+Y4lck4mqt69J3kG/lJTAso c6PKGVWOQiCztajs2khTzkuE/1mn202/kJdsHpHaN+T5dAoHyQFbb8UDRX6YpfWC Sq7LVUNFuvTgJbnWiwwzw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1762222188; x=1762308588; bh=z/N4V+WRCopOqY23QJiydcFNdIob bCKin51yP5oAGXY=; b=O3kfWSIOIsgoEiKvJDq3YMAz4FMZHstmuCHvtt/FfzoR QjhBiJqn9GceEMhvzBdsyyiKyOwJwkudLRazqxxmh/os8+YO8Z/wCeVg01osRD3X +VQ5pcFDPJdAHq7JCfS5EVj/Vmtpual2+oznCjJknwNut5A1c0E2KN24YQmNIJRz XnpIk6a+w9MMoqetWeHe2cv8U6hCzupbU9lI7bZe+AkC2uP0L8r9gtSdXJm5Y70E L/9dpZDpa1/hc5JdvhRrE4X+w543TC9jLkquLdEcdzJ+J37jxy99nHnj0bd5rgsB E2UPcHuEveJU/gInDc8zjkSgNaAx4kDzEfTV2dFv2A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddujeeljeejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekredtre dttdenucfhrhhomheplfhunhhiohcuvecujfgrmhgrnhhouceoghhithhsthgvrhesphho sghogidrtghomheqnecuggftrfgrthhtvghrnhepleevieefieeuffeugefhveeugefgfe evvdefleevuedvfedvudefkeehtdeftdegnecuvehluhhsthgvrhfuihiivgepudenucfr rghrrghmpehmrghilhhfrhhomhepghhithhsthgvrhesphhosghogidrtghomhdpnhgspg hrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrd gtohhm X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 3 Nov 2025 21:09:47 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 10/12] apply: check and fix incomplete lines Date: Mon, 3 Nov 2025 18:09:26 -0800 Message-ID: <20251104020928.582199-11-gitster@pobox.com> X-Mailer: git-send-email 2.52.0-rc0 In-Reply-To: <20251104020928.582199-1-gitster@pobox.com> References: <20251104020928.582199-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The final line of a file that lacks the terminating newline at its end is called an incomplete line. In general they are frowned upon for many reasons (imagine concatenating two files with "cat A B" and what happens when A ends in an incomplete line, for example), and text-oriented tools often mishandle such a line. Introduce a new whitespace rule "incomplete-line", which is off by default for backward compatibility's sake, so that "git apply --whitespace={fix,warn,error}" can notice, warn against, and fix them. As one of the new test shows, if you modify contents on an incomplete line in the original and leave the resulting line incomplete, it is still considered a whitespace error, the reasoning being that "you'd better fix it while at it if you are making a change on an incomplete line anyway", which may controversial. Signed-off-by: Junio C Hamano --- t/t4124-apply-ws-rule.sh | 112 +++++++++++++++++++++++++++++++++++++++ ws.c | 20 +++++++ ws.h | 1 + 3 files changed, 133 insertions(+) diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh index 485c7d2d12..568805df31 100755 --- a/t/t4124-apply-ws-rule.sh +++ b/t/t4124-apply-ws-rule.sh @@ -556,4 +556,116 @@ test_expect_success 'whitespace check skipped for excluded paths' ' git apply --include=used --stat --whitespace=error sample-i && + (test_write_lines 1 2 3 0 5 && printf 6) >sample2-i && + cat sample-i >target && + git add target && + cat sample2-i >target && + git diff-files -p target >patch && + + cat sample-i >target && + git apply --whitespace=error target && + git apply --whitespace=error -R sample && + (test_write_lines 1 2 3 4 5 && printf 6) >sample-i && + cat sample >target && + git add target && + cat sample-i >target && + git diff-files -p target >patch && + + cat sample >target && + test_must_fail git apply --whitespace=error error && + test_grep "no newline" error && + + cat sample-i >target && + git apply --whitespace=error -R target && + git apply --whitespace=fix sample-i && + test_write_lines 1 2 3 4 5 6 >sample && + cat sample-i >target && + git add target && + cat sample >target && + git diff-files -p target >patch && + + cat sample-i >target && + git apply --whitespace=error target && + test_must_fail git apply --whitespace=error -R error && + test_grep "no newline" error && + + cat sample >target && + git apply --whitespace=fix -R sample-i && + test_write_lines 1 2 3 4 5 7 >sample3 && + cat sample-i >target && + git add target && + cat sample3 >target && + git diff-files -p target >patch && + + cat sample-i >target && + git apply --whitespace=error target && + test_must_fail git apply --whitespace=error -R error && + test_grep "no newline" error && + + cat sample3 >target && + git apply --whitespace=fix -R sample-i && + (test_write_lines 1 2 3 4 5 && printf 7) >sample3-i && + test_write_lines 1 2 3 4 5 6 >sample && + test_write_lines 1 2 3 4 5 7 >sample3 && + cat sample-i >target && + git add target && + cat sample3-i >target && + git diff-files -p target >patch && + + cat sample-i >target && + test_must_fail git apply --whitespace=error error && + test_grep "no newline" error && + + cat sample3-i >target && + test_must_fail git apply --whitespace=error -R error && + test_grep "no newline" error && + + cat sample-i >target && + git apply --whitespace=fix target && + git apply --whitespace=fix -R