'git fetch' is broken when 'bundle install' runs from a git merge rule #1650

Closed
ndbroadbent opened this Issue Feb 3, 2012 · 5 comments

4 participants

@ndbroadbent
  • Bundler version 1.1.rc.7
  • Ruby 1.9.2p290

I am using a git merge rule to automatically resolve conflicts in Gemfile.lock.

~/.gitconfig:

[merge "bundleinstall"]
  name = runs bundle install to generate Gemfile.lock
  driver = bundle install

and in app/.git/info/attributes:

Gemfile.lock merge=bundleinstall

Here's the output from bundler when a conflict happens:

Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Updating git://github.com/crossroads/crm_mingle.git
fatal: Not a git repository: '.git'
Git error: command `git fetch --force --quiet --tags 'git://github.com/crossroads/crm_mingle.git' "refs/heads/*:refs/heads/*"` in directory /home/ndbroadbent/.rvm/gems/ruby-1.9.2-p290/cache/bundler/git/crm_mingle-54cf84d4b1c69511512a16389eee687deb8abe92 has failed.
If this error persists you could try removing the cache directory '/home/ndbroadbent/.rvm/gems/ruby-1.9.2-p290/cache/bundler/git/crm_mingle-54cf84d4b1c69511512a16389eee687deb8abe92'
Auto-merging Gemfile
Auto-merging Gemfile.lock
CONFLICT (content): Merge conflict in Gemfile.lock

Then I run bundle install from the command line and it works fine.

Does anyone have any suggestions?

@eliotsykes

I'm getting a similar problem ("fatal: Not a git repository: '.git') with running 'bundle outdated' inside a git pre-commit hook script. Haven't found the solution yet...

If I call 'bundle outdated' directly then there is no problem at all.

Bundler version 1.1.3 on ruby 1.9.2p318 (2012-02-14 revision 34678) [x86_64-darwin11.3.0]

@eliotsykes

When running bundle inside of a git hook script, the GIT_DIR environment variable is set to '.git' which can interfere with any git commands bundler calls.

To workaround this, you can unset the GIT_DIR before bundle runs. After bundle finishes, set GIT_DIR back to its original value. In Ruby:

def outdated_gems
   # If GIT_DIR is set, this spec is likely being run inside of a git hook script (e.g. pre-commit)
   # GIT_DIR causes bundle outdated to break in version 1.1.3. See https://github.com/carlhuda/bundler/issues/1650
   original_git_dir = ENV['GIT_DIR']
   ENV['GIT_DIR'] = nil
   output = IO.popen('bundle outdated')
   ENV['GIT_DIR'] = original_git_dir
   return output
end

Or if you don't care about setting the GIT_DIR value back to its original value, you can just do this at the command line:

unset GIT_DIR && bundle outdated

@RaVbaker

When will it be fixed?

@radar

@ndbroadbent Is this issue solved?

@ndbroadbent

Just saw the comment from @eliotsykes, which probably explains the issue. Closing!

@ndbroadbent ndbroadbent closed this Aug 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment