Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look into automatic enable #8

Open
ZryletTC opened this issue Apr 22, 2020 · 10 comments
Open

Look into automatic enable #8

ZryletTC opened this issue Apr 22, 2020 · 10 comments

Comments

@ZryletTC
Copy link
Contributor

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
Copy link
Member

ZLLentz commented Apr 22, 2020

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
Copy link
Member

ZLLentz commented Apr 22, 2020

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
Copy link
Member

ZLLentz commented Apr 22, 2020

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

@ZryletTC
Copy link
Contributor Author

This totally blows up on my windows

Blows up how?

@ZLLentz
Copy link
Member

ZLLentz commented Apr 22, 2020

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
Copy link
Contributor Author

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
Copy link
Member

ZLLentz commented Apr 22, 2020

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
Copy link
Member

ZLLentz commented Apr 22, 2020

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
Copy link
Contributor

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
Copy link
Member

ZLLentz commented Jun 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants