observing/pre-commit

It does not write pre-commit file in hooks folder on Windows

Opened this issue Β· 22 comments

Pretty much a duplicate of #43

pre-commit:
pre-commit: Failed to symlink the hook file in your .git/hooks folder because:
pre-commit: EPERM: operation not permitted, symlink '..\..\node_modules\pre-commit\hook' -> 'C:\path\to\glory\.git\hooks\pre-commit'
pre-commit: The hook was not installed.
pre-commit:

However, I'd like to share some more info: https://en.wikipedia.org/wiki/NTFS_symbolic_link

Ideally, we could request elevation something like https://www.npmjs.com/package/windows-elevate or call a native function.

Thanks!

Also experiencing the same issue.

Same result for me, although I did not get that error message (in fact I did not get any error, it just did not write the file). The solution in #43 did not work for me.

Same goes for me as well on Windows 10 x64 and Node 6.2.0.

I appreciate that this doesn't resolve the install scenario - but a quick fix can be to manually create the NTFS junction (symlink) yourself. From elevated PowerShell prompt in your repo's .git/hooks/ folder:

cmd /c mklink /H pre-commit ..\..\node_modules\pre-commit\hook

I confirm what @janis-kra said I received no error at all, it simply just didn't write the file.

UPDATE: Per my previous comment, upon further testing I disocvered that pre-commit will show the error on the initial install of pre-commit, but if you are to discover that it symlink isn't installed (like it doesn't in Windows without being Administrator) and run the npm i again the error won't show, because the install.js in not ran again, once pre-commit has already been installed.

Its interesting because earlier versions didn't suffer this issue.

How about just copy the file instead in case symlink fails?

neico commented

I'd prefer the elevate approach as well, if things need it, so be it, no biggie

windows also allows you to run mklink without elevated privileges trough a local policy, but not everyone is going to go that way, and besides,
admin accounts are unaffected by this setting, they still need elevated access

Maybe this is the reason:
1a04430

This change might help when moving or renaming the project directory... but it will stop working on Windows.
fs.symlinkSync() seems to have problems making relative 'junction' symlinks on Windows (as per https://nodejs.org/api/fs.html#fs_fs_symlink_target_path_type_callback)
nodejs.org doesn't say that it would also fail for 'file' symlinks, but it smells suspicious... seems like it started failing after that commit was added.

I had to adapt @robsimm solution but it worked for me, at least for the moment, until someone fix the issue. You guys can run it on Windows Prompt cmd /c mklink pre-commit ..\..\node_modules\pre-commit\hook with root access.

Even easier in a root command prompt just call node ./node_modules/pre-commit/install.js which will call the original install script provided by pre-commit and install the symlinked file for you

@alallier Your suggestion fixed it for me, thanks. Windows 10 Node 4.4.7

thank @alallier , I try it under the win10 System Node 6.3.0. And it succeeds.

thank@alallier
q

I had to try 'pre-commit', but it does not work because of having no β€˜pre-commit’ file. so I use node ./node_modules/pre-commit/install.js, it work successfully.

this should be solved by #84

@alallier trying on Win 8, Node 7.9.0 executing node ./node_modules/pre-commit/install.js. No messages, no errors, no pre-commit file in git hooks

@Alex-Sokolov not sure about the errors, but trying running node ./node_modules/pre-commit/install.js in an admin cmd

@alallier thanks for answer! Sadly, but as admin in cmd also no success

@Alex-Sokolov not sure what's going on then without more details, that is what worked for me and many others in this issue thread.

@alallier Thanks for your time!

Found where is problem.
In my project .git folder not at the same level as node_modules, it located in parent folder.
Now pre-commit fails silently if not found .git folder at the same level.

There is pull-request #55. But not merged yet