Mercurial > hg-stable
annotate tests/test-import-eol @ 8810:ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
The intent is to fix many issues involving patching when win32ext is enabled.
With win32ext, the working directory and repository files EOLs are not the same
which means that patches made on a non-win32ext host do not apply cleanly
because of EOLs discrepancies. A theorically correct approach would be
transform either the patched file or the patch content with the
encoding/decoding filters used by win32ext. This solution is tricky to
implement and invasive, instead we prefer to address the win32ext case, by
offering a way to ignore input EOLs when patching and rewriting them when
saving the patched result.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Mon, 15 Jun 2009 00:03:26 +0200 |
parents | |
children | 6c9dce20ed70 |
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') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
12 w('-b\r\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
13 w('+y\r\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
14 w(' c\r\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
15 w(' d\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
16 w('-e\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
17 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
|
18 w('+z\r\n') |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
19 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
|
20 EOF |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
21 |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
22 hg init repo |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
23 cd repo |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
24 echo '\.diff' > .hgignore |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
25 |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
26 # Test different --eol values |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
27 python -c 'file("a", "wb").write("a\nb\nc\nd\ne")' |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
28 hg ci -Am adda |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
29 python ../makepatch.py |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
30 echo % invalid eol |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
31 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
|
32 hg revert -a |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
33 echo % force LF |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
34 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
|
35 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
|
36 hg st |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
37 echo % force CRLF |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
38 hg up -C 0 |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
39 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
|
40 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
|
41 hg st |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
42 |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
43 # Test --eol and binary patches |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
44 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
|
45 hg ci -Am addb |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
46 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
|
47 hg diff --git > bin.diff |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
48 hg revert --no-backup b |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
49 echo % binary patch with --eol |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
50 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
|
51 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
|
52 hg st |
ac92775b3b80
Add patch.eol to ignore EOLs when patching (issue1019)
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
53 cd .. |