Mercurial > hg
annotate tests/test-import-eol @ 10102:1720d70cd6d4
patch: implement patch.eol=auto mode
EOLs in patched files are restored to their original value after
patching. We use the first EOL found in the file, files with
inconsistent EOLs will thus be normalized during this process.
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Sun, 20 Dec 2009 17:18:04 +0100 |
parents | 6c9dce20ed70 |
children | d8214e944b84 |
rev | line source |
---|---|
8810
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
1 #!/bin/sh |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
2 |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
3 cat > makepatch.py <<EOF |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
4 f = file('eol.diff', 'wb') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
5 w = f.write |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
6 w('test message\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
7 w('diff --git a/a b/a\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
8 w('--- a/a\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
9 w('+++ b/a\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
10 w('@@ -1,5 +1,5 @@\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
11 w(' a\n') |
8817
6c9dce20ed70
Fixed patch.eol bug that truncated all patched lines to one character
Colin Caughie <c.caughie@indigovision.com>
parents:
8810
diff
changeset
|
12 w('-bbb\r\n') |
6c9dce20ed70
Fixed patch.eol bug that truncated all patched lines to one character
Colin Caughie <c.caughie@indigovision.com>
parents:
8810
diff
changeset
|
13 w('+yyyy\r\n') |
6c9dce20ed70
Fixed patch.eol bug that truncated all patched lines to one character
Colin Caughie <c.caughie@indigovision.com>
parents:
8810
diff
changeset
|
14 w(' cc\r\n') |
6c9dce20ed70
Fixed patch.eol bug that truncated all patched lines to one character
Colin Caughie <c.caughie@indigovision.com>
parents:
8810
diff
changeset
|
15 w(' \n') |
8810
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
16 w(' d\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
17 w('-e\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
18 w('\ No newline at end of file\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
19 w('+z\r\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
20 w('\ No newline at end of file\r\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
21 EOF |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
22 |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
23 hg init repo |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
24 cd repo |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
25 echo '\.diff' > .hgignore |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
26 |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
27 # Test different --eol values |
8817
6c9dce20ed70
Fixed patch.eol bug that truncated all patched lines to one character
Colin Caughie <c.caughie@indigovision.com>
parents:
8810
diff
changeset
|
28 python -c 'file("a", "wb").write("a\nbbb\ncc\n\nd\ne")' |
8810
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
29 hg ci -Am adda |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
30 python ../makepatch.py |
10102
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
31 |
8810
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
32 echo % invalid eol |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
33 hg --config patch.eol='LFCR' import eol.diff |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
34 hg revert -a |
10102
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
35 |
8810
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
36 echo % force LF |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
37 hg --traceback --config patch.eol='LF' import eol.diff |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
38 python -c 'print repr(file("a","rb").read())' |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
39 hg st |
10102
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
40 |
8810
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
41 echo % force CRLF |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
42 hg up -C 0 |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
43 hg --traceback --config patch.eol='CRLF' import eol.diff |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
44 python -c 'print repr(file("a","rb").read())' |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
45 hg st |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
46 |
10102
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
47 echo % auto EOL on LF file |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
48 hg up -C 0 |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
49 hg --traceback --config patch.eol='auto' import eol.diff |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
50 python -c 'print repr(file("a","rb").read())' |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
51 hg st |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
52 |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
53 echo % auto EOL on CRLF file |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
54 python -c 'file("a", "wb").write("a\r\nbbb\r\ncc\r\n\r\nd\r\ne")' |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
55 hg commit -m 'switch EOLs in a' |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
56 hg --traceback --config patch.eol='auto' import eol.diff |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
57 python -c 'print repr(file("a","rb").read())' |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
58 hg st |
1720d70cd6d4
patch: implement patch.eol=auto mode
Martin Geisler <mg@lazybytes.net>
parents:
8817
diff
changeset
|
59 |
8810
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
60 # Test --eol and binary patches |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
61 python -c 'file("b", "wb").write("a\x00\nb")' |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
62 hg ci -Am addb |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
63 python -c 'file("b", "wb").write("a\x00\nc")' |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
64 hg diff --git > bin.diff |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
65 hg revert --no-backup b |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
66 echo % binary patch with --eol |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
67 hg import --config patch.eol='CRLF' -m changeb bin.diff |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
68 python -c 'print repr(file("b","rb").read())' |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
69 hg st |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
70 cd .. |