diff --git a/hgext/eol.py b/hgext/eol.py --- a/hgext/eol.py +++ b/hgext/eol.py @@ -169,7 +169,8 @@ class eolfile(object): % (style, self.cfg.source('patterns', pattern))) def checkrev(self, repo, ctx, files): - for f in files: + failed = [] + for f in (files or ctx.files()): if f not in ctx: continue for pattern, style in self.cfg.items('patterns'): @@ -177,14 +178,11 @@ class eolfile(object): continue target = self._encode[style.upper()] data = ctx[f].data() - if target == "to-lf" and "\r\n" in data: - raise util.Abort(_("%s should not have CRLF line endings") - % f) - elif target == "to-crlf" and singlelf.search(data): - raise util.Abort(_("%s should not have LF line endings") - % f) - # Ignore other rules for this file + if (target == "to-lf" and "\r\n" in data + or target == "to-crlf" and singlelf.search(data)): + failed.append((str(ctx), target, f)) break + return failed def parseeol(ui, repo, nodes): try: @@ -209,17 +207,26 @@ def _checkhook(ui, repo, node, headsonly files = set() revs = set() for rev in xrange(repo[node].rev(), len(repo)): - ctx = repo[rev] - files.update(ctx.files()) revs.add(rev) if headsonly: + ctx = repo[rev] + files.update(ctx.files()) for pctx in ctx.parents(): revs.discard(pctx.rev()) + failed = [] for rev in revs: ctx = repo[rev] eol = parseeol(ui, repo, [ctx.node()]) if eol: - eol.checkrev(repo, ctx, files) + failed.extend(eol.checkrev(repo, ctx, files)) + + if failed: + eols = {'to-lf': 'CRLF', 'to-crlf': 'LF'} + msgs = [] + for node, target, f in failed: + msgs.append(_(" %s in %s should not have %s line endings") % + (f, node, eols[target])) + raise util.Abort(_("end-of-line check failed:\n") + "\n".join(msgs)) def checkallhook(ui, repo, node, hooktype, **kwargs): """verify that files have expected EOLs""" diff --git a/tests/test-eol-hook.t b/tests/test-eol-hook.t --- a/tests/test-eol-hook.t +++ b/tests/test-eol-hook.t @@ -40,10 +40,12 @@ Create repo adding manifests adding file changes added 1 changesets with 1 changes to 1 files - error: pretxnchangegroup hook failed: a.txt should not have CRLF line endings + error: pretxnchangegroup hook failed: end-of-line check failed: + a.txt in a8ee6548cd86 should not have CRLF line endings transaction abort! rollback completed - abort: a.txt should not have CRLF line endings + abort: end-of-line check failed: + a.txt in a8ee6548cd86 should not have CRLF line endings [255] $ printf "first\nsecond\nthird\n" > a.txt @@ -66,10 +68,12 @@ Create repo adding manifests adding file changes added 1 changesets with 1 changes to 1 files - error: pretxnchangegroup hook failed: crlf.txt should not have LF line endings + error: pretxnchangegroup hook failed: end-of-line check failed: + crlf.txt in 004ba2132725 should not have LF line endings transaction abort! rollback completed - abort: crlf.txt should not have LF line endings + abort: end-of-line check failed: + crlf.txt in 004ba2132725 should not have LF line endings [255] $ printf "first\r\nsecond\r\nthird\r\n" > crlf.txt @@ -92,10 +96,12 @@ Create repo adding manifests adding file changes added 1 changesets with 1 changes to 1 files - error: pretxnchangegroup hook failed: b.txt should not have CRLF line endings + error: pretxnchangegroup hook failed: end-of-line check failed: + b.txt in fbcf9b1025f5 should not have CRLF line endings transaction abort! rollback completed - abort: b.txt should not have CRLF line endings + abort: end-of-line check failed: + b.txt in fbcf9b1025f5 should not have CRLF line endings [255] $ hg up -r -2 @@ -111,10 +117,12 @@ Create repo adding manifests adding file changes added 2 changesets with 2 changes to 2 files (+1 heads) - error: pretxnchangegroup hook failed: b.txt should not have CRLF line endings + error: pretxnchangegroup hook failed: end-of-line check failed: + b.txt in fbcf9b1025f5 should not have CRLF line endings transaction abort! rollback completed - abort: b.txt should not have CRLF line endings + abort: end-of-line check failed: + b.txt in fbcf9b1025f5 should not have CRLF line endings [255] Test checkheadshook alias @@ -130,10 +138,12 @@ Test checkheadshook alias adding manifests adding file changes added 2 changesets with 2 changes to 2 files (+1 heads) - error: pretxnchangegroup hook failed: b.txt should not have CRLF line endings + error: pretxnchangegroup hook failed: end-of-line check failed: + b.txt in fbcf9b1025f5 should not have CRLF line endings transaction abort! rollback completed - abort: b.txt should not have CRLF line endings + abort: end-of-line check failed: + b.txt in fbcf9b1025f5 should not have CRLF line endings [255] We can fix the head and push again @@ -166,10 +176,12 @@ Test it still fails with checkallhook adding manifests adding file changes added 3 changesets with 3 changes to 2 files (+1 heads) - error: pretxnchangegroup hook failed: b.txt should not have CRLF line endings + error: pretxnchangegroup hook failed: end-of-line check failed: + b.txt in fbcf9b1025f5 should not have CRLF line endings transaction abort! rollback completed - abort: b.txt should not have CRLF line endings + abort: end-of-line check failed: + b.txt in fbcf9b1025f5 should not have CRLF line endings [255] But we can push the clean head @@ -182,3 +194,24 @@ But we can push the clean head adding file changes added 1 changesets with 1 changes to 1 files +Test multiple files/revisions output + + $ printf "another\r\nbad\r\none" > d.txt + $ hg add d.txt + $ hg ci -m "add d.txt" + $ hg push -f ../main + pushing to ../main + searching for changes + adding changesets + adding manifests + adding file changes + added 3 changesets with 3 changes to 2 files (+1 heads) + error: pretxnchangegroup hook failed: end-of-line check failed: + d.txt in a7040e68714f should not have CRLF line endings + b.txt in fbcf9b1025f5 should not have CRLF line endings + transaction abort! + rollback completed + abort: end-of-line check failed: + d.txt in a7040e68714f should not have CRLF line endings + b.txt in fbcf9b1025f5 should not have CRLF line endings + [255]