Skip to content

Commit dfbf393

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4 test: newline handling
P4 stores newlines in the depos as \n. By default, git does this too, both on unix and windows. Test to make sure that this stays true. Both git and p4 have mechanisms to use \r\n in the working directory. Exercise these. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7f0e596 commit dfbf393

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

t/t9802-git-p4-filetype.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,123 @@ test_expect_success 'start p4d' '
88
start_p4d
99
'
1010

11+
#
12+
# This series of tests checks newline handling Both p4 and
13+
# git store newlines as \n, and have options to choose how
14+
# newlines appear in checked-out files.
15+
#
16+
test_expect_success 'p4 client newlines, unix' '
17+
(
18+
cd "$cli" &&
19+
p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
20+
printf "unix\ncrlf\n" >f-unix &&
21+
printf "unix\r\ncrlf\r\n" >f-unix-as-crlf &&
22+
p4 add -t text f-unix &&
23+
p4 submit -d f-unix &&
24+
25+
# LineEnd: unix; should be no change after sync
26+
cp f-unix f-unix-orig &&
27+
p4 sync -f &&
28+
test_cmp f-unix-orig f-unix &&
29+
30+
# make sure stored in repo as unix newlines
31+
# use sed to eat python-appened newline
32+
p4 -G print //depot/f-unix | marshal_dump data 2 |\
33+
sed \$d >f-unix-p4-print &&
34+
test_cmp f-unix-orig f-unix-p4-print &&
35+
36+
# switch to win, make sure lf -> crlf
37+
p4 client -o | sed "/LineEnd/s/:.*/:win/" | p4 client -i &&
38+
p4 sync -f &&
39+
test_cmp f-unix-as-crlf f-unix
40+
)
41+
'
42+
43+
test_expect_success 'p4 client newlines, win' '
44+
(
45+
cd "$cli" &&
46+
p4 client -o | sed "/LineEnd/s/:.*/:win/" | p4 client -i &&
47+
printf "win\r\ncrlf\r\n" >f-win &&
48+
printf "win\ncrlf\n" >f-win-as-lf &&
49+
p4 add -t text f-win &&
50+
p4 submit -d f-win &&
51+
52+
# LineEnd: win; should be no change after sync
53+
cp f-win f-win-orig &&
54+
p4 sync -f &&
55+
test_cmp f-win-orig f-win &&
56+
57+
# make sure stored in repo as unix newlines
58+
# use sed to eat python-appened newline
59+
p4 -G print //depot/f-win | marshal_dump data 2 |\
60+
sed \$d >f-win-p4-print &&
61+
test_cmp f-win-as-lf f-win-p4-print &&
62+
63+
# switch to unix, make sure lf -> crlf
64+
p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
65+
p4 sync -f &&
66+
test_cmp f-win-as-lf f-win
67+
)
68+
'
69+
70+
test_expect_success 'ensure blobs store only lf newlines' '
71+
test_when_finished cleanup_git &&
72+
(
73+
cd "$git" &&
74+
git init &&
75+
git p4 sync //depot@all &&
76+
77+
# verify the files in .git are stored only with newlines
78+
o=$(git ls-tree p4/master -- f-unix | cut -f1 | cut -d\ -f3) &&
79+
git cat-file blob $o >f-unix-blob &&
80+
test_cmp "$cli"/f-unix-orig f-unix-blob &&
81+
82+
o=$(git ls-tree p4/master -- f-win | cut -f1 | cut -d\ -f3) &&
83+
git cat-file blob $o >f-win-blob &&
84+
test_cmp "$cli"/f-win-as-lf f-win-blob &&
85+
86+
rm f-unix-blob f-win-blob
87+
)
88+
'
89+
90+
test_expect_success 'gitattributes setting eol=lf produces lf newlines' '
91+
test_when_finished cleanup_git &&
92+
(
93+
# checkout the files and make sure core.eol works as planned
94+
cd "$git" &&
95+
git init &&
96+
echo "* eol=lf" >.gitattributes &&
97+
git p4 sync //depot@all &&
98+
git checkout master &&
99+
test_cmp "$cli"/f-unix-orig f-unix &&
100+
test_cmp "$cli"/f-win-as-lf f-win
101+
)
102+
'
103+
104+
test_expect_success 'gitattributes setting eol=crlf produces crlf newlines' '
105+
test_when_finished cleanup_git &&
106+
(
107+
# checkout the files and make sure core.eol works as planned
108+
cd "$git" &&
109+
git init &&
110+
echo "* eol=crlf" >.gitattributes &&
111+
git p4 sync //depot@all &&
112+
git checkout master &&
113+
test_cmp "$cli"/f-unix-as-crlf f-unix &&
114+
test_cmp "$cli"/f-win-orig f-win
115+
)
116+
'
117+
118+
test_expect_success 'crlf cleanup' '
119+
(
120+
cd "$cli" &&
121+
rm f-unix-orig f-unix-as-crlf &&
122+
rm f-win-orig f-win-as-lf &&
123+
p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
124+
p4 sync -f
125+
)
126+
'
127+
11128
test_expect_success 'utf-16 file create' '
12129
(
13130
cd "$cli" &&

0 commit comments

Comments
 (0)