Show More
This diff has been collapsed as it changes many lines, (543 lines changed) Show them Hide them | |||||
@@ -1,180 +1,385 b'' | |||||
1 | #!/bin/sh |
|
1 | Test EOL extension | |
2 |
|
2 | |||
3 | cat > $HGRCPATH <<EOF |
|
3 | $ cat > $HGRCPATH <<EOF | |
4 | [diff] |
|
4 | > [diff] | |
5 | git = True |
|
5 | > git = True | |
6 | EOF |
|
6 | > EOF | |
|
7 | ||||
|
8 | Set up helpers | |||
7 |
|
9 | |||
8 | cat > switch-eol.py <<EOF |
|
10 | $ cat > switch-eol.py <<EOF | |
9 | import sys |
|
11 | > import sys | |
10 |
|
12 | > try: | ||
11 | try: |
|
13 | > import os, msvcrt | |
12 | import os, msvcrt |
|
14 | > msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) | |
13 |
msvcrt.setmode(sys.std |
|
15 | > msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) | |
14 | msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
|
16 | > except ImportError: | |
15 | except ImportError: |
|
17 | > pass | |
16 | pass |
|
18 | > (old, new) = sys.argv[1] == 'LF' and ('\n', '\r\n') or ('\r\n', '\n') | |
|
19 | > print "%% switching encoding from %r to %r" % (old, new) | |||
|
20 | > for path in sys.argv[2:]: | |||
|
21 | > data = file(path, 'rb').read() | |||
|
22 | > data = data.replace(old, new) | |||
|
23 | > file(path, 'wb').write(data) | |||
|
24 | > EOF | |||
17 |
|
25 | |||
18 | (old, new) = sys.argv[1] == 'LF' and ('\n', '\r\n') or ('\r\n', '\n') |
|
26 | $ seteol () { | |
19 | print "%% switching encoding from %r to %r" % (old, new) |
|
27 | > if [ $1 = "LF" ]; then | |
20 | for path in sys.argv[2:]: |
|
28 | > EOL='\n' | |
21 | data = file(path, 'rb').read() |
|
29 | > else | |
22 | data = data.replace(old, new) |
|
30 | > EOL='\r\n' | |
23 | file(path, 'wb').write(data) |
|
31 | > fi | |
24 | EOF |
|
32 | > } | |
25 |
|
33 | |||
26 | seteol () { |
|
34 | $ makerepo () { | |
27 | if [ $1 = "LF" ]; then |
|
35 | > seteol $1 | |
28 | EOL='\n' |
|
36 | > echo "% setup $1 repository" | |
29 | else |
|
37 | > hg init repo | |
30 | EOL='\r\n' |
|
38 | > cd repo | |
31 | fi |
|
39 | > cat > .hgeol <<EOF | |
32 | } |
|
40 | > [repository] | |
33 |
|
41 | > native = $1 | ||
34 | makerepo () { |
|
42 | > [patterns] | |
35 | seteol $1 |
|
43 | > mixed.txt = BIN | |
36 | echo "% setup $1 repository" |
|
44 | > **.txt = native | |
37 | hg init repo |
|
45 | > EOF | |
38 | cd repo |
|
46 | > printf "first${EOL}second${EOL}third${EOL}" > a.txt | |
39 |
|
47 | > hg commit --addremove -m 'checkin' | ||
40 | cat > .hgeol <<EOF |
|
48 | > echo | |
41 | [repository] |
|
49 | > cd .. | |
42 | native = $1 |
|
50 | > } | |
43 |
|
51 | |||
44 | [patterns] |
|
52 | $ dotest () { | |
45 | mixed.txt = BIN |
|
53 | > seteol $1 | |
46 | **.txt = native |
|
54 | > echo "% hg clone repo repo-$1" | |
47 | EOF |
|
55 | > hg clone --noupdate repo repo-$1 | |
48 |
|
56 | > cd repo-$1 | ||
49 | printf "first${EOL}second${EOL}third${EOL}" > a.txt |
|
57 | > cat > .hg/hgrc <<EOF | |
50 | hg commit --addremove -m 'checkin' |
|
58 | > [extensions] | |
51 | echo |
|
59 | > eol = | |
52 | cd .. |
|
60 | > [eol] | |
53 | } |
|
61 | > native = $1 | |
54 |
|
62 | > EOF | ||
55 | dotest () { |
|
63 | > hg update | |
56 | seteol $1 |
|
64 | > echo '% printrepr.py a.txt' | |
57 | echo "% hg clone repo repo-$1" |
|
65 | > python $TESTDIR/printrepr.py < a.txt | |
58 | hg clone --noupdate repo repo-$1 |
|
66 | > echo '% hg cat a.txt' | |
59 | cd repo-$1 |
|
67 | > hg cat a.txt | python $TESTDIR/printrepr.py | |
60 |
|
68 | > printf "fourth${EOL}" >> a.txt | ||
61 | cat > .hg/hgrc <<EOF |
|
69 | > echo '% printrepr.py a.txt' | |
62 | [extensions] |
|
70 | > python $TESTDIR/printrepr.py < a.txt | |
63 | eol = |
|
71 | > hg diff | python $TESTDIR/printrepr.py | |
|
72 | > python ../switch-eol.py $1 a.txt | |||
|
73 | > echo '% hg diff only reports a single changed line:' | |||
|
74 | > hg diff | python $TESTDIR/printrepr.py | |||
|
75 | > echo "% reverting back to $1 format" | |||
|
76 | > hg revert a.txt | |||
|
77 | > python $TESTDIR/printrepr.py < a.txt | |||
|
78 | > printf "first\r\nsecond\n" > mixed.txt | |||
|
79 | > hg add mixed.txt | |||
|
80 | > echo "% hg commit of inconsistent .txt file marked as binary (should work)" | |||
|
81 | > hg commit -m 'binary file' | |||
|
82 | > echo "% hg commit of inconsistent .txt file marked as native (should fail)" | |||
|
83 | > printf "first\nsecond\r\nthird\nfourth\r\n" > a.txt | |||
|
84 | > hg commit -m 'inconsistent file' | |||
|
85 | > echo "% hg commit --config eol.only-consistent=False (should work)" | |||
|
86 | > hg commit --config eol.only-consistent=False -m 'inconsistent file' | |||
|
87 | > echo "% hg commit of binary .txt file marked as native (binary files always okay)" | |||
|
88 | > printf "first${EOL}\0${EOL}third${EOL}" > a.txt | |||
|
89 | > hg commit -m 'binary file' | |||
|
90 | > cd .. | |||
|
91 | > rm -r repo-$1 | |||
|
92 | > } | |||
64 |
|
93 | |||
65 | [eol] |
|
94 | $ makemixedrepo () { | |
66 | native = $1 |
|
95 | > echo | |
67 | EOF |
|
96 | > echo "# setup $1 repository" | |
68 |
|
97 | > hg init mixed | ||
69 | hg update |
|
98 | > cd mixed | |
70 | echo '% printrepr.py a.txt' |
|
99 | > printf "foo\r\nbar\r\nbaz\r\n" > win.txt | |
71 | python $TESTDIR/printrepr.py < a.txt |
|
100 | > printf "foo\nbar\nbaz\n" > unix.txt | |
72 | echo '% hg cat a.txt' |
|
101 | > #printf "foo\r\nbar\nbaz\r\n" > mixed.txt | |
73 | hg cat a.txt | python $TESTDIR/printrepr.py |
|
102 | > hg commit --addremove -m 'created mixed files' | |
|
103 | > echo "# setting repository-native EOLs to $1" | |||
|
104 | > cat > .hgeol <<EOF | |||
|
105 | > [repository] | |||
|
106 | > native = $1 | |||
|
107 | > [patterns] | |||
|
108 | > **.txt = native | |||
|
109 | > EOF | |||
|
110 | > hg commit --addremove -m 'added .hgeol' | |||
|
111 | > cd .. | |||
|
112 | > } | |||
74 |
|
113 | |||
75 | printf "fourth${EOL}" >> a.txt |
|
114 | $ testmixed () { | |
76 | echo '% printrepr.py a.txt' |
|
115 | > echo | |
77 | python $TESTDIR/printrepr.py < a.txt |
|
116 | > echo "% hg clone mixed mixed-$1" | |
78 | hg diff | python $TESTDIR/printrepr.py |
|
117 | > hg clone mixed mixed-$1 | |
|
118 | > cd mixed-$1 | |||
|
119 | > echo '% hg status (eol extension not yet activated)' | |||
|
120 | > hg status | |||
|
121 | > cat > .hg/hgrc <<EOF | |||
|
122 | > [extensions] | |||
|
123 | > eol = | |||
|
124 | > [eol] | |||
|
125 | > native = $1 | |||
|
126 | > EOF | |||
|
127 | > echo '% hg status (eol activated)' | |||
|
128 | > hg status | |||
|
129 | > echo '% hg commit' | |||
|
130 | > hg commit -m 'synchronized EOLs' | |||
|
131 | > echo '% hg status' | |||
|
132 | > hg status | |||
|
133 | > cd .. | |||
|
134 | > rm -r mixed-$1 | |||
|
135 | > } | |||
79 |
|
136 | |||
80 | python ../switch-eol.py $1 a.txt |
|
137 | Basic tests | |
81 | echo '% hg diff only reports a single changed line:' |
|
|||
82 | hg diff | python $TESTDIR/printrepr.py |
|
|||
83 |
|
||||
84 | echo "% reverting back to $1 format" |
|
|||
85 | hg revert a.txt |
|
|||
86 | python $TESTDIR/printrepr.py < a.txt |
|
|||
87 |
|
138 | |||
88 | printf "first\r\nsecond\n" > mixed.txt |
|
139 | $ makerepo LF | |
89 | hg add mixed.txt |
|
140 | % setup LF repository | |
90 | echo "% hg commit of inconsistent .txt file marked as binary (should work)" |
|
141 | adding .hgeol | |
91 | hg commit -m 'binary file' |
|
142 | adding a.txt | |
92 |
|
143 | |||
93 | echo "% hg commit of inconsistent .txt file marked as native (should fail)" |
|
144 | $ dotest LF | |
94 | printf "first\nsecond\r\nthird\nfourth\r\n" > a.txt |
|
145 | % hg clone repo repo-LF | |
95 | hg commit -m 'inconsistent file' |
|
146 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
96 |
|
147 | % printrepr.py a.txt | ||
97 | echo "% hg commit --config eol.only-consistent=False (should work)" |
|
148 | first | |
98 | hg commit --config eol.only-consistent=False -m 'inconsistent file' |
|
149 | second | |
99 |
|
150 | third | ||
100 | echo "% hg commit of binary .txt file marked as native (binary files always okay)" |
|
151 | % hg cat a.txt | |
101 | printf "first${EOL}\0${EOL}third${EOL}" > a.txt |
|
152 | first | |
102 | hg commit -m 'binary file' |
|
153 | second | |
103 |
|
154 | third | ||
104 | cd .. |
|
155 | % printrepr.py a.txt | |
105 | rm -r repo-$1 |
|
156 | first | |
106 | } |
|
157 | second | |
107 |
|
158 | third | ||
108 | makerepo LF |
|
159 | fourth | |
109 | dotest LF |
|
160 | diff --git a/a.txt b/a.txt | |
110 | dotest CRLF |
|
161 | --- a/a.txt | |
111 | rm -r repo |
|
162 | +++ b/a.txt | |
112 |
|
163 | @@ -1,3 +1,4 @@ | ||
113 | makerepo CRLF |
|
164 | first | |
114 | dotest LF |
|
165 | second | |
115 | dotest CRLF |
|
166 | third | |
116 | rm -r repo |
|
167 | +fourth | |
117 |
|
168 | % switching encoding from '\n' to '\r\n' | ||
118 |
|
169 | % hg diff only reports a single changed line: | ||
119 | makemixedrepo () { |
|
170 | diff --git a/a.txt b/a.txt | |
120 | echo |
|
171 | --- a/a.txt | |
121 | echo "# setup $1 repository" |
|
172 | +++ b/a.txt | |
122 | hg init mixed |
|
173 | @@ -1,3 +1,4 @@ | |
123 | cd mixed |
|
174 | first | |
124 | printf "foo\r\nbar\r\nbaz\r\n" > win.txt |
|
175 | second | |
125 | printf "foo\nbar\nbaz\n" > unix.txt |
|
176 | third | |
126 | #printf "foo\r\nbar\nbaz\r\n" > mixed.txt |
|
177 | +fourth | |
127 |
|
178 | % reverting back to LF format | ||
128 | hg commit --addremove -m 'created mixed files' |
|
179 | first | |
129 |
|
180 | second | ||
130 | echo "# setting repository-native EOLs to $1" |
|
181 | third | |
131 | cat > .hgeol <<EOF |
|
182 | % hg commit of inconsistent .txt file marked as binary (should work) | |
132 | [repository] |
|
183 | % hg commit of inconsistent .txt file marked as native (should fail) | |
133 | native = $1 |
|
184 | abort: inconsistent newline style in a.txt | |
|
185 | ||||
|
186 | % hg commit --config eol.only-consistent=False (should work) | |||
|
187 | % hg commit of binary .txt file marked as native (binary files always okay) | |||
|
188 | $ dotest CRLF | |||
|
189 | % hg clone repo repo-CRLF | |||
|
190 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
191 | % printrepr.py a.txt | |||
|
192 | first\r | |||
|
193 | second\r | |||
|
194 | third\r | |||
|
195 | % hg cat a.txt | |||
|
196 | first | |||
|
197 | second | |||
|
198 | third | |||
|
199 | % printrepr.py a.txt | |||
|
200 | first\r | |||
|
201 | second\r | |||
|
202 | third\r | |||
|
203 | fourth\r | |||
|
204 | diff --git a/a.txt b/a.txt | |||
|
205 | --- a/a.txt | |||
|
206 | +++ b/a.txt | |||
|
207 | @@ -1,3 +1,4 @@ | |||
|
208 | first | |||
|
209 | second | |||
|
210 | third | |||
|
211 | +fourth | |||
|
212 | % switching encoding from '\r\n' to '\n' | |||
|
213 | % hg diff only reports a single changed line: | |||
|
214 | diff --git a/a.txt b/a.txt | |||
|
215 | --- a/a.txt | |||
|
216 | +++ b/a.txt | |||
|
217 | @@ -1,3 +1,4 @@ | |||
|
218 | first | |||
|
219 | second | |||
|
220 | third | |||
|
221 | +fourth | |||
|
222 | % reverting back to CRLF format | |||
|
223 | first\r | |||
|
224 | second\r | |||
|
225 | third\r | |||
|
226 | % hg commit of inconsistent .txt file marked as binary (should work) | |||
|
227 | % hg commit of inconsistent .txt file marked as native (should fail) | |||
|
228 | abort: inconsistent newline style in a.txt | |||
|
229 | ||||
|
230 | % hg commit --config eol.only-consistent=False (should work) | |||
|
231 | % hg commit of binary .txt file marked as native (binary files always okay) | |||
|
232 | $ rm -r repo | |||
|
233 | $ makerepo CRLF | |||
|
234 | % setup CRLF repository | |||
|
235 | adding .hgeol | |||
|
236 | adding a.txt | |||
|
237 | ||||
|
238 | $ dotest LF | |||
|
239 | % hg clone repo repo-LF | |||
|
240 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
241 | % printrepr.py a.txt | |||
|
242 | first | |||
|
243 | second | |||
|
244 | third | |||
|
245 | % hg cat a.txt | |||
|
246 | first\r | |||
|
247 | second\r | |||
|
248 | third\r | |||
|
249 | % printrepr.py a.txt | |||
|
250 | first | |||
|
251 | second | |||
|
252 | third | |||
|
253 | fourth | |||
|
254 | diff --git a/a.txt b/a.txt | |||
|
255 | --- a/a.txt | |||
|
256 | +++ b/a.txt | |||
|
257 | @@ -1,3 +1,4 @@ | |||
|
258 | first\r | |||
|
259 | second\r | |||
|
260 | third\r | |||
|
261 | +fourth\r | |||
|
262 | % switching encoding from '\n' to '\r\n' | |||
|
263 | % hg diff only reports a single changed line: | |||
|
264 | diff --git a/a.txt b/a.txt | |||
|
265 | --- a/a.txt | |||
|
266 | +++ b/a.txt | |||
|
267 | @@ -1,3 +1,4 @@ | |||
|
268 | first\r | |||
|
269 | second\r | |||
|
270 | third\r | |||
|
271 | +fourth\r | |||
|
272 | % reverting back to LF format | |||
|
273 | first | |||
|
274 | second | |||
|
275 | third | |||
|
276 | % hg commit of inconsistent .txt file marked as binary (should work) | |||
|
277 | % hg commit of inconsistent .txt file marked as native (should fail) | |||
|
278 | abort: inconsistent newline style in a.txt | |||
|
279 | ||||
|
280 | % hg commit --config eol.only-consistent=False (should work) | |||
|
281 | % hg commit of binary .txt file marked as native (binary files always okay) | |||
|
282 | $ dotest CRLF | |||
|
283 | % hg clone repo repo-CRLF | |||
|
284 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
285 | % printrepr.py a.txt | |||
|
286 | first\r | |||
|
287 | second\r | |||
|
288 | third\r | |||
|
289 | % hg cat a.txt | |||
|
290 | first\r | |||
|
291 | second\r | |||
|
292 | third\r | |||
|
293 | % printrepr.py a.txt | |||
|
294 | first\r | |||
|
295 | second\r | |||
|
296 | third\r | |||
|
297 | fourth\r | |||
|
298 | diff --git a/a.txt b/a.txt | |||
|
299 | --- a/a.txt | |||
|
300 | +++ b/a.txt | |||
|
301 | @@ -1,3 +1,4 @@ | |||
|
302 | first\r | |||
|
303 | second\r | |||
|
304 | third\r | |||
|
305 | +fourth\r | |||
|
306 | % switching encoding from '\r\n' to '\n' | |||
|
307 | % hg diff only reports a single changed line: | |||
|
308 | diff --git a/a.txt b/a.txt | |||
|
309 | --- a/a.txt | |||
|
310 | +++ b/a.txt | |||
|
311 | @@ -1,3 +1,4 @@ | |||
|
312 | first\r | |||
|
313 | second\r | |||
|
314 | third\r | |||
|
315 | +fourth\r | |||
|
316 | % reverting back to CRLF format | |||
|
317 | first\r | |||
|
318 | second\r | |||
|
319 | third\r | |||
|
320 | % hg commit of inconsistent .txt file marked as binary (should work) | |||
|
321 | % hg commit of inconsistent .txt file marked as native (should fail) | |||
|
322 | abort: inconsistent newline style in a.txt | |||
|
323 | ||||
|
324 | % hg commit --config eol.only-consistent=False (should work) | |||
|
325 | % hg commit of binary .txt file marked as native (binary files always okay) | |||
|
326 | $ rm -r repo | |||
134 |
|
327 | |||
135 | [patterns] |
|
328 | Mixed tests | |
136 | **.txt = native |
|
|||
137 | EOF |
|
|||
138 | hg commit --addremove -m 'added .hgeol' |
|
|||
139 | cd .. |
|
|||
140 | } |
|
|||
141 |
|
||||
142 | testmixed () { |
|
|||
143 | echo |
|
|||
144 | echo "% hg clone mixed mixed-$1" |
|
|||
145 | hg clone mixed mixed-$1 |
|
|||
146 | cd mixed-$1 |
|
|||
147 |
|
||||
148 | echo '% hg status (eol extension not yet activated)' |
|
|||
149 | hg status |
|
|||
150 |
|
||||
151 | cat > .hg/hgrc <<EOF |
|
|||
152 | [extensions] |
|
|||
153 | eol = |
|
|||
154 |
|
329 | |||
155 | [eol] |
|
330 | $ makemixedrepo LF | |
156 | native = $1 |
|
331 | ||
157 | EOF |
|
332 | # setup LF repository | |
158 |
|
333 | adding unix.txt | ||
159 | echo '% hg status (eol activated)' |
|
334 | adding win.txt | |
160 | hg status |
|
335 | # setting repository-native EOLs to LF | |
161 | echo '% hg commit' |
|
336 | adding .hgeol | |
162 | hg commit -m 'synchronized EOLs' |
|
337 | $ testmixed LF | |
163 |
|
338 | |||
164 | echo '% hg status' |
|
339 | % hg clone mixed mixed-LF | |
165 | hg status |
|
340 | updating to branch default | |
166 |
|
341 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved | ||
167 | cd .. |
|
342 | % hg status (eol extension not yet activated) | |
168 | rm -r mixed-$1 |
|
343 | % hg status (eol activated) | |
169 | } |
|
344 | M win.txt | |
170 |
|
345 | % hg commit | ||
171 | makemixedrepo LF |
|
346 | % hg status | |
172 | testmixed LF |
|
347 | $ testmixed CRLF | |
173 | testmixed CRLF |
|
348 | ||
174 | rm -r mixed |
|
349 | % hg clone mixed mixed-CRLF | |
175 |
|
350 | updating to branch default | ||
176 | makemixedrepo CRLF |
|
351 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
177 | testmixed LF |
|
352 | % hg status (eol extension not yet activated) | |
178 | testmixed CRLF |
|
353 | % hg status (eol activated) | |
179 | rm -r mixed |
|
354 | M win.txt | |
180 |
|
355 | % hg commit | ||
|
356 | % hg status | |||
|
357 | $ rm -r mixed | |||
|
358 | $ makemixedrepo CRLF | |||
|
359 | ||||
|
360 | # setup CRLF repository | |||
|
361 | adding unix.txt | |||
|
362 | adding win.txt | |||
|
363 | # setting repository-native EOLs to CRLF | |||
|
364 | adding .hgeol | |||
|
365 | $ testmixed LF | |||
|
366 | ||||
|
367 | % hg clone mixed mixed-LF | |||
|
368 | updating to branch default | |||
|
369 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
370 | % hg status (eol extension not yet activated) | |||
|
371 | % hg status (eol activated) | |||
|
372 | M unix.txt | |||
|
373 | % hg commit | |||
|
374 | % hg status | |||
|
375 | $ testmixed CRLF | |||
|
376 | ||||
|
377 | % hg clone mixed mixed-CRLF | |||
|
378 | updating to branch default | |||
|
379 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
380 | % hg status (eol extension not yet activated) | |||
|
381 | % hg status (eol activated) | |||
|
382 | M unix.txt | |||
|
383 | % hg commit | |||
|
384 | % hg status | |||
|
385 | $ rm -r mixed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now