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

Sometimes unable to lock the index during pre-commit hook

From
Réda Housni Alaoui <reda.housnialaoui@gmail.com>
Date
Nov 9, 2019, 21:39 UTC
Message-ID
<CAE0unxyojHVWP4aM3C+DdMYORmcoCuq-0wwLGjE8ok6dLj_E8w@mail.gmail.com>
Hi everyone,

I am the maintainer of https://github.com/Cosium/maven-git-code-format/. maven-git-code-format is a code formatter plugin triggered by git pre-commit hook. On pre-commit, the plugin make use of https://www.eclipse.org/jgit/ to alter the git index to format files.

When performing:
  git add . && git commit -m "Test"
The plugin works without issues
But when performing instead:
  git commit -am "Test"
The plugin fails because it can't lock the index file.

With the commit "all" command, it seems that the index is locked at https://github.com/git/git/blob/master/builtin/commit.c#L419 and kept locked during the pre commit hooks execution.

This difference of behaviour with or without "all" option leaves me puzzled. Are pre-commit hooks expected to be able to manipulate the index? If yes, can we call the current commit "all" behaviour a bug? If no, is there a document specifying what hooks are authorized to do?

Thanks in advance
Next: Junio C Hamano
Message 1 of 5 in “Sometimes unable to lock the index during pre-commit hook”
  1. Réda Housni AlaouiNov 9, 2019
  2. Junio C HamanoNov 10, 2019
  3. Réda Housni AlaouiNov 10, 2019
  4. Junio C HamanoNov 11, 2019
  5. Réda Housni AlaouiNov 11, 2019

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.