Reputation: 1829
I have a pre-commit-hook
written in python, which does some changes for a file. Now I would want to also add this file, to include the changes the pre-commit-hook
does.
I tried to use subprocess
to do this
subprocess.check_call(('git', 'add', filename))
If I try this in the interactive python session it properly adds the file, but I the hook it doesn't work.
I already checked out, that the hook works form the proper directory.
How can I add files the right way?
Edit:
My git
version is 2.1.4
Upvotes: 1
Views: 736
Reputation: 489828
Interesting: as long as the pre-commit hook really is running, the git add
should take effect in any Git version later than 1.5.4. See this commit in the Git repository for Git.
(I remember having this not work correctly in some version of Git, but do not recall it being broken in any specific version.)
The alternative, if this is broken in your particular Git version, is to have your pre-commit hook add the file, run its own git commit
that arranges to have the inner, recursive commit not recurse again—it's up to you how to work this out—and then when the inner commit finishes, reject the commit. This solution is ugly since it makes every commit seem to fail.
Upvotes: 1