Re: Arguments to git hooks
On Tue, May 8, 2012 at 3:47 AM, Andrew Sayers <andrew-git@pileofstuff.org> wrote:
Show 13 quoted lines
> On 06/05/12 19:35, jaseem abid wrote:
>> Hello all,
>>
>> I am trying to write a hook '.git/hooks/commit-msg' to be run before
>> every commit.
>>
>> How can I pass arguments to the script? Now by default the only arg I
>> am getting is `.git/COMMIT_EDITMSG'`. I would love to get the list of
>> files I tried to commit also into the script so that I can run a lint
>> program on it before committing it. How can I get this done?
>
> First, a standard warning - consider using a pre-receive hook instead of
> a pre-commit hook.
I am trying to get a lint, commit message spell checker, trailing whitespace check in code etc work on my *local machine* before committing. pre-receive works in the server right? Its also time I need to seriously consider a pre-commit hook to "Reject commits made between 4am and 7am with a note to go to bed."
> A lot of git's power comes from making commits as
> cheap as possible, so rules like "no committing until your code is
> pretty" tend to stifle people.
Its ok since I am the only one to use it because I want to make my commits cleaner and better. There is always --no-verify for skipping hooks.
> The best solution I've found is a `git commit` wrapper that does
> something like `CHANGES="$(git commit $@ --dry-run -v)"` to get a
> reliable diff, then starts work from there.
Isn't `git commit $@ --dry-run --porcelain` better for parsing or am I missing something ?
--
Jaseem Abid
http://jaseemabid.github.com