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

init-templatedir installing hooks to wrong directory #1720

Closed
chronoB opened this issue Nov 28, 2020 · 1 comment
Closed

init-templatedir installing hooks to wrong directory #1720

chronoB opened this issue Nov 28, 2020 · 1 comment
Labels

Comments

@chronoB
Copy link

@chronoB chronoB commented Nov 28, 2020

I was trying to use the init-templatedir functionality of pre-commit and ran into a weird problem:

Using Windows 10, pre-commit 2.9.2, git version 2.29.2.windows.1

I followed the example on the pre-commit.com website and used:

git config --global init.templateDir ~/.git-template
pre-commit init-templatedir ~/.git-template

grafik

It wants me to be in a git repository (I thought you prevented this with da80cc6).
So i switched to a git repository and rerun

pre-commit init-templatedir ~/.git-template

grafik

the hooks aren't installed in the stated directory.
Based on the warnings it looks like pre-commit isn't resolving the ~ correctly, or did I miss sth.?

git config --get init.templateDir 

returns ~/.git-template

grafik

@asottile
Copy link
Member

@asottile asottile commented Nov 28, 2020

Ahah, so the first part of this is that the cygwin check relies on being in a git repo and it is only run on windows -- that's why it only was failing on windows and why I didn't notice the regression there

As for the other components here, ~ is a special shell expansion on posix -- on windows you'll use %HOMEPATH%\.git-template instead (this probably is worth a documentation update -- the docs live at https://github.com/pre-commit/pre-commit.com if you'd like to contribute to them!).

If we try with %HOMEPATH% I get this output:

(venv) C:\Users\Anthony\workspace\wat>pre-commit init-templatedir %HOMEPATH%\.git-template
pre-commit installed at \Users\Anthony\.git-template\hooks\pre-commit
[WARNING] `init.templateDir` not set to the target directory
[WARNING] maybe `git config --global init.templateDir C:\Users\Anthony\.git-template`?

(venv) C:\Users\Anthony\workspace\wat>git config --global init.templateDir %HOMEPATH%\.git-template

(venv) C:\Users\Anthony\workspace\wat>pre-commit init-templatedir %HOMEPATH%\.git-template
pre-commit installed at \Users\Anthony\.git-template\hooks\pre-commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants