diff --git a/Library/Homebrew/cmd/update.rb b/Library/Homebrew/cmd/update.rb index 6f4992deeea34d56e1d808888b57285f2c146540..b3248c5cb32aeab6bbe8b1be592ed7030e0c73e0 100644 --- a/Library/Homebrew/cmd/update.rb +++ b/Library/Homebrew/cmd/update.rb @@ -146,11 +146,24 @@ class Report < Hash def tapped_formula_for key fetch(key, []).map do |path| case path when %r{^Library/Taps/(\w+-\w+/.*)} - Pathname.new($1) + relative_path = $1 + if valid_formula_location?(relative_path) + Pathname.new(relative_path) + end end end.compact end + def valid_formula_location?(relative_path) + ruby_file = /\A.*\.rb\Z/ + parts = relative_path.split('/')[1..-1] + [ + parts.length == 1 && parts.first =~ ruby_file, + parts.length == 2 && parts.first == 'Formula' && parts.last =~ ruby_file, + parts.length == 2 && parts.first == 'HomebrewFormula' && parts.last =~ ruby_file, + ].any? + end + def new_tapped_formula tapped_formula_for :A end diff --git a/Library/Homebrew/test/fixtures/updater_fixture.yaml b/Library/Homebrew/test/fixtures/updater_fixture.yaml index cbe50d051c21622037fa06f6b02a25218d7541bb..e761db6ed70d79a52c96d58cd6e851ccf2765d8d 100644 --- a/Library/Homebrew/test/fixtures/updater_fixture.yaml +++ b/Library/Homebrew/test/fixtures/updater_fixture.yaml @@ -25,3 +25,9 @@ update_git_diff_output_with_formulae_changes: | :100644 100644 cc176d388507c7ed9381a36fd42ae0feceaad593 6a7a2385d89a12b5c7369fa0a87980b285ee5fd8 M Library/Homebrew/utils.rb :100644 100644 d1d9c62e6280bcb06c8b884c188d7bd37f8754e3 4aa0473705264cac864bd09f8a9d419d805e4774 M README :100644 100644 c0084b02faf7ab04abcffb3d5688e9d7c1ff7ae8 25cae981801e21cde048cd28747241d18093ca71 M bin/brew +update_git_diff_output_with_tapped_formulae_changes: | + :100644 100644 9dde0708e2db78e1aa697782bd2ab2ddfd8da984 ee0a81cbe3757e9a4b5aab1c41457f65fed9f258 M Library/Contributions/brew_bash_completion.sh + :100644 100644 741f11dcd29ec909a94fa54df4bcdd2c1d5bb47b 7535134e865994e8ad66ba02a924a1e6c1271b9e A Library/Taps/someuser-sometap/Formula/antiword.rb + :100644 100644 741f11dcd29ec909a94fa54df4bcdd2c1d5bb47b 7535134e865994e8ad66ba02a924a1e6c1271b9e A Library/Taps/someuser-sometap/HomebrewFormula/lua.rb + :100644 100644 741f11dcd29ec909a94fa54df4bcdd2c1d5bb47b 7535134e865994e8ad66ba02a924a1e6c1271b9e A Library/Taps/someuser-sometap/custom-formula.rb + :100644 100644 741f11dcd29ec909a94fa54df4bcdd2c1d5bb47b 7535134e865994e8ad66ba02a924a1e6c1271b9e A Library/Taps/someuser-sometap/lib/not-a-formula.rb diff --git a/Library/Homebrew/test/test_updater.rb b/Library/Homebrew/test/test_updater.rb index 20aba015a73d550df676ad700b67cb581ed7af68..1464e1084d7359917ffc8f638c5549404f0121cc 100644 --- a/Library/Homebrew/test/test_updater.rb +++ b/Library/Homebrew/test/test_updater.rb @@ -102,4 +102,28 @@ class UpdaterTests < Test::Unit::TestCase assert_equal %w{ shapelib }, report.select_formula(:R) end end + + def test_update_homebrew_with_tapped_formula_changes + diff_output = fixture('update_git_diff_output_with_tapped_formulae_changes') + HOMEBREW_REPOSITORY.cd do + updater = UpdaterMock.new + updater.in_repo_expect("git checkout -q master") + updater.in_repo_expect("git rev-parse -q --verify HEAD", "1234abcd") + updater.in_repo_expect("git config core.autocrlf false") + updater.in_repo_expect("git pull -q origin refs/heads/master:refs/remotes/origin/master") + updater.in_repo_expect("git rev-parse -q --verify HEAD", "3456cdef") + updater.in_repo_expect("git diff-tree -r --raw -M85% 1234abcd 3456cdef", diff_output) + updater.pull! + report = Report.new + report.merge!(updater.report) + + assert updater.expectations_met? + assert_equal [ + Pathname('someuser-sometap/Formula/antiword.rb'), + Pathname('someuser-sometap/HomebrewFormula/lua.rb'), + Pathname('someuser-sometap/custom-formula.rb'), + ], report.tapped_formula_for(:A) + end + + end end