Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Don't display 'fatal: Not a git repository (or any of the parent directories): .git' if git package vendored #2039

Closed
drnic opened this issue Aug 1, 2012 · 21 comments

Comments

@drnic
Copy link

drnic commented Aug 1, 2012

[with bundler 1.2.0.rc on local & production machines]

If an application's Gemfile uses git repos, such as https://github.com/gitlabhq/gitlabhq/blob/master/Gemfile, and I run bundle package --all, and then in production run bundle install --local --deployment --without development test it gives the following error:

> /var/vcap/packages/ruby/bin/bundle install --local --deployment --without development test
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
Some gems seem to be missing from your vendor/cache directory.
Could not find libv8-3.3.10.4 in any of the sources
@drnic
Copy link
Author

drnic commented Aug 1, 2012

How can I vendor all the gems and not need git at all in production?

@drnic
Copy link
Author

drnic commented Aug 1, 2012

Why are there 10 instances of fatal: Not a git repository (or any of the parent directories): .git above, but in the Gemfile.lock there are only 8 GIT references matching to the 8 gems with :git sources in Gemfile.

@drnic
Copy link
Author

drnic commented Aug 1, 2012

"Could not find libv8-3.3.10.4 in any of the sources" is because it vendored a darwin gem instead of the source gem - libv8-3.3.10.4-x86_64-darwin-11.gem

@drnic
Copy link
Author

drnic commented Aug 1, 2012

It looks like the vendored gems arrived ok (and I worked around #2040 by adding the libv8.gem into vendor/cache explicitly).

Note, the entire application was ported to production as a tarball and not a git repository.

How can I tell bundler that its not a git repo any more and that all the vendored gems are where they should be (vendor/cache) and to be happy about that and not spew out 10 warning messages?

@drnic
Copy link
Author

drnic commented Aug 2, 2012

Updating title to match the issue - the vendored package installs correctly but I get ugly warnings whenever I run any bundle commands:

fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git

@fesplugas
Copy link

Updated to bundler 1.2.0 and still have the same problem.

@robolson
Copy link

This is happening for me as well and I dug into it a bit.

The error message is not coming from bundler but from git itself. The errors are coming from git commands executing inside of gemspecs. Almost always the command is git ls-files.

Unfortunately using git ls-files in gemspecs is becoming more and more common despite the fact that it makes Rails load slower.

I am not a Bundler contributor but I am not sure how Bundler can fix this problem short of not loading the gemspec files at all. However, these errors are really annoying and it makes it look like bundler has a bug.

@indirect
Copy link
Member

Yeah, I think this is the same bug that was recently fixed by explicitly setting GIT_DIR (the guy who figured it out noticed Bundler was broken inside post-commit hooks). I'm pretty sure that git ls-files is getting more common because it's the default in the basic gemspec generated by bundle gem. For what it's worth, it only slows down git gems. Gemspecs fetched from rubygems.org are pre-evaluated YAML files, and so git doesn't have to run there.

@subelsky
Copy link

subelsky commented Nov 6, 2012

The rubygems site has a good alternative to git ls-files that helped me get around this (because I'm having to package some private gems):

spec.files = Dir['lib/**/*.rb'] + Dir['bin/*']
spec.files += Dir['[A-Z]*'] + Dir['test/**/*']
spec.files.reject! { |fn| fn.include? "CVS" }

@indirect
Copy link
Member

@subelsky we just had a pretty long discussion about this in ticket #2023. I strongly suggest reading the comments there, but the tl;dr is that gitignores are pretty complicated. With some tweaking, that might be a viable replacement, though.

@subelsky
Copy link

@indirect Ahhh! I totally forgot about .gitignore. Fortunately in my case I'm using internal git gems so the impact is small. Thanks for pointing out the other issue!

@teejayvanslyke
Copy link

Any updates here? I'm having the same issue, although it appears to only occur on Heroku. Local commands work just fine.

@bison
Copy link
Contributor

bison commented Dec 7, 2012

This, at least in my case, is happening because Bundler removes the .git directory from the cached gems. See Bundler::Source::Git#cache:

def cache(spec)
  return unless Bundler.settings[:cache_all]
  return if path == app_cache_path
  cached!
  FileUtils.rm_rf(app_cache_path)
  git_proxy.checkout if requires_checkout?
  git_proxy.copy_to(app_cache_path, @submodules)
  FileUtils.rm_rf(app_cache_path.join(".git"))
  FileUtils.touch(app_cache_path.join(".bundlecache"))
end

Looks like this has been around since support for packaging gems from Git was added in 6ef6e75.

Can anyone explain the rationale behind this? Is it just a space saving effort? @josevalim?

Personally, I'm fine with needing Git installed in production, but these errors will happen either way.

@josevalim
Copy link
Contributor

The .git directories can contain many, many, many files. Maybe a solution is to cache the gemspec at the moment they are vendored. This would also speed up boot as other people mentioned.

@bison
Copy link
Contributor

bison commented Dec 7, 2012

That sounds reasonable. I don't know much about Bundler internals. Would that be as simple as looking for any .gemspec files in the app_cache_path, loading them, and replacing the contents with the results of the #to_ruby method on the Gem::Specification?

@bison
Copy link
Contributor

bison commented Dec 7, 2012

Here's my first pass at this: bison@d79b6a5c4297aeaec00553245320722910a24d79

It seems to work for me, but I have no idea if it's The Right Thing™.

@josevalim
Copy link
Contributor

It seems fine, but I am not that familiar with this particular bundler area. @indirect, @hone what do you think?

@indirect
Copy link
Member

indirect commented Dec 8, 2012

Hey guys, I've fixed this in the brand new 1.3.0.pre2 release. Can you try it out and let me know how it's working? Thanks.

@bison
Copy link
Contributor

bison commented Dec 10, 2012

Works great here. Thanks!

@allomov
Copy link

allomov commented Mar 18, 2015

have the same issue with bundler-1.3.5. @subelsky's suggestion worked for me.

ianfixes added a commit to ianfixes/Illuminator that referenced this issue Apr 14, 2015
sfroehler added a commit to shipcloud/billwerk that referenced this issue Sep 21, 2016
The use of `git ls-files` in the gemspec file
causes fatal error warning when loading the gem.

See rubygems/bundler#2039

Solution was found here:
rubygems/bundler#2039 (comment)
sfroehler added a commit to shipcloud/billwerk that referenced this issue Sep 21, 2016
The use of `git ls-files` in the gemspec file
causes fatal error warning when loading the gem.

See rubygems/bundler#2039

Solution was found here:
rubygems/bundler#2039 (comment)
sfroehler added a commit to shipcloud/billwerk that referenced this issue Sep 21, 2016
The use of `git ls-files` in the gemspec file
causes fatal error warning when loading the gem.

See rubygems/bundler#2039

Solution was found here:
rubygems/bundler#2039 (comment)
@nagipogu
Copy link

i am getting problem in Git bash
yesterday i run my server and shout down my laptop and open again it's showing error
HolySpirit@HolySpirit-PC MINGW64 ~
$ cd / D:\project files\globex\globex -root directory

HolySpirit@HolySpirit-PC MINGW64 /
$ git checkout master
fatal: Not a git repository (or any of the parent directories): .git

michaelkl pushed a commit to OnlinetoursGit/qiwi-pay that referenced this issue Aug 24, 2018
The use of `git ls-files` in the gemspec file
causes fatal error warning when loading the gem.

See rubygems/bundler#2039

Solution was found here:
rubygems/bundler#2039 (comment)
michaelkl pushed a commit to michaelkl/yajl-rest that referenced this issue Aug 24, 2018
The use of `git ls-files` in the gemspec file
causes fatal error warning when loading the gem.

See rubygems/bundler#2039
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants