Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit ca8807a

Browse files
authored
Merge pull request #10140 from Golden007-prog/fix/10136-relative-bundler-override
Resolve local Git overrides from the Bundler project root
2 parents fc37d0f + 9f818b5 commit ca8807a

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

‎lib/bundler/source/git.rb‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@ def local_override!(path)
154154

155155
original_path = path
156156
path = Pathname.new(path)
157-
path = path.expand_path(Bundler.root) unless path.relative?
157+
begin
158+
# An empty value would expand to Bundler.root itself
159+
path = path.expand_path(Bundler.root) unless path.to_s.empty?
160+
rescue ArgumentError => e
161+
Bundler.ui.debug(e)
162+
raise GitError, "Cannot use local override for #{name} at #{path} because #{e.message}. Run " \
163+
"`bundle config unset local.#{override_for(original_path)}` to remove the local override"
164+
end
158165

159166
unless branch || Bundler.settings[:disable_local_branch_check]
160167
raise GitError, "Cannot use local override for #{name} at #{path} because " \

‎spec/install/gemfile/git_overrides_spec.rb‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,58 @@
1919
expect(out).to eq("LOCAL")
2020
end
2121

22+
it "resolves a relative local override against the project root from a subdirectory" do
23+
local = lib_path("local-myrack")
24+
build_git "myrack", "0.8", path: local
25+
26+
gemfile <<-G
27+
source "https://gem.repo1"
28+
gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main"
29+
G
30+
31+
env = { "BUNDLE_LOCAL__MYRACK" => local.relative_path_from(bundled_app).to_s }
32+
bundle :install, env: env
33+
bundle :check, dir: bundled_app("subdir").mkpath, env: env
34+
expect(out).to include("The Gemfile's dependencies are satisfied")
35+
end
36+
37+
it "expands a home-relative local override" do
38+
build_git "myrack", "0.8", path: home("local-myrack")
39+
40+
gemfile <<-G
41+
source "https://gem.repo1"
42+
gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main"
43+
G
44+
45+
bundle :install, env: { "BUNDLE_LOCAL__MYRACK" => "~/local-myrack" }
46+
expect(out).to include("Bundle complete!")
47+
end
48+
49+
it "reports a Git error for a local override with an unknown home directory" do
50+
skip "problems with ~ expansion" if Gem.win_platform?
51+
52+
gemfile <<-G
53+
source "https://gem.repo1"
54+
gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main"
55+
G
56+
57+
path = "~some_unexisting_user/local-myrack"
58+
bundle :install, env: { "BUNDLE_LOCAL__MYRACK" => path }, raise_on_error: false
59+
expect(exitstatus).to eq(11)
60+
expect(err).to include("Cannot use local override", path, "bundle config unset local.myrack")
61+
end
62+
63+
it "rejects an empty local override" do
64+
gemfile <<-G
65+
source "https://gem.repo1"
66+
gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main"
67+
G
68+
69+
bundle :install, env: { "BUNDLE_LOCAL__MYRACK" => "" }, raise_on_error: false
70+
expect(exitstatus).to eq(11)
71+
expect(err).to include("does not exist", "bundle config unset local.myrack")
72+
end
73+
2274
it "chooses the local repository on runtime" do
2375
build_git "myrack", "0.8"
2476

0 commit comments

Comments
 (0)