Skip to content

Commit 59f5ced

Browse files
bjornggitster
authored andcommitted
t3417: Add test cases for "rebase --whitespace=fix"
The command "git rebase --whitespace=fix HEAD~<N>" is supposed to only clean up trailing whitespace, and the expectation is that it cannot fail. Unfortunately, if one commit adds a blank line at the end of a file and a subsequent commit adds more non-blank lines after the blank line, "git apply" (used indirectly by "git rebase") will fail to apply the patch of the second commit. Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c1376c1 commit 59f5ced

1 file changed

Lines changed: 126 additions & 0 deletions

File tree

t/t3417-rebase-whitespace-fix.sh

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/bin/sh
2+
3+
test_description='git rebase --whitespace=fix
4+
5+
This test runs git rebase --whitespace=fix and make sure that it works.
6+
'
7+
8+
. ./test-lib.sh
9+
10+
# prepare initial revision of "file" with a blank line at the end
11+
cat >file <<EOF
12+
a
13+
b
14+
c
15+
16+
EOF
17+
18+
# expected contents in "file" after rebase
19+
cat >expect-first <<EOF
20+
a
21+
b
22+
c
23+
EOF
24+
25+
# prepare second revision of "file"
26+
cat >second <<EOF
27+
a
28+
b
29+
c
30+
31+
d
32+
e
33+
f
34+
35+
36+
37+
38+
EOF
39+
40+
# expected contents in second revision after rebase
41+
cat >expect-second <<EOF
42+
a
43+
b
44+
c
45+
46+
d
47+
e
48+
f
49+
EOF
50+
51+
test_expect_success 'blank line at end of file; extend at end of file' '
52+
git commit --allow-empty -m "Initial empty commit" &&
53+
git add file && git commit -m first &&
54+
mv second file &&
55+
git add file && git commit -m second &&
56+
git rebase --whitespace=fix HEAD^^ &&
57+
git diff --exit-code HEAD^:file expect-first &&
58+
test_cmp file expect-second
59+
'
60+
61+
# prepare third revision of "file"
62+
sed -e's/Z//' >third <<EOF
63+
a
64+
b
65+
c
66+
67+
d
68+
e
69+
f
70+
Z
71+
Z
72+
h
73+
i
74+
j
75+
k
76+
l
77+
EOF
78+
79+
sed -e's/ //g' <third >expect-third
80+
81+
test_expect_success 'two blanks line at end of file; extend at end of file' '
82+
cp third file && git add file && git commit -m third &&
83+
git rebase --whitespace=fix HEAD^^ &&
84+
git diff --exit-code HEAD^:file expect-second &&
85+
test_cmp file expect-third
86+
'
87+
88+
test_expect_success 'same, but do not remove trailing spaces' '
89+
git config core.whitespace "-blank-at-eol" &&
90+
git reset --hard HEAD^ &&
91+
cp third file && git add file && git commit -m third &&
92+
git rebase --whitespace=fix HEAD^^
93+
git diff --exit-code HEAD^:file expect-second &&
94+
test_cmp file third
95+
'
96+
97+
sed -e's/Z//' >beginning <<EOF
98+
a
99+
Z
100+
Z
101+
EOF
102+
103+
cat >expect-beginning <<EOF
104+
a
105+
106+
107+
1
108+
2
109+
3
110+
4
111+
5
112+
EOF
113+
114+
test_expect_success 'at beginning of file' '
115+
git config core.whitespace "blank-at-eol" &&
116+
cp beginning file &&
117+
git commit -m beginning file &&
118+
for i in 1 2 3 4 5; do
119+
echo $i
120+
done >> file &&
121+
git commit -m more file &&
122+
git rebase --whitespace=fix HEAD^^ &&
123+
test_cmp file expect-beginning
124+
'
125+
126+
test_done

0 commit comments

Comments
 (0)