This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Explain how to set up the whitespace commit hook locally
Type: enhancement Stage: resolved
Components: Devguide Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: willingc Nosy List: ezio.melotti, ncoghlan, ned.deily, python-dev, ronaldoussoren, terry.reedy, willingc
Priority: normal Keywords: patch

Created on 2012-11-04 15:04 by ncoghlan, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
iss-hooks.patch willingc, 2015-04-14 15:01
iss-hooks-1.patch willingc, 2015-04-15 05:47
Messages (12)
msg174810 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-11-04 15:04
Setting up the same commit checks locally that the main repo enforces for incoming patch sets can save a great deal of frustration with the server rejecting "hg push" for changes (this can be especially frustrating if you have already merged changes across branches).

The committer section of the devguide [1] should explain how to:

1. Check out the hooks repo from
2. Configure the whitespace checking hook by adding this to hgrc for the relevant repo(s) (adjusting the path appropriately for the checked out location of the hooks repo):

commit = python:~/devel/hg_hooks/

msg174812 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-04 15:10
Configuring the editor to remove trailing whitespace, and using make patchcheck are other valid solutions to this problem.
msg174814 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-11-04 15:33
Sure, but both of those can fail (forgetting to run make patchcheck, using a different editor from your normal one for some reason)

Once the commit hook is set up properly, you get alerted to the problem as soon as you try to commit, rather than having to untangle a merge chain when you realise on pushing that you stuffed up the whitespace in the original bugfix commit.
msg174815 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-04 15:44
I'm not against your proposal.  If the goal is to explain how to get rid of trailing whitespace then the other solutions should be mentioned too (I think made patchcheck already is).  If the goal is to show how to set up local hooks and where to get them, then the other solutions don't belong there.
msg175374 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-11-11 17:29
I would be helped by such an explanation in the devguide.
msg240900 - (view) Author: Carol Willing (willingc) * (Python committer) Date: 2015-04-14 15:01
Adds whitespace checking hook setup information to Minimal Configuration section of devguide [1].

Patch is ready for review.

msg240964 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-04-14 17:35
The wording of the patch looks good to me other than one issue: which hook to use.  I notice Nick's suggestion is to use the hg "commit" hook.  But in the comments for the checkwhitespace hook itself, "pretxncommit" is the suggested hook.  The difference between them, AFAIK, is that the "commit" hook is executed after the changeset has been created and applied in the local repo, while the "pretxncommit" hook is called before the changeset is committed and can thus abort the commit.  So in either case, you'll see the warning message from the hook if the changeset has extraneous white space but when using the "commit" hook the changeset will be applied anyway and, to fix it, you either have to strip it or commit a fix in an additional changeset.  There may be some workflows where using "commit" is a better choice (like when using mq) but I think in general using the "pretxncommit" hook is the better choice.

msg240994 - (view) Author: Carol Willing (willingc) * (Python committer) Date: 2015-04-14 19:28
Ned, Thanks for the review and feedback.

It seems reasonable to me to mention both the "pretxncommit" hook as well as the "commit" hook as well as your brief comments on the difference between the two. 

I'll make that change to the patch and resubmit.
msg241083 - (view) Author: Carol Willing (willingc) * (Python committer) Date: 2015-04-15 05:47
Patch is ready for review. Ned's feedback on "pretxncommit" hook is added.
msg241085 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-04-15 06:09
New changeset b494a25915a9 by Ned Deily in branch 'default':
Issue #16405: Explain how to set up the whitespace commit hook locally.
msg241086 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-04-15 06:13
Thanks for the patch, Carol.  (I made a few minor changes before committing: to the file paths and to make it clearer that one should choose one of the hooks.)
msg241997 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2015-04-25 06:49
Oh, so *that's* why my local hook isn't aborting commits when the whitespace check fails :)
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60609
2015-04-25 06:49:50ncoghlansetmessages: + msg241997
2015-04-15 06:13:50ned.deilysetstatus: open -> closed
resolution: fixed
messages: + msg241086

stage: patch review -> resolved
2015-04-15 06:09:10python-devsetnosy: + python-dev
messages: + msg241085
2015-04-15 05:47:20willingcsetfiles: + iss-hooks-1.patch

messages: + msg241083
2015-04-14 19:28:50willingcsetmessages: + msg240994
2015-04-14 17:35:44ned.deilysetnosy: + ned.deily
messages: + msg240964
2015-04-14 15:01:49willingcsetfiles: + iss-hooks.patch
keywords: + patch
messages: + msg240900

stage: needs patch -> patch review
2015-04-14 14:10:43willingcsetassignee: willingc

nosy: + willingc
2013-07-17 19:02:10ronaldoussorensetnosy: + ronaldoussoren
2012-11-11 17:29:03terry.reedysetnosy: + terry.reedy
messages: + msg175374
2012-11-04 15:44:30ezio.melottisetmessages: + msg174815
2012-11-04 15:33:13ncoghlansetmessages: + msg174814
2012-11-04 15:10:44ezio.melottisetmessages: + msg174812
2012-11-04 15:04:11ncoghlancreate