From 25db85f436e630ac63263e4e7a964eee8e2eb817 Mon Sep 17 00:00:00 2001 From: Patrick Mezard Date: Sun, 13 Mar 2011 15:07:44 +0100 Subject: [PATCH] eol: make the hook check all new heads, not only tip (issue2666) Report and test by Antoine Pitrou --- hgext/eol.py | 17 ++++++++++++----- tests/test-eol-hook.t | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/hgext/eol.py b/hgext/eol.py index 7ccbe86aa5..e454f0b7a0 100644 --- a/hgext/eol.py +++ b/hgext/eol.py @@ -202,13 +202,20 @@ def parseeol(ui, repo, nodes): def hook(ui, repo, node, hooktype, **kwargs): """verify that files have expected EOLs""" + # Extract heads and get touched files set at the same time files = set() + heads = set() for rev in xrange(repo[node].rev(), len(repo)): - files.update(repo[rev].files()) - tip = repo['tip'] - eol = parseeol(ui, repo, [tip.node()]) - if eol: - eol.checkrev(repo, tip, files) + ctx = repo[rev] + files.update(ctx.files()) + heads.add(rev) + for pctx in ctx.parents(): + heads.discard(pctx.rev()) + for rev in heads: + ctx = repo[rev] + eol = parseeol(ui, repo, [ctx.node()]) + if eol: + eol.checkrev(repo, ctx, files) def preupdate(ui, repo, hooktype, parent1, parent2): #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2) diff --git a/tests/test-eol-hook.t b/tests/test-eol-hook.t index 71b5396b7f..ec14900fba 100644 --- a/tests/test-eol-hook.t +++ b/tests/test-eol-hook.t @@ -81,3 +81,38 @@ Create repo adding manifests adding file changes added 2 changesets with 2 changes to 1 files + + $ printf "first\r\nsecond" > b.txt + $ hg add b.txt + $ hg commit -m 'CRLF b.txt' + $ hg push ../main + pushing to ../main + searching for changes + adding changesets + 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 + transaction abort! + rollback completed + abort: b.txt should not have CRLF line endings + [255] + + $ hg up -r -2 + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ printf "some\nother\nfile" > c.txt + $ hg add c.txt + $ hg commit -m "LF c.txt, b.txt doesn't exist here" + created new head + $ hg push -f ../main + pushing to ../main + searching for changes + adding changesets + 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 + transaction abort! + rollback completed + abort: b.txt should not have CRLF line endings + [255]