pcdshub / pre-commit-hooks

Pre-commit hooks for PCDS projects (https://pre-commit.com/)
Other
10 stars 7 forks source link

Look into automatic enable #8

Open ZryletTC opened 4 years ago

ZryletTC commented 4 years ago

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.

ZLLentz commented 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.

ZLLentz commented 4 years ago

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...

ZLLentz commented 4 years ago

After editing the shebang to just python, this seems to work great on linux.

ZryletTC commented 4 years ago

This totally blows up on my windows

Blows up how?

ZLLentz commented 4 years ago

Two ways:

  1. by raising an exception on 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)
  2. by being unable to locate my template directory no matter how I configure it using 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.
ZryletTC commented 4 years ago

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 cded 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.

ZLLentz commented 4 years ago

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.

ZLLentz commented 4 years ago

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

rruiter87 commented 5 months ago

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.

ZLLentz commented 4 months ago

Thank you @rruiter87, I didn't know this existed. I'm definitely going to integrate it into our CI pipelines.