From: Alessio Attilio <atti…@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 <atti…@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