Closed goldstar611 closed 2 years ago
When running python3 unittest from a git pre-commit hook, it seems that subprocess.run() to the git binary affect the root repo instead of the temporary directory created by utils.py at https://github.com/goldstar611/gitless/blob/0ee074f6acd79c43bc34c1b72645e9a1226b71da/gitless/tests/utils.py#L24-L29
subprocess.run()
git
So this line https://github.com/goldstar611/gitless/blob/8a84ca0b9d87c3110bb7e36f604cea6c5ceb54a3/gitless/tests/test_core.py#L79 basically will re-initialize our repository (ok because not destructive) but then https://github.com/goldstar611/gitless/blob/8a84ca0b9d87c3110bb7e36f604cea6c5ceb54a3/gitless/tests/test_core.py#L81 will update/overwrite user.name and user.email before all of the tests fail.
user.name
user.email
Related: https://stackoverflow.com/questions/59686461/calling-git-in-pre-commit-hook
Easy fix with env -i
env -i
./.git/pre-commit:
#!/bin/sh env -i python3 -m unittest discover -s $(git rev-parse --show-toplevel) -t $(git rev-parse --show-toplevel) -p 'test_core.py'
When running python3 unittest from a git pre-commit hook, it seems that
subprocess.run()
to thegit
binary affect the root repo instead of the temporary directory created by utils.py at https://github.com/goldstar611/gitless/blob/0ee074f6acd79c43bc34c1b72645e9a1226b71da/gitless/tests/utils.py#L24-L29So this line https://github.com/goldstar611/gitless/blob/8a84ca0b9d87c3110bb7e36f604cea6c5ceb54a3/gitless/tests/test_core.py#L79 basically will re-initialize our repository (ok because not destructive) but then https://github.com/goldstar611/gitless/blob/8a84ca0b9d87c3110bb7e36f604cea6c5ceb54a3/gitless/tests/test_core.py#L81 will update/overwrite
user.name
anduser.email
before all of the tests fail.Related: https://stackoverflow.com/questions/59686461/calling-git-in-pre-commit-hook