File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,16 @@ def run
5353 [ HOMEBREW_REPOSITORY ]
5454 end
5555 else
56+ args . named . each do |name |
57+ if !args . cask? && !CoreTap . instance . installed? &&
58+ Homebrew ::API . formula_names . include? ( name . delete_prefix ( "#{ CoreTap . instance . name } /" ) )
59+ CoreTap . instance . install ( force : true )
60+ elsif !args . formula? && !CoreCaskTap . instance . installed? &&
61+ Homebrew ::API . cask_tokens . include? ( name . delete_prefix ( "#{ CoreCaskTap . instance . name } /" ) )
62+ CoreCaskTap . instance . install ( force : true )
63+ end
64+ end
65+
5666 expanded_paths = args . named . to_paths
5767 expanded_paths . each do |path |
5868 raise_with_message! ( path , args . cask? ) unless path . exist?
Original file line number Diff line number Diff line change @@ -358,6 +358,25 @@ def setup_unredable_cask(name)
358358
359359 expect ( described_class . new ( "foo" , "baz" ) . to_paths ( only : :cask ) ) . to eq [ cask_path , Cask ::CaskLoader . path ( "baz" ) ]
360360 end
361+
362+ context "when without_api: true" do
363+ it "returns a bare path for an API-known formula when the tap is not installed" do
364+ allow ( CoreTap . instance ) . to receive ( :installed? ) . and_return ( false )
365+
366+ require "api"
367+ allow ( Homebrew ::API ) . to receive ( :formula_names ) . and_return ( [ "foo" ] )
368+ allow ( Homebrew ::API ::Formula ) . to receive ( :all_formulae ) . and_return ( "foo" => { } )
369+
370+ named_args = described_class . new ( "foo" , without_api : true )
371+ paths = named_args . to_paths
372+
373+ # to_paths returns a bare expanded path (not the core formula path) because
374+ # without_api: true sets HOMEBREW_NO_INSTALL_FROM_API=1 which defeats the
375+ # API name fallback check. The brew edit command works around this by
376+ # auto-tapping before calling to_paths.
377+ expect ( paths . first . to_s ) . not_to match ( %r{homebrew-core/Formula} )
378+ end
379+ end
361380 end
362381
363382 describe "#to_taps" do
Original file line number Diff line number Diff line change 1818 . and not_to_output . to_stderr
1919 . and be_a_success
2020 end
21+
22+ it "auto-taps core when editing an API-known formula without the tap installed" do
23+ ( HOMEBREW_REPOSITORY /".git" ) . mkpath
24+
25+ allow ( CoreTap . instance ) . to receive ( :installed? ) . and_return ( false )
26+
27+ require "api"
28+ allow ( Homebrew ::API ) . to receive ( :formula_names ) . and_return ( [ "testball" ] )
29+ allow ( Homebrew ::API ::Formula ) . to receive ( :all_formulae ) . and_return ( "testball" => { } )
30+
31+ expect ( CoreTap . instance ) . to receive ( :install ) . with ( force : true ) do
32+ allow ( CoreTap . instance ) . to receive ( :installed? ) . and_return ( true )
33+ CoreTap . instance . clear_cache
34+
35+ formula_path = CoreTap . instance . path /"Formula" /"testball.rb"
36+ formula_path . dirname . mkpath
37+ formula_path . write <<~RUBY
38+ class Testball < Formula
39+ url "https://brew.sh/testball-1.0"
40+ end
41+ RUBY
42+ end
43+
44+ allow_any_instance_of ( described_class ) . to receive ( :exec_editor )
45+
46+ described_class . new ( [ "testball" ] ) . run
47+ end
2148end
You can’t perform that action at this time.
0 commit comments