Skip to content

Commit f88e797

Browse files
Edouard-chinmatzbot
authored andcommitted
[ruby/rubygems] Allow bundle pristine to work for git gems in the same repo:
- Fix ruby/rubygems#9186 - ### Problem Running `bundle pristine` in a Gemfile where there is many git gem pointing to the same repository will result in a error "Another git process seems to be running in this repository". ### Context This error is a regression since ruby/rubygems@a555fd6ccd17 where `bundle pristine` now runs in parallel which could lead to running simultaneous git operations in the same repository. ### Solution When Bundler pristine a git gem it does a `git reset --hard` without specifying a path. This means the whole repository will be reset. In this case, we can leverage that by just pristining one gem per unique git sources. This is also more efficient. ruby/rubygems@710ba514a8
1 parent 98cac1a commit f88e797

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

lib/bundler/cli/pristine.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def run
1111
definition = Bundler.definition
1212
definition.validate_runtime!
1313
installer = Bundler::Installer.new(Bundler.root, definition)
14+
git_sources = []
1415

1516
ProcessLock.lock do
1617
installed_specs = definition.specs.reject do |spec|
@@ -41,6 +42,9 @@ def run
4142
end
4243
FileUtils.rm_rf spec.extension_dir
4344
FileUtils.rm_rf spec.full_gem_path
45+
46+
next if git_sources.include?(source)
47+
git_sources << source
4448
else
4549
Bundler.ui.warn("Cannot pristine #{gem_name}. Gem is sourced from local path.")
4650
next

spec/bundler/commands/pristine_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,66 @@
8989
expect(changes_txt).to be_file
9090
expect(err).to include("Cannot pristine #{spec.name} (#{spec.version}#{spec.git_version}). Gem is locally overridden.")
9191
end
92+
93+
it "doesn't run multiple git processes for the same repository" do
94+
nested_gems = [
95+
"actioncable",
96+
"actionmailer",
97+
"actionpack",
98+
"actionview",
99+
"activejob",
100+
"activemodel",
101+
"activerecord",
102+
"activestorage",
103+
"activesupport",
104+
"railties",
105+
]
106+
107+
build_repo2 do
108+
nested_gems.each do |gem|
109+
build_lib gem, path: lib_path("rails/#{gem}")
110+
end
111+
112+
build_git "rails", path: lib_path("rails") do |s|
113+
nested_gems.each do |gem|
114+
s.add_dependency gem
115+
end
116+
end
117+
end
118+
119+
install_gemfile <<-G
120+
source 'https://rubygems.org'
121+
122+
git "#{lib_path("rails")}" do
123+
gem "rails"
124+
gem "actioncable"
125+
gem "actionmailer"
126+
gem "actionpack"
127+
gem "actionview"
128+
gem "activejob"
129+
gem "activemodel"
130+
gem "activerecord"
131+
gem "activestorage"
132+
gem "activesupport"
133+
gem "railties"
134+
end
135+
G
136+
137+
changed_files = []
138+
diff = "#Pristine spec changes"
139+
140+
nested_gems.each do |gem|
141+
spec = find_spec(gem)
142+
changed_files << Pathname.new(spec.full_gem_path).join("lib/#{gem}.rb")
143+
File.open(changed_files.last, "a") {|f| f.puts diff }
144+
end
145+
146+
bundle "pristine"
147+
148+
changed_files.each do |changed_file|
149+
expect(File.read(changed_file)).to_not include(diff)
150+
end
151+
end
92152
end
93153

94154
context "when sourced from gemspec" do

0 commit comments

Comments
 (0)