Expose prepare-commit-msg arguments as environment vars#2407
Expose prepare-commit-msg arguments as environment vars#2407asottile merged 1 commit intopre-commit:mainfrom
Conversation
|
so it shouldn't treat them as arguments, pre-commit only deals in files they should be environment variables to match up with the other hooks |
|
Ah! I see what you mean now...
I have changed it accordingly. |
|
This was the most elegant way I thought of to keep this underneath the PEP8 line length. Maybe you have an opinion on this... if args.prepare_commit_message_source:
environ['PRE_COMMIT_COMMIT_MSG_SOURCE'] \
= args.prepare_commit_message_sourceI have implemented all the other name changes as you suggested. In regards to the tests: Do you usually extend the existing tests i.e. test_prepare_commit_msg_hook or do you want one for each different possible argument passed from the hook? |
even pep8 suggests using parens over backslashes:
and yeah there'll need to be new tests -- whatever is needed to demonstrate the change should be sufficient |
|
Hello, is there any documentation in pre-commit on these environment vars? |
@asottile Same problem, but with PRE_COMMIT_COMMIT_OBJECT_NAME @Konfekt did you resolve it? |
|
Hello, I think I got interested in it for a commit message generation script and resorted to detecting rebases by detecting more than one command-line argument https://gist.github.com/Konfekt/d9640c390deea4beafcf74e29410b8a6#file-chatgpt-write-msg-py-L8 but actually cannot remember at all |
@asottile Same problem, but with PRE_COMMIT_COMMIT_OBJECT_NAME @Konfekt did you resolve it? |
|
Hello, I think I got interested in it for a commit message generation script and resorted to detecting rebases by detecting more than one command-line argument https://gist.github.com/Konfekt/d9640c390deea4beafcf74e29410b8a6#file-chatgpt-write-msg-py-L8 but actually cannot remember at all |

Closes #2406.
This adds the ability to pass environ args that are not files to the prepare-commit-msg hook as defined by the git specification:
Git hook documentation
If you want some tests for this more than happy to think up some, however, I have tried to only add to existing code and use optional arguments so all existing tests are not affected.