comparison 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
comparison
equal deleted inserted replaced
8809:6fce36336e42 8810:ac92775b3b80
1 #!/bin/sh
2
3 cat > makepatch.py <<EOF
4 f = file('eol.diff', 'wb')
5 w = f.write
6 w('test message\n')
7 w('diff --git a/a b/a\n')
8 w('--- a/a\n')
9 w('+++ b/a\n')
10 w('@@ -1,5 +1,5 @@\n')
11 w(' a\n')
12 w('-b\r\n')
13 w('+y\r\n')
14 w(' c\r\n')
15 w(' d\n')
16 w('-e\n')
17 w('\ No newline at end of file\n')
18 w('+z\r\n')
19 w('\ No newline at end of file\r\n')
20 EOF
21
22 hg init repo
23 cd repo
24 echo '\.diff' > .hgignore
25
26 # Test different --eol values
27 python -c 'file("a", "wb").write("a\nb\nc\nd\ne")'
28 hg ci -Am adda
29 python ../makepatch.py
30 echo % invalid eol
31 hg --config patch.eol='LFCR' import eol.diff
32 hg revert -a
33 echo % force LF
34 hg --traceback --config patch.eol='LF' import eol.diff
35 python -c 'print repr(file("a","rb").read())'
36 hg st
37 echo % force CRLF
38 hg up -C 0
39 hg --traceback --config patch.eol='CRLF' import eol.diff
40 python -c 'print repr(file("a","rb").read())'
41 hg st
42
43 # Test --eol and binary patches
44 python -c 'file("b", "wb").write("a\x00\nb")'
45 hg ci -Am addb
46 python -c 'file("b", "wb").write("a\x00\nc")'
47 hg diff --git > bin.diff
48 hg revert --no-backup b
49 echo % binary patch with --eol
50 hg import --config patch.eol='CRLF' -m changeb bin.diff
51 python -c 'print repr(file("b","rb").read())'
52 hg st
53 cd ..