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