Link new tapped formula during brew update

Required me to spoil tap's code. All in the name of DRY! Alas!
This commit is contained in:
Max Howell 2012-03-07 22:48:44 +00:00
parent 2c84be96d8
commit 7280590e88
2 changed files with 29 additions and 10 deletions

View File

@ -21,21 +21,28 @@ module Homebrew extend self
raise "Already tapped!" if tapd.directory?
abort unless system "git clone https://github.com/#{user}/homebrew-#{repo} #{tapd}"
gitignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
files = []
tapd.find_formula{ |file| files << Pathname.new("#{user}-#{repo}").join(file) }
link_tap_formula(files)
end
cd HOMEBREW_LIBRARY/"Formula"
tapd.find_formula do |relative_pathname|
# using the system ln is the only way to get relative symlinks
system "ln -s ../Taps/#{user}-#{repo}/#{relative_pathname} 2>/dev/null"
if $?.success?
gitignores << relative_pathname.basename.to_s
else
opoo "#{relative_pathname.basename('.rb')} conflicts"
def link_tap_formula formulae
ignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
cd HOMEBREW_LIBRARY/"Formula" do
formulae.each do |formula|
# using the system ln is the only way to get relative symlinks
system "ln -s ../Taps/#{formula} 2>/dev/null"
if $?.success?
ignores << formula.basename.to_s
else
opoo "#{formula.basename('.rb')} conflicts"
end
end
end
tf = Tempfile.new("brew-tap")
tf.write(gitignores.uniq.join("\n"))
tf.write(ignores.uniq.join("\n"))
tf.close
mv tf.path, "#{HOMEBREW_LIBRARY}/Formula/.gitignore"
end

View File

@ -1,3 +1,5 @@
require 'cmd/tap'
module Homebrew extend self
def update
@ -14,6 +16,7 @@ module Homebrew extend self
master_updater.pull!
report.merge!(master_updater.report)
new_files = []
Dir["Library/Taps/*"].each do |tapd|
cd tapd do
updater = Updater.new
@ -23,6 +26,7 @@ module Homebrew extend self
end
end
end
Homebrew.link_tap_formula(report.new_tapped_formula)
if report.empty?
puts "Already up-to-date."
@ -117,6 +121,14 @@ class Report < Hash
# dump_deleted_commands
end
def new_tapped_formula
fetch(:A, []).map do |path|
case path when %r{^Library/Taps(/\w+-\w+/.*)}
Pathname.new($1)
end
end.compact
end
def select_formula key
fetch(key, []).map do |path|
case path when %r{^Library/Formula}