views:

44

answers:

1

Is there any Mercurial extension that can grep for "console.log" that might have been accidentally left over as debugging code?

Right now this is what I am doing:

1) hg out ssh://....  

the above is to see what is the first committed revision in my local repo, say, the smallest revision is 3456

2) hg diff -r 3455 | grep "^+" | grep "console\.log"

The number 3455 is 3456 - 1. the first grep is to see newly added code. the second one is for console.log

This method can tell that I have "console.log" in the new code, but won't say what file it is in.

+1  A: 

It sounds like you're in need of a commit hook. Try putting something like this into your .hg/hgrc (or ~/.hgrc if you want it global):

[hooks]
pretxncommit = sh -c 'if hg log -p -r $HG_NODE | grep -q '^\+.*console\.log' ; then exit 1; else exit 0; fi'

That will abort your commits if they would be adding a line that contains console.log. Your commit message will be saved in .hg/last-message.txt.

See http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html for more details.

Ry4an