Open ZryletTC opened 4 years ago
This is neat, it only requires that each user pick a template dir and run one git and one pre-commit command on each machine they want to set it up for. It does still require that you have a viable pre-commit python environment on that machine to run the pre-commit command with. We should check out how the resulting hook script looks and add instructions to this repo.
This totally blows up on my windows, but seems to have worked nicely for my linux desktop. Note that you may want to edit the shebang on the script after it is generated, for mine it was hardcoded to try python3.8
which requires that I be in a python3.8
environment when making git commits...
After editing the shebang to just python
, this seems to work great on linux.
This totally blows up on my windows
Blows up how?
Two ways:
pre-commit init-templatedir ~/.git-template
that doesn't make any sense and leaving a log file with no good clues. I tried the obvious things like picking different directories and making sure they existed before running the command (something I did not have to do on linux)git config --global init.templateDir
(I tried to copy in a hooks file manually). I tried many different permutations of ~/.git-template
, C:\\Users\zlentz\.git-template
, etc.Where were you running those from? I was able to set it up on my personal Windows computer just now using git-bash.
I had no problems running git config --global init.templateDir ~/.git-template
.
Running pre-commit init-templatedir ~/.git-template
initially complained that it wasn't inside a git directory but worked fine after I cd
ed to a git directory (no idea why it needed to be in one though, it didn't touch it).
After set up, I was able to run pre-commit run --all-files
and git commit
ran the hooks from a freshly cloned repo without having to run pre-commit install
.
I'm running it through powershell, I'll try again and do it inside an arbitrary git directory, and failing that see if it works through git bash for me. If git bash ends up being the solution to all windows problems then I am 100% ok with that.
Running inside a git directory and iterating through the options for specifying directories made it work, I just had to specify it as C:\Users\zlentz\.git-template
Why not use https://pre-commit.ci/ ? It's free for public repos. You can enable it for pull requests to prevent PRs from messing up the repo.
Thank you @rruiter87, I didn't know this existed. I'm definitely going to integrate it into our CI pipelines.
Saw this today: https://pre-commit.com/#automatically-enabling-pre-commit-on-repositories
If it works, it'd be a lot easier than trying to get everyone to run
pre-commit install
every time they clone a repo.