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

Re: Arguments to git hooks

From
Jeff King <peff@peff.net>
Date
May 7, 2012, 07:15 UTC
Message-ID
<20120507071541.GA19874@sigill.intra.peff.net>
In-Reply-To
<CAH-tXsB4PBS_YjW4DCjT6ORmNPomQ8XMPbKx3hxVNH=FyB2u3g@mail.gmail.com>
On Mon, May 07, 2012 at 12:05:51AM +0530, jaseem abid wrote:
Show 7 quoted lines
> 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?
It sounds like you want the "pre-commit" hook rather than "commit-msg".

But that aside, the solution is to use plumbing commands to examine the state. You probably want "git diff-index --cached --name-only" to get the list of files that are being committed.

-Peff
Previous: Jeff KingNext: Andrew Sayers
Message 7 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.