| 1 |
$ cat > makepatch.py <<EOF |
| 2 |
> import sys |
| 3 |
> f = open(sys.argv[2], 'wb') |
| 4 |
> w = f.write |
| 5 |
> w(b'test message\n') |
| 6 |
> w(b'diff --git a/a b/a\n') |
| 7 |
> w(b'--- a/a\n') |
| 8 |
> w(b'+++ b/a\n') |
| 9 |
> w(b'@@ -1,5 +1,5 @@\n') |
| 10 |
> w(b' a\n') |
| 11 |
> w(b'-bbb\r\n') |
| 12 |
> w(b'+yyyy\r\n') |
| 13 |
> w(b' cc\r\n') |
| 14 |
> w({'empty:lf': b' \n', |
| 15 |
> 'empty:crlf': b' \r\n', |
| 16 |
> 'empty:stripped-lf': b'\n', |
| 17 |
> 'empty:stripped-crlf': b'\r\n'}[sys.argv[1]]) |
| 18 |
> w(b' d\n') |
| 19 |
> w(b'-e\n') |
| 20 |
> w(b'\\\\ No newline at end of file\n') |
| 21 |
> w(b'+z\r\n') |
| 22 |
> w(b'\\\\ No newline at end of file\r\n') |
| 23 |
> EOF |
| 24 |
|
| 25 |
$ hg init repo |
| 26 |
$ cd repo |
| 27 |
$ echo '\.diff' > .hgignore |
| 28 |
|
| 29 |
|
| 30 |
Test different --eol values |
| 31 |
|
| 32 |
$ "$PYTHON" -c 'open("a", "wb").write(b"a\nbbb\ncc\n\nd\ne")' |
| 33 |
$ hg ci -Am adda |
| 34 |
adding .hgignore |
| 35 |
adding a |
| 36 |
$ "$PYTHON" ../makepatch.py empty:lf eol.diff |
| 37 |
$ "$PYTHON" ../makepatch.py empty:crlf eol-empty-crlf.diff |
| 38 |
$ "$PYTHON" ../makepatch.py empty:stripped-lf eol-empty-stripped-lf.diff |
| 39 |
$ "$PYTHON" ../makepatch.py empty:stripped-crlf eol-empty-stripped-crlf.diff |
| 40 |
|
| 41 |
invalid eol |
| 42 |
|
| 43 |
$ hg --config patch.eol='LFCR' import eol.diff |
| 44 |
applying eol.diff |
| 45 |
abort: unsupported line endings type: LFCR |
| 46 |
[255] |
| 47 |
$ hg revert -a |
| 48 |
|
| 49 |
|
| 50 |
force LF |
| 51 |
|
| 52 |
$ hg --traceback --config patch.eol='LF' import eol.diff |
| 53 |
applying eol.diff |
| 54 |
$ hg id |
| 55 |
9e4ef7b3d4af tip |
| 56 |
$ cat a |
| 57 |
a |
| 58 |
yyyy |
| 59 |
cc |
| 60 |
|
| 61 |
d |
| 62 |
e (no-eol) |
| 63 |
$ hg st |
| 64 |
|
| 65 |
(test empty-line variants: all of them should generate the same revision) |
| 66 |
|
| 67 |
$ hg up -qC 0 |
| 68 |
$ hg --config patch.eol='LF' import eol-empty-crlf.diff |
| 69 |
applying eol-empty-crlf.diff |
| 70 |
$ hg id |
| 71 |
9e4ef7b3d4af tip |
| 72 |
|
| 73 |
$ hg up -qC 0 |
| 74 |
$ hg --config patch.eol='LF' import eol-empty-stripped-lf.diff |
| 75 |
applying eol-empty-stripped-lf.diff |
| 76 |
$ hg id |
| 77 |
9e4ef7b3d4af tip |
| 78 |
|
| 79 |
$ hg up -qC 0 |
| 80 |
$ hg --config patch.eol='LF' import eol-empty-stripped-crlf.diff |
| 81 |
applying eol-empty-stripped-crlf.diff |
| 82 |
$ hg id |
| 83 |
9e4ef7b3d4af tip |
| 84 |
|
| 85 |
force CRLF |
| 86 |
|
| 87 |
$ hg up -C 0 |
| 88 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 89 |
$ hg --traceback --config patch.eol='CRLF' import eol.diff |
| 90 |
applying eol.diff |
| 91 |
$ cat a |
| 92 |
a\r (esc) |
| 93 |
yyyy\r (esc) |
| 94 |
cc\r (esc) |
| 95 |
\r (esc) |
| 96 |
d\r (esc) |
| 97 |
e (no-eol) |
| 98 |
$ hg st |
| 99 |
|
| 100 |
|
| 101 |
auto EOL on LF file |
| 102 |
|
| 103 |
$ hg up -C 0 |
| 104 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 105 |
$ hg --traceback --config patch.eol='auto' import eol.diff |
| 106 |
applying eol.diff |
| 107 |
$ cat a |
| 108 |
a |
| 109 |
yyyy |
| 110 |
cc |
| 111 |
|
| 112 |
d |
| 113 |
e (no-eol) |
| 114 |
$ hg st |
| 115 |
|
| 116 |
|
| 117 |
auto EOL on CRLF file |
| 118 |
|
| 119 |
$ "$PYTHON" -c 'open("a", "wb").write(b"a\r\nbbb\r\ncc\r\n\r\nd\r\ne")' |
| 120 |
$ hg commit -m 'switch EOLs in a' |
| 121 |
$ hg --traceback --config patch.eol='auto' import eol.diff |
| 122 |
applying eol.diff |
| 123 |
$ cat a |
| 124 |
a\r (esc) |
| 125 |
yyyy\r (esc) |
| 126 |
cc\r (esc) |
| 127 |
\r (esc) |
| 128 |
d\r (esc) |
| 129 |
e (no-eol) |
| 130 |
$ hg st |
| 131 |
|
| 132 |
|
| 133 |
auto EOL on new file or source without any EOL |
| 134 |
|
| 135 |
$ "$PYTHON" -c 'open("noeol", "wb").write(b"noeol")' |
| 136 |
$ hg add noeol |
| 137 |
$ hg commit -m 'add noeol' |
| 138 |
$ "$PYTHON" -c 'open("noeol", "wb").write(b"noeol\r\nnoeol\n")' |
| 139 |
$ "$PYTHON" -c 'open("neweol", "wb").write(b"neweol\nneweol\r\n")' |
| 140 |
$ hg add neweol |
| 141 |
$ hg diff --git > noeol.diff |
| 142 |
$ hg revert --no-backup noeol neweol |
| 143 |
$ rm neweol |
| 144 |
$ hg --traceback --config patch.eol='auto' import -m noeol noeol.diff |
| 145 |
applying noeol.diff |
| 146 |
$ cat noeol |
| 147 |
noeol\r (esc) |
| 148 |
noeol |
| 149 |
$ cat neweol |
| 150 |
neweol |
| 151 |
neweol\r (esc) |
| 152 |
$ hg st |
| 153 |
|
| 154 |
|
| 155 |
Test --eol and binary patches |
| 156 |
|
| 157 |
$ "$PYTHON" -c 'open("b", "wb").write(b"a\x00\nb\r\nd")' |
| 158 |
$ hg ci -Am addb |
| 159 |
adding b |
| 160 |
$ "$PYTHON" -c 'open("b", "wb").write(b"a\x00\nc\r\nd")' |
| 161 |
$ hg diff --git > bin.diff |
| 162 |
$ hg revert --no-backup b |
| 163 |
|
| 164 |
binary patch with --eol |
| 165 |
|
| 166 |
$ hg import --config patch.eol='CRLF' -m changeb bin.diff |
| 167 |
applying bin.diff |
| 168 |
$ cat b |
| 169 |
a\x00 (esc) |
| 170 |
c\r (esc) |
| 171 |
d (no-eol) |
| 172 |
$ hg st |
| 173 |
$ cd .. |