git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Arguments to git hooks

From
jaseem abid <jaseemabid@gmail.com>
Date
May 14, 2012, 20:34 UTC
Message-ID
<CAH-tXsBMYe2q6dZ6COyEH7N9n-mJh4yV8O50tgeZ1PeSEnZHvQ@mail.gmail.com>
In-Reply-To
<4FA84A0F.6060608@pileofstuff.org>

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
Previous: Andrew Sayers
Message 9 of 9 in “Arguments to git hooks”
  1. jaseem abidMay 6, 2012
  2. Marcus KarlssonMay 6, 2012
  3. jaseem abidMay 6, 2012
  4. Marcus KarlssonMay 6, 2012
  5. jaseem abidMay 6, 2012
  6. Jeff KingMay 7, 2012
  7. Jeff KingMay 7, 2012
  8. Andrew SayersMay 7, 2012
  9. jaseem abidMay 14, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.