Not executing on bundle install
adambutler opened this issue · comments
First of all ❤️ the idea of this project, and is exactly what I am after. However, I'm not seeing it behave as documented.
I am finding that the script is not being executed on bundle install
, but works perfectly if I invoke it with bundle exec git-hookshot
.
It seems perhaps pre_install
is not being executed or something is up with the output
.
When I run the following in irb
then output
is an empty string. I do get the symlink created though.
require "hookshot"
output = Hookshot.with_captured_stdout do
current_working_directory = `lsof -p #{Process.ppid} | grep cwd`.split(" ").last
Hookshot.link(current_working_directory: current_working_directory)
end
output === ""
=> true
I am running ruby 2.4.1
with bundler 1.15.1
.
I've got an open PR here exhibiting this issue.
Update: Changing my Gemfile to point to this repo seems to work. My guess is that the released gem has a bug in it and requires updating.
Hmm, interesting. This required a ton of testing to get it to work, and so I tested it by pointing to the repo rather than pushing a gem. I wonder if Bundler behaves slightly differently depending on where the gem comes from…
I'll play around with it and see what I can figure out.
Maybe ¯_(ツ)_/¯
I was trying to debug the gem itself so I cloned it from GitHub and changed my Gemfile to use my cloned versions path
when I noticed it started working.
This is when I changed it to point to GitHub to test which again seemed to work just fine. After this I had just assumed the published Gem was outdated.
Hmm, OK, so if you're manually running the code in the pre_install
hook, I'd guess the reason there's no output is because the hooks directories had already been created? I think if you deleted the contents of .git/hooks
and .hooks
you'd see output.
Which leaves the problem of why Gem.pre_install
hook is not being triggered in some instances…
Also, I'm amazed you found this 😂 I was waiting to tell anyone about it until I'd confirmed it worked consistently.
I know right? I searched git hooks
on RubyGems.org, but nearly everything was about Ruby wrappers for writing Git Hooks... not really what I was looking for.
I wanted something like the shared-git-hooks
project but for Ruby land.
I then searched for git hooks share
... one result. Mind blown when I saw "Initial commit... a day ago" 😍
So it turns out this 🔮 dark magic 🔮 can be quite scary...
Looks like it's broken deploys for us on Heroku. I'd suggest finding a way of making this run without lsof
or failing elegantly. For now though I'm sadly going to have to remove the gem.
[...]
remote: Using coffee-script 2.4.1
remote: Using turbolinks 5.0.1
remote: Using activesupport 5.1.0.rc1
remote: Using loofah 2.0.3
remote: Using mail 2.6.4
remote: Installing recaptcha 4.3.1
remote: sh: 1: lsof: not found
remote: Installing unf_ext 0.0.7.4 with native extensions
remote: sh: 1: lsof: not found
remote: The latest bundler is 1.15.3, but you are currently running 1.15.2.
remote: To update, run `gem install bundler`
remote: Errno::ENOENT: No such file or directory @ rb_file_s_symlink -
remote: (/tmp/build_0cce25259cbb38c1ac704fdd31ba83b5/.hooks/pre-push,
remote: /tmp/build_0cce25259cbb38c1ac704fdd31ba83b5/.git/hooks/pre-push)
remote: An error occurred while installing netrc (0.11.0), and Bundler cannot continue.
remote: Make sure that `gem install netrc -v '0.11.0'` succeeds before bundling.
remote:
remote: In Gemfile:
remote: rest-client was resolved to 2.0.2, which depends on
remote: netrc
remote: !
remote: ! Failed to install gems via Bundler.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to redacted.
remote:
To https://git.heroku.com/redacted.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/redacted.git'
Ruh roh! Hmm… would this be solved by putting in the development
group? That way it would only be triggered locally (when deploying you usually bundle install --without="development test"
).