Git tagging and rails gemfile - ruby-on-rails

I have a gem that is hosted on github and not yet pushed to rubygems, and I added a tag to the master branch of the gem like this:
git tag -a v0.1.0 -m "gem version 0.1.0"
git push origin -tags
and then in a rails application I have on github I edited my gemfile like so:
gem 'your-gem', git: 'git://github.com/your-repo/your-gem.git', tag: 'v0.1.0'
My question is, when I merge in additional changes into the master branch of my gem, my rails application will still point to the last commit before I made the tag? I just want to make sure adding additional changes to the gems master branch will not break anything in the rails app. Thank You

The correct command is git push origin --tags, or git push origin v0.1.0 if you want to push just the one tag, but otherwise yes, your expectation is correct.
See here for more on bundling gems from git repositories:
http://gembundler.com/v1.3/git.html

Related

Installing a gem using a commit's hash

I have really simple Gemfile:
source 'https://rubygems.org'
gem 'stripe-ruby-mock',
github: 'mnin/stripe-ruby-mock',
require: 'stripe_mock',
ref: 'b6446fb5ae2b14b6703554cbea4ebd466e4f3c47'
When I run bundle command to install this gem I get this error:
root#6bcff6bf3997:/app# bundle
The git source `git://github.com/mnin/stripe-ruby-mock.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
Fetching git://github.com/mnin/stripe-ruby-mock.git
fatal: Could not parse object 'b6446fb5ae2b14b6703554cbea4ebd466e4f3c47'.
Revision b6446fb5ae2b14b6703554cbea4ebd466e4f3c47 does not exist in the repository git://github.com/mnin/stripe-ruby-mock.git. Maybe you misspelled it?
But I can visit the commit's page on Github using this link https://github.com/mnin/stripe-ruby-mock/commit/b6446fb5ae2b14b6703554cbea4ebd466e4f3c47.
So how can I the gem using this commit's hash?
That commit is not reachable from any branch or tag. For that reason, when you clone the repo from GitHub (which Bundler does under the hood), your local copy will not have that commit.
Thus, you can't use it.
On GitHub, you can see that this commit is not reachable as it doesn't list any branch or tag that contains it:
Compare that to the parent commit, which lists as being reachable from master:
Note that orphaned commits would get garbage collected by Git eventually. GitHub though doesn't do that as there might be references to particular commits.
Try not to use forked gem if possible. But if you need to lock a forked version, make sure you own the fork. Fork the forked branch, merge it to your own repo's main branch, and then just use that repo in your gemfile.

I pushed gemfile and gemfile.lock to my branch, do I have to merge to master?

I did a git add, git commit, and git push for 9 files (2 of those being Gemfile and Gemfile.lock). My team has informed me that we do not need Gemfile and gemfile.lock in the code review. What is the easiest way to revert these 2 files? (I would like to keep the other 7). I pushed these changes to my branch, can I ignore them when I am merging to master? Or should I somehow revert the changes to the 2 files (Gemfile and gemfile.lock)?
The simplest thing is to reset Gemfile and Gemfile.lock to their present state on master.
You can do this in two ways; either by adding a new commit which discards your changes to those files, or by amending whichever commit introduced those changes.
The former is the simplest. Add a new commit on your branch which discards the changes you made to Gemfile and Gemfile.lock:
Check out your branch, in its current state, with Gemfile and Gemfile.lock
Check out master's version of Gemfile and Gemfile.lock:
$ git checkout master -- Gemfile Gemfile.lock
Add and commit your changes
$ git add Gemfile Gemfile.lock
$ git commit -m "Discard changes to Gemfile and Gemfile.lock"
Now you can push, and the changes will disappear from your branch.
Note that this is the easier solution but that it leaves your branch in a slightly weird state, both introducing and removing changes to some files. Once you've done this, you can squash your entire branch down to a single commit prior to merging, and all history of the needlessly introduced changes to Gemfile and Gemfile.lock will be discarded.

How to update forked github repo on heroku

I have a forked Github repo which is used by my app deployed on heroku. I included it in my Gemfile like this :
gem 'service-client', :git => 'https://github.com/blabla/client-stuff'
Now I changed some parts of the forked repo, which requires no changes in my heroku app.
So how can I make my heroku app, rebundle or do the bundle install or whatever to pick up the latest changes from https://github.com/blabla/client-stuff master branch?
You should update gem localy and write changes to Gemfile.lock by bundle update service-client then commit changes and push to origin. Heroku update you gemset when look in to the changes in Gemfile.lock.
Unfortunately it does require changes in your heroku app.
It requires the newest gem version. You will have to push up to heroku again so that it can re bundle your Gemfile.
there is not way to run a bundle update on heroku itself because this could cause git fast-forward issues along with other unexpected consequences where a newer gem does not work appropriately.
Heroku is a production environment and all changes should be tested locally before deploying
See this SO Question

Trouble pushing basic Ruby on Rails app to Heroku

I was working through the first chapter of the Rails Tutorial. I pushed first_app to heroku. At first I was getting the sqlite3 error (I think). But, I edited the gemfile and pushed it up to heroku again. But, I don't get the same page as on: http://railstutorial.org/ruby-on-rails-tutorial-book#sec:1.4.3 (I think it's supposed to look like Figure 1.11 in section 1.4.3)
Instead, I get this: http://blooming-samurai-546.heroku.com/
It just says:
Heroku | Welcome to your new app!
Refer to the documentation if you need help deploying.
I did something wrong right? Any ideas what?
In your git console try:
git add .
git commit -am "Initial commit"
git push heroku
It looks like you pushed to heroku with nothing so it created an empty directory.
I had this same issue and was very frustrated by it. What solved the issue for me was moving
gem 'sqlite3'
into the block following
group :development, :test
in the Gemfile.
After that, no longer saw these kinds of messages:
remote: ! Failed to install gems via Bundler.
remote: ! Detected sqlite3 gem which is not supported on Heroku:
...
remote: ! Push rejected, failed to compile Ruby app.
in terminal after typing git push heroku or git push heroku master
Hope this helps.
Can’t argue with success.
However, before pushing the master with $ git push heroku master some folks may need to run the following command:
$ git remote add heroku git#heroku.com:your-heroku-url-goes-here.git
as discussed in the “Git Remotes and Heroku” section currently at:
http://devcenter.heroku.com/articles/git

Updating an unpacked and customised gem

We have an interesting scenario I need to sort out:
1) We have an existing application running with an unpacked gem
2) The application has some customisations to the unpacked gem
3) I would like to somehow "merge" a new version of said gem into this unpacked gem to bring it up to date.
Any ideas on a nice way of doing this?
All the code is in git, although the gem source is in a different repo.
You can compute the diff with git.
Create a new empty repository and copy the customized Gem.
Add the changes and commit.
$ mkdir thegem
$ cd thegem
$ git init
$ cp -r /path/to/gem/* .
$ git add *
$ git commit -m "Custom Gem"
Now download a snapshot of the original Gem and replace all the content of the folder (exept the .git folder). Add and commit.
Now you can view the differences between the first and second commit to know what changed in your customized Gem.

Resources