| 1 |
Test the EOL hook |
| 2 |
|
| 3 |
$ hg init main |
| 4 |
$ cat > main/.hg/hgrc <<EOF |
| 5 |
> [hooks] |
| 6 |
> pretxnchangegroup = python:hgext.eol.hook |
| 7 |
> EOF |
| 8 |
$ hg clone main fork |
| 9 |
updating to branch default |
| 10 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 11 |
$ cd fork |
| 12 |
|
| 13 |
Create repo |
| 14 |
$ cat > .hgeol <<EOF |
| 15 |
> [patterns] |
| 16 |
> mixed.txt = BIN |
| 17 |
> crlf.txt = CRLF |
| 18 |
> **.txt = native |
| 19 |
> EOF |
| 20 |
$ hg add .hgeol |
| 21 |
$ hg commit -m 'Commit .hgeol' |
| 22 |
|
| 23 |
$ printf "first\nsecond\nthird\n" > a.txt |
| 24 |
$ hg add a.txt |
| 25 |
$ hg commit -m 'LF a.txt' |
| 26 |
$ hg push ../main |
| 27 |
pushing to ../main |
| 28 |
searching for changes |
| 29 |
adding changesets |
| 30 |
adding manifests |
| 31 |
adding file changes |
| 32 |
added 2 changesets with 2 changes to 2 files |
| 33 |
|
| 34 |
$ printf "first\r\nsecond\r\nthird\n" > a.txt |
| 35 |
$ hg commit -m 'CRLF a.txt' |
| 36 |
$ hg push ../main |
| 37 |
pushing to ../main |
| 38 |
searching for changes |
| 39 |
adding changesets |
| 40 |
adding manifests |
| 41 |
adding file changes |
| 42 |
error: pretxnchangegroup hook failed: end-of-line check failed: |
| 43 |
a.txt in a8ee6548cd86 should not have CRLF line endings |
| 44 |
transaction abort! |
| 45 |
rollback completed |
| 46 |
abort: end-of-line check failed: |
| 47 |
a.txt in a8ee6548cd86 should not have CRLF line endings |
| 48 |
[255] |
| 49 |
|
| 50 |
$ printf "first\nsecond\nthird\n" > a.txt |
| 51 |
$ hg commit -m 'LF a.txt (fixed)' |
| 52 |
$ hg push ../main |
| 53 |
pushing to ../main |
| 54 |
searching for changes |
| 55 |
adding changesets |
| 56 |
adding manifests |
| 57 |
adding file changes |
| 58 |
added 2 changesets with 2 changes to 1 files |
| 59 |
|
| 60 |
$ printf "first\nsecond\nthird\n" > crlf.txt |
| 61 |
$ hg add crlf.txt |
| 62 |
$ hg commit -m 'LF crlf.txt' |
| 63 |
$ hg push ../main |
| 64 |
pushing to ../main |
| 65 |
searching for changes |
| 66 |
adding changesets |
| 67 |
adding manifests |
| 68 |
adding file changes |
| 69 |
error: pretxnchangegroup hook failed: end-of-line check failed: |
| 70 |
crlf.txt in 004ba2132725 should not have LF line endings |
| 71 |
transaction abort! |
| 72 |
rollback completed |
| 73 |
abort: end-of-line check failed: |
| 74 |
crlf.txt in 004ba2132725 should not have LF line endings |
| 75 |
[255] |
| 76 |
|
| 77 |
$ printf "first\r\nsecond\r\nthird\r\n" > crlf.txt |
| 78 |
$ hg commit -m 'CRLF crlf.txt (fixed)' |
| 79 |
$ hg push ../main |
| 80 |
pushing to ../main |
| 81 |
searching for changes |
| 82 |
adding changesets |
| 83 |
adding manifests |
| 84 |
adding file changes |
| 85 |
added 2 changesets with 2 changes to 1 files |
| 86 |
|
| 87 |
$ printf "first\r\nsecond" > b.txt |
| 88 |
$ hg add b.txt |
| 89 |
$ hg commit -m 'CRLF b.txt' |
| 90 |
$ hg push ../main |
| 91 |
pushing to ../main |
| 92 |
searching for changes |
| 93 |
adding changesets |
| 94 |
adding manifests |
| 95 |
adding file changes |
| 96 |
error: pretxnchangegroup hook failed: end-of-line check failed: |
| 97 |
b.txt in fbcf9b1025f5 should not have CRLF line endings |
| 98 |
transaction abort! |
| 99 |
rollback completed |
| 100 |
abort: end-of-line check failed: |
| 101 |
b.txt in fbcf9b1025f5 should not have CRLF line endings |
| 102 |
[255] |
| 103 |
|
| 104 |
$ hg up -r -2 |
| 105 |
0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 106 |
$ printf "some\nother\nfile" > c.txt |
| 107 |
$ hg add c.txt |
| 108 |
$ hg commit -m "LF c.txt, b.txt doesn't exist here" |
| 109 |
created new head |
| 110 |
$ hg push -f ../main |
| 111 |
pushing to ../main |
| 112 |
searching for changes |
| 113 |
adding changesets |
| 114 |
adding manifests |
| 115 |
adding file changes |
| 116 |
error: pretxnchangegroup hook failed: end-of-line check failed: |
| 117 |
b.txt in fbcf9b1025f5 should not have CRLF line endings |
| 118 |
transaction abort! |
| 119 |
rollback completed |
| 120 |
abort: end-of-line check failed: |
| 121 |
b.txt in fbcf9b1025f5 should not have CRLF line endings |
| 122 |
[255] |
| 123 |
|
| 124 |
Test checkheadshook alias |
| 125 |
|
| 126 |
$ cat > ../main/.hg/hgrc <<EOF |
| 127 |
> [hooks] |
| 128 |
> pretxnchangegroup = python:hgext.eol.checkheadshook |
| 129 |
> EOF |
| 130 |
$ hg push -f ../main |
| 131 |
pushing to ../main |
| 132 |
searching for changes |
| 133 |
adding changesets |
| 134 |
adding manifests |
| 135 |
adding file changes |
| 136 |
error: pretxnchangegroup hook failed: end-of-line check failed: |
| 137 |
b.txt in fbcf9b1025f5 should not have CRLF line endings |
| 138 |
transaction abort! |
| 139 |
rollback completed |
| 140 |
abort: end-of-line check failed: |
| 141 |
b.txt in fbcf9b1025f5 should not have CRLF line endings |
| 142 |
[255] |
| 143 |
|
| 144 |
We can fix the head and push again |
| 145 |
|
| 146 |
$ hg up 6 |
| 147 |
1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 148 |
$ printf "first\nsecond" > b.txt |
| 149 |
$ hg ci -m "remove CRLF from b.txt" |
| 150 |
$ hg push -f ../main |
| 151 |
pushing to ../main |
| 152 |
searching for changes |
| 153 |
adding changesets |
| 154 |
adding manifests |
| 155 |
adding file changes |
| 156 |
added 3 changesets with 3 changes to 2 files (+1 heads) |
| 157 |
$ hg -R ../main rollback |
| 158 |
repository tip rolled back to revision 5 (undo push) |
| 159 |
|
| 160 |
Test it still fails with checkallhook |
| 161 |
|
| 162 |
$ cat > ../main/.hg/hgrc <<EOF |
| 163 |
> [hooks] |
| 164 |
> pretxnchangegroup = python:hgext.eol.checkallhook |
| 165 |
> EOF |
| 166 |
$ hg push -f ../main |
| 167 |
pushing to ../main |
| 168 |
searching for changes |
| 169 |
adding changesets |
| 170 |
adding manifests |
| 171 |
adding file changes |
| 172 |
error: pretxnchangegroup hook failed: end-of-line check failed: |
| 173 |
b.txt in fbcf9b1025f5 should not have CRLF line endings |
| 174 |
transaction abort! |
| 175 |
rollback completed |
| 176 |
abort: end-of-line check failed: |
| 177 |
b.txt in fbcf9b1025f5 should not have CRLF line endings |
| 178 |
[255] |
| 179 |
|
| 180 |
But we can push the clean head |
| 181 |
|
| 182 |
$ hg push -r7 -f ../main |
| 183 |
pushing to ../main |
| 184 |
searching for changes |
| 185 |
adding changesets |
| 186 |
adding manifests |
| 187 |
adding file changes |
| 188 |
added 1 changesets with 1 changes to 1 files |
| 189 |
|
| 190 |
Test multiple files/revisions output |
| 191 |
|
| 192 |
$ printf "another\r\nbad\r\none" > d.txt |
| 193 |
$ hg add d.txt |
| 194 |
$ hg ci -m "add d.txt" |
| 195 |
$ hg push -f ../main |
| 196 |
pushing to ../main |
| 197 |
searching for changes |
| 198 |
adding changesets |
| 199 |
adding manifests |
| 200 |
adding file changes |
| 201 |
error: pretxnchangegroup hook failed: end-of-line check failed: |
| 202 |
b.txt in fbcf9b1025f5 should not have CRLF line endings |
| 203 |
d.txt in a7040e68714f should not have CRLF line endings |
| 204 |
transaction abort! |
| 205 |
rollback completed |
| 206 |
abort: end-of-line check failed: |
| 207 |
b.txt in fbcf9b1025f5 should not have CRLF line endings |
| 208 |
d.txt in a7040e68714f should not have CRLF line endings |
| 209 |
[255] |
| 210 |
|
| 211 |
$ cd .. |