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

Re: is it kosher for pre-commit to change what's staged?

From
Joey Hess <joey@kitenet.net>
Date
Nov 10, 2010, 20:45 UTC
Message-ID
<20101110204542.GA11201@gnu.kitenet.net>
In-Reply-To
<20101110200650.GA13439@burratino>
Jonathan Nieder wrote:
> In this case, isn't it only a half accident?  For example, I think
> v1.5.4-rc0~78^2~12 (builtin-commit: fix partial-commit support,
> 2007-11-18) taught git to support this a little better.

Partial commits modified by pre-commit still don't work entirely right IME. After the commit, the index is such that git wants to revert any changes added to the commit by the pre-commit hook.

> That said, I would be interested to hear the use case, since modifying
> staged content on the fly for a commit sounds a little crazy. :)

Well, with git-annex (which I should probably properly announce here sometime), large files are not committed to git, but instead a symlink pointing at the content is committed. That symlink can temporarily be replaced with a copy of the file when the user wants to modify it, and if the user then commits, it's nice if it can move away the large file's content, and arrange for the commit to contain an updated symlink pointing at the new content.

That said, since git commit stages the whole large file into the index, which is the kind of expensive operation git-annex exists to avoid, it's still not very practical to intercept the commit like that. What I ideally need is a hook that is run before git commit stages anything.

BTW, githooks says pre-commit is "invoked before obtaining the proposed commit log message", which is a bit confusing. I actually see prepare-commit-msg and commit-msg both called after pre-commit.

-- 
see shy jo
Previous: Jonathan NiederNext: Dmitry Potapov
Message 4 of 9 in “is it kosher for pre-commit to change what's staged?”
  1. Joey HessNov 10, 2010
  2. Junio C HamanoNov 10, 2010
  3. Jonathan NiederNov 10, 2010
  4. Joey HessNov 10, 2010
  5. Dmitry PotapovNov 10, 2010
  6. Jan HudecNov 11, 2010
  7. Joey HessNov 11, 2010
  8. Junio C HamanoNov 11, 2010
  9. Kevin BallardNov 11, 2010

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.