Show More
@@ -169,7 +169,8 b' class eolfile(object):' | |||||
169 | % (style, self.cfg.source('patterns', pattern))) |
|
169 | % (style, self.cfg.source('patterns', pattern))) | |
170 |
|
170 | |||
171 | def checkrev(self, repo, ctx, files): |
|
171 | def checkrev(self, repo, ctx, files): | |
172 | for f in files: |
|
172 | failed = [] | |
|
173 | for f in (files or ctx.files()): | |||
173 | if f not in ctx: |
|
174 | if f not in ctx: | |
174 | continue |
|
175 | continue | |
175 | for pattern, style in self.cfg.items('patterns'): |
|
176 | for pattern, style in self.cfg.items('patterns'): | |
@@ -177,14 +178,11 b' class eolfile(object):' | |||||
177 | continue |
|
178 | continue | |
178 | target = self._encode[style.upper()] |
|
179 | target = self._encode[style.upper()] | |
179 | data = ctx[f].data() |
|
180 | data = ctx[f].data() | |
180 |
if target == "to-lf" and "\r\n" in data |
|
181 | if (target == "to-lf" and "\r\n" in data | |
181 | raise util.Abort(_("%s should not have CRLF line endings") |
|
182 | or target == "to-crlf" and singlelf.search(data)): | |
182 | % f) |
|
183 | failed.append((str(ctx), target, f)) | |
183 | elif target == "to-crlf" and singlelf.search(data): |
|
|||
184 | raise util.Abort(_("%s should not have LF line endings") |
|
|||
185 | % f) |
|
|||
186 | # Ignore other rules for this file |
|
|||
187 | break |
|
184 | break | |
|
185 | return failed | |||
188 |
|
186 | |||
189 | def parseeol(ui, repo, nodes): |
|
187 | def parseeol(ui, repo, nodes): | |
190 | try: |
|
188 | try: | |
@@ -209,17 +207,26 b' def _checkhook(ui, repo, node, headsonly' | |||||
209 | files = set() |
|
207 | files = set() | |
210 | revs = set() |
|
208 | revs = set() | |
211 | for rev in xrange(repo[node].rev(), len(repo)): |
|
209 | for rev in xrange(repo[node].rev(), len(repo)): | |
212 | ctx = repo[rev] |
|
|||
213 | files.update(ctx.files()) |
|
|||
214 | revs.add(rev) |
|
210 | revs.add(rev) | |
215 | if headsonly: |
|
211 | if headsonly: | |
|
212 | ctx = repo[rev] | |||
|
213 | files.update(ctx.files()) | |||
216 | for pctx in ctx.parents(): |
|
214 | for pctx in ctx.parents(): | |
217 | revs.discard(pctx.rev()) |
|
215 | revs.discard(pctx.rev()) | |
|
216 | failed = [] | |||
218 | for rev in revs: |
|
217 | for rev in revs: | |
219 | ctx = repo[rev] |
|
218 | ctx = repo[rev] | |
220 | eol = parseeol(ui, repo, [ctx.node()]) |
|
219 | eol = parseeol(ui, repo, [ctx.node()]) | |
221 | if eol: |
|
220 | if eol: | |
222 | eol.checkrev(repo, ctx, files) |
|
221 | failed.extend(eol.checkrev(repo, ctx, files)) | |
|
222 | ||||
|
223 | if failed: | |||
|
224 | eols = {'to-lf': 'CRLF', 'to-crlf': 'LF'} | |||
|
225 | msgs = [] | |||
|
226 | for node, target, f in failed: | |||
|
227 | msgs.append(_(" %s in %s should not have %s line endings") % | |||
|
228 | (f, node, eols[target])) | |||
|
229 | raise util.Abort(_("end-of-line check failed:\n") + "\n".join(msgs)) | |||
223 |
|
230 | |||
224 | def checkallhook(ui, repo, node, hooktype, **kwargs): |
|
231 | def checkallhook(ui, repo, node, hooktype, **kwargs): | |
225 | """verify that files have expected EOLs""" |
|
232 | """verify that files have expected EOLs""" |
@@ -40,10 +40,12 b' Create repo' | |||||
40 | adding manifests |
|
40 | adding manifests | |
41 | adding file changes |
|
41 | adding file changes | |
42 | added 1 changesets with 1 changes to 1 files |
|
42 | added 1 changesets with 1 changes to 1 files | |
43 |
error: pretxnchangegroup hook failed: |
|
43 | error: pretxnchangegroup hook failed: end-of-line check failed: | |
|
44 | a.txt in a8ee6548cd86 should not have CRLF line endings | |||
44 | transaction abort! |
|
45 | transaction abort! | |
45 | rollback completed |
|
46 | rollback completed | |
46 | abort: a.txt should not have CRLF line endings |
|
47 | abort: end-of-line check failed: | |
|
48 | a.txt in a8ee6548cd86 should not have CRLF line endings | |||
47 | [255] |
|
49 | [255] | |
48 |
|
50 | |||
49 | $ printf "first\nsecond\nthird\n" > a.txt |
|
51 | $ printf "first\nsecond\nthird\n" > a.txt | |
@@ -66,10 +68,12 b' Create repo' | |||||
66 | adding manifests |
|
68 | adding manifests | |
67 | adding file changes |
|
69 | adding file changes | |
68 | added 1 changesets with 1 changes to 1 files |
|
70 | added 1 changesets with 1 changes to 1 files | |
69 |
error: pretxnchangegroup hook failed: |
|
71 | error: pretxnchangegroup hook failed: end-of-line check failed: | |
|
72 | crlf.txt in 004ba2132725 should not have LF line endings | |||
70 | transaction abort! |
|
73 | transaction abort! | |
71 | rollback completed |
|
74 | rollback completed | |
72 | abort: crlf.txt should not have LF line endings |
|
75 | abort: end-of-line check failed: | |
|
76 | crlf.txt in 004ba2132725 should not have LF line endings | |||
73 | [255] |
|
77 | [255] | |
74 |
|
78 | |||
75 | $ printf "first\r\nsecond\r\nthird\r\n" > crlf.txt |
|
79 | $ printf "first\r\nsecond\r\nthird\r\n" > crlf.txt | |
@@ -92,10 +96,12 b' Create repo' | |||||
92 | adding manifests |
|
96 | adding manifests | |
93 | adding file changes |
|
97 | adding file changes | |
94 | added 1 changesets with 1 changes to 1 files |
|
98 | added 1 changesets with 1 changes to 1 files | |
95 |
error: pretxnchangegroup hook failed: |
|
99 | error: pretxnchangegroup hook failed: end-of-line check failed: | |
|
100 | b.txt in fbcf9b1025f5 should not have CRLF line endings | |||
96 | transaction abort! |
|
101 | transaction abort! | |
97 | rollback completed |
|
102 | rollback completed | |
98 | abort: b.txt should not have CRLF line endings |
|
103 | abort: end-of-line check failed: | |
|
104 | b.txt in fbcf9b1025f5 should not have CRLF line endings | |||
99 | [255] |
|
105 | [255] | |
100 |
|
106 | |||
101 | $ hg up -r -2 |
|
107 | $ hg up -r -2 | |
@@ -111,10 +117,12 b' Create repo' | |||||
111 | adding manifests |
|
117 | adding manifests | |
112 | adding file changes |
|
118 | adding file changes | |
113 | added 2 changesets with 2 changes to 2 files (+1 heads) |
|
119 | added 2 changesets with 2 changes to 2 files (+1 heads) | |
114 |
error: pretxnchangegroup hook failed: |
|
120 | error: pretxnchangegroup hook failed: end-of-line check failed: | |
|
121 | b.txt in fbcf9b1025f5 should not have CRLF line endings | |||
115 | transaction abort! |
|
122 | transaction abort! | |
116 | rollback completed |
|
123 | rollback completed | |
117 | abort: b.txt should not have CRLF line endings |
|
124 | abort: end-of-line check failed: | |
|
125 | b.txt in fbcf9b1025f5 should not have CRLF line endings | |||
118 | [255] |
|
126 | [255] | |
119 |
|
127 | |||
120 | Test checkheadshook alias |
|
128 | Test checkheadshook alias | |
@@ -130,10 +138,12 b' Test checkheadshook alias' | |||||
130 | adding manifests |
|
138 | adding manifests | |
131 | adding file changes |
|
139 | adding file changes | |
132 | added 2 changesets with 2 changes to 2 files (+1 heads) |
|
140 | added 2 changesets with 2 changes to 2 files (+1 heads) | |
133 |
error: pretxnchangegroup hook failed: |
|
141 | error: pretxnchangegroup hook failed: end-of-line check failed: | |
|
142 | b.txt in fbcf9b1025f5 should not have CRLF line endings | |||
134 | transaction abort! |
|
143 | transaction abort! | |
135 | rollback completed |
|
144 | rollback completed | |
136 | abort: b.txt should not have CRLF line endings |
|
145 | abort: end-of-line check failed: | |
|
146 | b.txt in fbcf9b1025f5 should not have CRLF line endings | |||
137 | [255] |
|
147 | [255] | |
138 |
|
148 | |||
139 | We can fix the head and push again |
|
149 | We can fix the head and push again | |
@@ -166,10 +176,12 b' Test it still fails with checkallhook' | |||||
166 | adding manifests |
|
176 | adding manifests | |
167 | adding file changes |
|
177 | adding file changes | |
168 | added 3 changesets with 3 changes to 2 files (+1 heads) |
|
178 | added 3 changesets with 3 changes to 2 files (+1 heads) | |
169 |
error: pretxnchangegroup hook failed: |
|
179 | error: pretxnchangegroup hook failed: end-of-line check failed: | |
|
180 | b.txt in fbcf9b1025f5 should not have CRLF line endings | |||
170 | transaction abort! |
|
181 | transaction abort! | |
171 | rollback completed |
|
182 | rollback completed | |
172 | abort: b.txt should not have CRLF line endings |
|
183 | abort: end-of-line check failed: | |
|
184 | b.txt in fbcf9b1025f5 should not have CRLF line endings | |||
173 | [255] |
|
185 | [255] | |
174 |
|
186 | |||
175 | But we can push the clean head |
|
187 | But we can push the clean head | |
@@ -182,3 +194,24 b' But we can push the clean head' | |||||
182 | adding file changes |
|
194 | adding file changes | |
183 | added 1 changesets with 1 changes to 1 files |
|
195 | added 1 changesets with 1 changes to 1 files | |
184 |
|
196 | |||
|
197 | Test multiple files/revisions output | |||
|
198 | ||||
|
199 | $ printf "another\r\nbad\r\none" > d.txt | |||
|
200 | $ hg add d.txt | |||
|
201 | $ hg ci -m "add d.txt" | |||
|
202 | $ hg push -f ../main | |||
|
203 | pushing to ../main | |||
|
204 | searching for changes | |||
|
205 | adding changesets | |||
|
206 | adding manifests | |||
|
207 | adding file changes | |||
|
208 | added 3 changesets with 3 changes to 2 files (+1 heads) | |||
|
209 | error: pretxnchangegroup hook failed: end-of-line check failed: | |||
|
210 | d.txt in a7040e68714f should not have CRLF line endings | |||
|
211 | b.txt in fbcf9b1025f5 should not have CRLF line endings | |||
|
212 | transaction abort! | |||
|
213 | rollback completed | |||
|
214 | abort: end-of-line check failed: | |||
|
215 | d.txt in a7040e68714f should not have CRLF line endings | |||
|
216 | b.txt in fbcf9b1025f5 should not have CRLF line endings | |||
|
217 | [255] |
General Comments 0
You need to be logged in to leave comments.
Login now