[issue1030] precommit hook does not execute before commit

Tyler mercurial-bugs at selenic.com
Tue Mar 11 13:18:53 CDT 2008


New submission from Tyler <hickswright at gmail.com>:

I'm trying to add a precommit hook that provides the same functionality as 'hg
ci -A', but with the 'hg addremove -s 70' similarity feature.  However, when I
set the hook and add a file, it is not added to the repo until after the commit,
which is contrary to the documentation.

hgrc.5 reads:
"precommit
    Run before starting a local commit. Exit status 0 allows the commit to
proceed. Non-zero status will cause the commit to fail. Parent changeset IDs are
in $HG_PARENT1 and $HG_PARENT2."

http://hgbook.red-bean.com/hgbookch10.html#x14-24300010.9.6 agrees:
"This hook is run before Mercurial begins to commit a new changeset. It is run
before Mercurial has any of the metadata for the commit, such as the files to be
committed, the commit message, or the commit date."

Repro:

mercurial.ini:
...
[hooks]
precommit = hg addremove -s 70
...

Observed:
>> echo "this is a file i'm adding" > test.txt
>> hg st
? test.txt
>> hg ci
nothing changed
>> hg st
# The hook was never run, why not?
>> echo "this is a file i'm adding manually" > test2.txt
>> hg add test2.txt
>> hg st
A test2.txt
? test.txt
>> hg ci
adding test.txt
# Commit message appears in editor, only lists test2.txt
>> hg st
A test.txt # When there's another change to commit, the hook gets run, but not
until after the commit, so it takes another commit to make it work.

Expected: 
test.txt should be added before the first commit, and that commit should include
test.txt, not be empty. The commit should not report "nothing changed".

----------
messages: 5566
nosy: tghw
priority: bug
status: unread
title: precommit hook does not execute before commit

____________________________________________________
Mercurial issue tracker <mercurial-bugs at selenic.com>
<http://www.selenic.com/mercurial/bts/issue1030>
____________________________________________________



More information about the Mercurial-devel mailing list