Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Something keeps rewriting my Gemfile.lock [duplicate]

Tags:

ruby

bundler

Working on a shared project, I often find that my Gemfile.lock gets out of sync with the repository, producing error messages like:

$ git pull
Updating 1911275..8c5d26f
error: Your local changes to the following files would be overwritten by merge:
    Gemfile.lock
Please commit your changes or stash them before you merge.
Aborting

When I try to git stash the change, it doesn't work:

$ git stash
Saved working directory and index state WIP on development: 1911275 Merge branch 'development' of https://github.com/mygroup/myrepo into development
HEAD is now at 1911275 Merge branch 'development' of https://github.com/mygroup/myrepo into development
$ git status
On branch development
Your branch is behind 'origin/development' by 3 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   Gemfile.lock

no changes added to commit (use "git add" and/or "git commit -a")

If I stash and status quickly enough, I can see that the change is getting stashed:

$ git stash && git status
Saved working directory and index state WIP on development: 1911275 Merge branch 'development' of https://github.com/mygroup/myrepo into development
HEAD is now at 1911275 Merge branch 'development' of https://github.com/mygroup/myrepo into development
On branch development
Your branch is behind 'origin/development' by 3 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
nothing to commit, working tree clean

But another status shows that Gemfile.lock has come back:

$ git status
On branch development
Your branch is behind 'origin/development' by 3 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   Gemfile.lock

no changes added to commit (use "git add" and/or "git commit -a")

Unfortunately the same trick doesn't work with git stash && git pull; pull is too slow, and the lockfile reappears before the pull can succeed.

I thought it might be my IDE re-bundling in the background, but it happens whether or not the IDE is running. I can't find any running bundler processes, gem processes, or indeed any obvious Ruby processes of any kind.

Who or what is regenerating my file?

like image 726
David Moles Avatar asked Apr 12 '17 21:04

David Moles


People also ask

Is Gemfile lock automatically generated?

Gemfile. lock is automatically generated when you run bundle install or bundle update . It should never be edited manually.

What creates Gemfile lock?

The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.

Should Gemfile lock be checked in?

The Gem Development guide says that the Gemfile. lock file "should always be checked into version control." However, this is NOT true for Gems. For Applications, like your Rails apps, Sinatra apps, etc., it is true. The same does not go for Gems.

How do I remove gem from Gemfile lock?

You can run just bundle or bundle install to install gems based on your Gemfile. That will remove the instance of mygem from your Gemfile. lock file.


1 Answers

Found the culprit, thanks to this answer (this answer concurs): Spring. There were half a dozen rogue spring processes on my machine, and any or all of them must have been regenerating the file. Killing those processes solved the problem, and so far adding export DISABLE_SPRING=1 to my .bash_profile seems to have kept it from recurring.

(spring stop might have worked too. I don't know whether it stops all Spring processes or just one of them, though.)

like image 192
David Moles Avatar answered Oct 17 '22 11:10

David Moles