changeset 13649:328ce8a405ac

eol: improve hook failure output Before, only the first failure was reported: abort: b.txt should not have CRLF line endings while now all of them are listed: 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 As first suggested by Antoine Pitrou <solipsis@pitrou.net>
author Patrick Mezard <pmezard@gmail.com>
date Mon, 14 Mar 2011 21:08:18 +0100
parents 595dba23d337
children 56e71e7d2ba2
files hgext/eol.py tests/test-eol-hook.t
diffstat 2 files changed, 60 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/eol.py	Mon Mar 14 13:11:26 2011 -0500
+++ b/hgext/eol.py	Mon Mar 14 21:08:18 2011 +0100
@@ -169,6 +169,7 @@
                         % (style, self.cfg.source('patterns', pattern)))
 
     def checkrev(self, repo, ctx, files):
+        failed = []
         for f in files:
             if f not in ctx:
                 continue
@@ -177,14 +178,11 @@
                     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:
@@ -215,11 +213,20 @@
         if headsonly:
             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"""
--- a/tests/test-eol-hook.t	Mon Mar 14 13:11:26 2011 -0500
+++ b/tests/test-eol-hook.t	Mon Mar 14 21:08:18 2011 +0100
@@ -40,10 +40,12 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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]