Skip to content

Commit

Permalink
Properly define tapped formulae in update
Browse files Browse the repository at this point in the history
A tapped formula is a ruby file present:

  - in the root of the tap
  - in directory of the tap called Formula
  - in a directory of the tap called HomebrewFormula

And nowhere else. This corrects an overzealous definition of tapped
formula in the updater. (the correct definition has been in Pathname
since e613cbe)

Refs Homebrew#19743.
Closes Homebrew#21087.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
  • Loading branch information
phinze authored and jacknagel committed Jul 10, 2013
1 parent 50de02b commit 0fab6c9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Library/Homebrew/cmd/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,24 @@ def dump
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
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/test/fixtures/updater_fixture.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions Library/Homebrew/test/test_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,28 @@ def test_update_homebrew_with_formulae_changes
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

0 comments on commit 0fab6c9

Please sign in to comment.