observing/pre-commit

Symlinks on Vagrant running on Windows

Opened this issue · 8 comments

I've been using this project for a while but am stuck with v0.0.11. My default OS is Windows (sad, I know), so to make things less weird I use Vagrant for development.

After 248d18c it's not possible to install pre-commit because of this:

vagrant@vagrant-ubuntu-trusty-64:~/cha/api/code$ npm install --save-dev pre-commit --no-bin-links
/
> pre-commit@1.0.6 install /home/vagrant/cha/api/code/node_modules/pre-commit
> node install.js

pre-commit:
pre-commit: Detected an existing git pre-commit hook
pre-commit: Old pre-commit hook backuped to pre-commit.old
pre-commit:
pre-commit:
pre-commit: Failed to symlink the hook file in your .git/hooks folder because:
pre-commit: EPROTO: protocol error, symlink '/home/vagrant/cha/api/code/node_modules/pre-commit/hook' -> '/home/vagrant/cha/api/code/.git/hooks/pre-co
mmit'
pre-commit: The hook was not installed.
pre-commit:
pre-commit@1.0.6 node_modules/pre-commit
└── shelljs@0.3.0

There are ways to enable symlinking from Vagrant on Windows, but they're all hacks and really, really painful.

What do you guys think about supporting copying again (in case symlink creation fails)? If you agree, I can send a PR to support this :)

Thanks!

The reason why we're symlinking is so we can use our node_modules inside of the hook as it will properly resolve to the node_modules of this project. By copying, we would lose all the functionality again making the codebase super hard to maintain and update. But if you know ways around and can create a working pull request, i'll be more than happy to merge that in.

That's true, I haven't thought about that. I'm gonna play with it over the weekend.

g-p-g commented

I don't think this is an issue only for Windows users, I would expect this to affect anyone using Vagrant or similar. The symlink it creates doesn't use relative paths, so I need to recreate it anyway.

I can't tell if this works on Windows (but I suspect it doesn't), but in the Vagrant instance I remove the symlink created and create another one either using ln -rs node_modules/pre-commit/hook .git/hooks/pre-commit or ln -s '../../node_modules/pre-commit/hook' .git/hooks/pre-commit and then I can run it outside Vagrant as the link gets resolved correctly.

@g-p-g So your suggestion is change symlinks to use relative paths instead of full paths and that could magically fix the issue?

g-p-g commented

@3rd-Eden what do you mean by magically? I explicitly mentioned that it doesn't work for me right now, even when using Vagrant inside Linux or OSX, that is not specific to Windows. The relative path fix the problem I have.

@g-p-g Yes, sorry about. I read it incorrectly.

+1 for this issue.
As far as some team members use window - this is the only thing that prevents us from using it.

Sorry for digging up this old issue, but I believe my PR solves this issue:
#84