git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/4] rebase: test whitespace fixes with the merge backend

From
AGAlessio Attilio via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 30, 2026, 00:01 UTC
Message-ID
<e462455723a5bb021093bae98603ab32e5cf49c8.1795996885.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2511.git.git.1795996885.gitgitgadget@gmail.com>
From: Alessio Attilio <attilio.alessio@protonmail.com>

Exercise whitespace=fix while replaying commits with the merge backend, including interactive use, attribute rules, existing whitespace in the base, added files, and whitespace at end of file. Also check that the option remains rejected with the merge backend for actions it does not support.

These tests cover the user-visible behavior across both backend selection and merge replay, guarding against fixing unchanged context or regressing the apply backend.

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
 t/t3417-rebase-whitespace-fix.sh | 163 +++++++++++++++++++++++++++++++
 1 file changed, 163 insertions(+)
diff --git a/t/t3417-rebase-whitespace-fix.sh b/t/t3417-rebase-whitespace-fix.sh
index 96f2cf22fa..c65b5c1e37 100755
--- a/t/t3417-rebase-whitespace-fix.sh
+++ b/t/t3417-rebase-whitespace-fix.sh
@@ -94,6 +94,169 @@ test_expect_success 'same, but do not remove trailing spaces' '
 	test_cmp file third
 '
 
+test_expect_success 'interactive rebase fixes whitespace' '
+	git config core.whitespace blank-at-eol &&
+	git checkout -b interactive-whitespace HEAD^ &&
+	test_write_lines "clean" >file &&
+	git commit -am clean &&
+	test_write_lines "trailing " >>file &&
+	git commit -am "add whitespace errors" &&
+	write_script sequence-editor <<-\EOF &&
+	sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+	mv "$1.tmp" "$1"
+	EOF
+	GIT_SEQUENCE_EDITOR=./sequence-editor git rebase -i --whitespace=fix HEAD^^ &&
+	test_write_lines clean "trailing" >expect &&
+	test_cmp expect file
+'
+
+test_expect_success 'interactive rebase fixes whitespace in upstream context' '
+	test_create_repo context &&
+	(
+		cd context &&
+		test_write_lines one "two " three >file &&
+		git add file && git commit -m base &&
+		git checkout -b topic &&
+		test_write_lines one two THREE >file &&
+		git commit -am topic &&
+		git checkout -b upstream HEAD^ &&
+		test_write_lines one two three >file &&
+		git commit -am whitespace &&
+		git checkout topic &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix upstream &&
+		test_write_lines one two THREE >expect &&
+		test_cmp expect file
+	)
+'
+
+test_expect_success 'interactive rebase preserves other whitespace changes' '
+	test_create_repo preserve &&
+	(
+		cd preserve &&
+		git config core.whitespace blank-at-eol &&
+		test_write_lines one "two " three >file &&
+		git add file && git commit -m base &&
+		git checkout -b topic &&
+		printf " one\ntwo \nthree \n" >file &&
+		git commit -am topic &&
+		git checkout -b upstream HEAD^ &&
+		printf "one\ntwo\nthree\n" >file &&
+		git commit -am whitespace &&
+		git checkout topic &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix upstream &&
+		printf " one\ntwo\nthree\n" >expect &&
+		test_cmp expect file
+	)
+'
+
+test_expect_success 'interactive rebase rejects unsupported whitespace actions' '
+	test_create_repo unsupported &&
+	(
+		cd unsupported &&
+		test_write_lines base >file &&
+		git add file && git commit -m base &&
+		test_write_lines change >>file &&
+		git commit -am change &&
+		test_must_fail env GIT_SEQUENCE_EDITOR=: \
+			git rebase -i --whitespace=warn HEAD^
+	)
+'
+
+test_expect_success 'interactive rebase fixes blank-at-eof' '
+	test_create_repo eof &&
+	(
+		cd eof &&
+		test_write_lines one >file &&
+		git add file && git commit -m base &&
+		test_write_lines one two >file &&
+		printf "\n\n" >>file &&
+		git commit -am whitespace &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix HEAD^ &&
+		test_write_lines one two >expect &&
+		test_cmp expect file
+	)
+'
+
+test_expect_success 'interactive rebase handles upstream blank-at-eof fixes' '
+	test_create_repo eof-context &&
+	(
+		cd eof-context &&
+		test_write_lines one >file &&
+		printf "\n\n" >>file &&
+		git add file && git commit -m base &&
+		git checkout -b topic &&
+		test_write_lines one two >file &&
+		printf "\n\n" >>file &&
+		git commit -am topic &&
+		git checkout -b upstream HEAD^ &&
+		test_write_lines one >file &&
+		git commit -am whitespace &&
+		git checkout topic &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix upstream &&
+		test_write_lines one two >expect &&
+		test_cmp expect file
+	)
+'
+
+test_expect_success 'interactive rebase honors path whitespace rules' '
+	test_create_repo attr &&
+	(
+		cd attr &&
+		echo "file whitespace=-blank-at-eol" >.gitattributes &&
+		test_write_lines one >file &&
+		git add .gitattributes file && git commit -m base &&
+		printf "one \n" >file &&
+		git commit -am whitespace &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix HEAD^ &&
+		printf "one \n" >expect &&
+		test_cmp expect file
+	)
+'
+
+test_expect_success 'interactive rebase fixes whitespace in added files' '
+	test_create_repo added &&
+	(
+		cd added &&
+		test_write_lines base >file &&
+		git add file && git commit -m base &&
+		printf "new file with whitespace \n" >new-file &&
+		git add new-file && git commit -m add &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix HEAD^ &&
+		printf "new file with whitespace\n" >expect &&
+		test_cmp expect new-file
+	)
+'
+
 sed -e's/Z//' >beginning <<EOF
 a
 		    Z
-- 
gitgitgadget
Previous: Alessio Attilio via GitGitGadget
Message 5 of 5 in “rebase: support --whitespace=fix with --interactive”
  1. 0/4 rebase: support --whitespace=fix with --interactiveAlessio Attilio via GitGitGadget, Nov 30, 2026
  2. 1/4 xdiff: support transformed records in merge matchingAlessio Attilio via GitGitGadget, Nov 30, 2026
  3. 2/4 merge-ort: fix whitespace in replayed changesAlessio Attilio via GitGitGadget, Nov 30, 2026
  4. 3/4 rebase: route whitespace fixes through the selected backendAlessio Attilio via GitGitGadget, Nov 30, 2026
  5. 4/4 rebase: test whitespace fixes with the merge backendAlessio Attilio via GitGitGadget, Nov 30, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.