RubyGems post-install hook not triggering #5429
Comments
The easiest way I found to test this out is to create a new gem. Add a file at Gem.post_install do
File.write("~/test.txt", "it worked!")
end If you do But if you create a new folder, add a Gemfile, and reference your gem via |
Thanks for reporting this! Running |
Hmm, if memory serves I also tried that because I suspected |
Yeah, I just tried it with a private gem on GitHub… oh wait, does that not work either? Does it only trigger the install hook if the source is RubyGems? |
@brandonweiss I honestly don't know about git gems, but I would only expect a post-install hook to run from an actual .gem file coming from a gem server, yeah. |
No wait, that doesn't make any sense, because if I |
OK, my theory is that it has something to do with that I install gems with I tried to test this out by not installing using the path flag, although… that's weird, I don't see the gem when I do
Shouldn't it be in the outer-level gem directory? Did Bundler change at some point to nest it inside the Bundler gem? |
Bundler only should be running the install hooks when it runs an actual gem installer, which definitely doesn't happen for path gems |
By “path gems” do you mean a gem that is referenced in a Gemfile via the |
Via the |
@brandonweiss to answer your earlier question, I believe that gems in |
@indirect Oh, well I am installing it via GitHub at the moment, so that would make sense why it's being installed there. OK, so maybe it's still bypassing the RubyGems install process and thus not triggering the post-install hook. Let me try publishing a gem to RubyGems and see if installing via bundler triggers the post-install hook. |
ping @brandonweiss |
I'm closing this for now but feel free to open this again if needed |
The install from path not triggering |
Please share a gemfile that we can use to reproduce the issue |
Remove the workaround here: The run Expected behaviour: |
Ah now I understand, thanks! |
@glebm gems from paths are never installed, and that's why the post install hook is not firing. can you describe what you would expect to happen with a post install hook for gems that aren't installed? what's the goal you're trying to accomplish? |
@indirect it's just that the plugin file should be loaded, if I'm understanding correctly. I have a patch nearly done |
Sorry I haven't followed up with a repro 😞 Distracted by too many things. It's possible the term “installation” might have a particular meaning here that I'm not getting, but if I made a gem, someone might “install” it in a number of ways. Manually to global gems
From a Gemfile with Bundler to global gemssource "http://rubygems.org"
gem "gem_name"
From a Gemfile via path with Bundler to global gemssource "http://rubygems.org"
gem "gem_name", path: "~/Code/gem_name"
From a Gemfile with Bundler to local pathsource "http://rubygems.org"
gem "gem_name"
It's possible there are some other permutations I'm not thinking of, but from my perspective, running |
This case doesn't actually install |
@segiddins True but that seems to be an implementation detail. I think the common expectation is that |
Loading the plugins is separate from post install hooks, and I think loading them is totally reasonable |
If you load the plugins, their post-install hooks will run, right? |
*post- and pre-install hooks |
Maybe I don't understand the terminology… I would assume loading the plugin would then trigger a pre/post-install hook (if one exists) because they’re defined in |
Yes, that's what I think as well. Just checking as I am a bit confused by @segiddins's last comment |
Looks like hooks will not trigger during the gems installation (by design): http://help.rubygems.org/discussions/problems/378-gempre_install-does-not-working-as-it-named |
[Installer] Load plugin files from path gems Closes #5429 . Because RubyGems doesn't know about path gems before we install, we need to manually load the plugin files for the path gems we're installing. This is basically copying the logic RG uses, but scoped only to those gems that we're entirely responsible for.
Damn. That is really disappointing. |
OK, I sort of got it working, actually. Here's the repo: https://github.com/brandonweiss/git-hookshot Instead of using But someone just noticed that if they use RubyGems as a source then it doesn't work. Is that expected? That pre/post install hooks would run if the source is from GitHub but not RubyGems? |
I see a lot of talk about Bundler install hooks on different issues/PRs that (like this thread) mentions that Bundler respects RubyGems post install hooks, but I'm testing it out and that doesn't seem to be the case… if I install via
gem install
the hook runs, but if I add the gem to a Gemfile and install it doesn't seem to be triggering the hook. Is that unexpected?The text was updated successfully, but these errors were encountered: