goldstar611 / gitless

A maintained fork of the simple git interface
https://goldstar611.github.io/gitless/
MIT License
26 stars 2 forks source link

gl not working correctly from git pre-commit hook #9

Closed goldstar611 closed 2 years ago

goldstar611 commented 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

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.

Related: https://stackoverflow.com/questions/59686461/calling-git-in-pre-commit-hook

goldstar611 commented 2 years ago

Easy fix with 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'