-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bundle install
when older revisions of git source
#6980
Fix bundle install
when older revisions of git source
#6980
Conversation
Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality. We use GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions in the PR status window below. If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #rubygems or #bundler channel on Slack. For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just a small comment!
Fix `bundle install` when older revisions of git source (cherry picked from commit e0bdcd6)
Fix `bundle install` when older revisions of git source (cherry picked from commit e0bdcd6)
Fix `bundle install` when older revisions of git source (cherry picked from commit e0bdcd6)
Fix `bundle install` when older revisions of git source (cherry picked from commit e0bdcd6)
This seems to break with really old versions of
One fix is to set git "config", "uploadpack.allowAnySHA1InWant", "true", :dir => destination if ref here didn't seem to actually change the cache repository config. If someone can point me at the right place in the code, I can send a PR. Environment
Bundler Build Metadata
|
Hei! Interesting! So this used to work for you and only broke after the latest release including this PR? My understanding is that I googled the error and found this thread which points to submodule issues? Is a git submodule involved here? |
👋 I just wanted to report we're seeing the similar happen when using https://github.com/DataDog/omnibus-software as a git source in our Gemfile (no git submoduled involved). We see this with git 2.7 and 2.10, but not with 2.40. |
Thank you, since that's an open source repo, it should be easily reproducible, right? What do I need to do to see the issue for myself? |
Since this sounds fixed in |
I'm in the same boat as @bkabrda — no submodules involved, also erroring out on an Unfortunately, upgrading git is not an option for us — we build on a variety of older platforms in Docker containers, and we're stuck with the system git. |
Repro instructionsSave the following files in a new directory:
FROM opensuse/leap:42.3 as base
RUN zypper -n install git curl which tar
RUN mv /var/lib/ca-certificates/pem/DST_Root_CA_X3.pem /etc/pki/trust/blacklist/ \
&& update-ca-certificates
RUN gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
RUN curl -sSL -o get-rvm-io.sh https://get.rvm.io \
&& /bin/bash get-rvm-io.sh stable
RUN ["/bin/bash", "-lc", "rvm requirements && rvm install 3.1.2"]
ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" skipcache
ARG BUNDLER_VERSION=2.4.21
RUN ["/bin/bash", "-lc", "gem install bundler --no-document --version ${BUNDLER_VERSION}"]
COPY 6980.rb /6980.rb
RUN ["/bin/bash", "-lc", "rvm use 3.1.2 && bundle --version && ruby /6980.rb"]
require 'tmpdir'
Dir.mktmpdir do |dir|
app_path = "#{dir}/app"
Dir.mkdir(app_path)
File.write("#{app_path}/Gemfile", <<~GEMFILE)
source 'https://rubygems.org'
gem 'omnibus-software', :github => 'chef/omnibus-software'
GEMFILE
Dir.chdir(app_path) do
system 'bundle config --local path vendor/bundle'
system 'bundle config --local clean true'
end
Dir.chdir(app_path) do
system 'bundle install' # => Git error
end
end Invoke as follows:
(or just
Invoke to see it succeed with
Note To see the effect of
|
Nice investigation and repro @igorpeshansky 😍 I think you are basically on the right track but you were running the git command in the wrong folder, it should be:
Besides that, this setting is not the default in git, so I'd feel more confortable keeping it like that on git versions without this bug. So I'd go with something like: diff --git a/bundler/lib/bundler/source/git/git_proxy.rb b/bundler/lib/bundler/source/git/git_proxy.rb
index 93625145c..0b507abc7 100644
--- a/bundler/lib/bundler/source/git/git_proxy.rb
+++ b/bundler/lib/bundler/source/git/git_proxy.rb
@@ -131,7 +131,11 @@ def copy_to(destination, submodules = false)
end
ref = @commit_ref || (locked_to_full_sha? && @revision)
- git "fetch", "--force", "--quiet", *extra_fetch_args(ref), :dir => destination if ref
+ if ref
+ git "config", "uploadpack.allowAnySHA1InWant", "true", :dir => path.to_s if @commit_ref.nil? && needs_allow_any_sha1_in_want?
+
+ git "fetch", "--force", "--quiet", *extra_fetch_args(ref), :dir => destination
+ end
git "reset", "--hard", @revision, :dir => destination
@@ -434,6 +438,10 @@ def supports_minus_c?
@supports_minus_c ||= Gem::Version.new(version) >= Gem::Version.new("1.8.5")
end
+ def needs_allow_any_sha1_in_want?
+ @needs_allow_any_sha1_in_want ||= Gem::Version.new(version) <= Gem::Version.new("2.13.7")
+ end
+
def supports_fetching_unreachable_refs?
@supports_fetching_unreachable_refs ||= Gem::Version.new(version) >= Gem::Version.new("2.5.0")
end I'm not sure which git version fixed this bug, but I guess we workaround it for everyone who has noticed it here and move on, that's why I set 2.13.7. We could also do a proper bisection by manually building from source different git versions, or try to rescue the error message and retry configuring that setting right before, but feels overkill to me. |
What was the end-user or developer problem that led to this PR?
Fixes #6929.
bundle install
may fail if an old revision is specified for a gem of git source.At that time, the following error occurs.
What is your fix for the problem, implemented in this PR?
This implementation is to execute
fetch
after copying to the installation directory. Because the target commit may exist in the repository in cache, but not in the destination repository.Make sure the following tasks are checked