Don't break if symlink already exists during tap
This shouldn't happen but is possible and we should handle it. Also added some puts when tapping/untapping.
This commit is contained in:
parent
0f02354073
commit
919f36717c
@ -19,24 +19,33 @@ module Homebrew extend self
|
|||||||
|
|
||||||
files = []
|
files = []
|
||||||
tapd.find_formula{ |file| files << Pathname.new("#{user}-#{repo}").join(file) }
|
tapd.find_formula{ |file| files << Pathname.new("#{user}-#{repo}").join(file) }
|
||||||
link_tap_formula(files)
|
tapped = link_tap_formula(files)
|
||||||
|
puts "Tapped #{tapped} formula"
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_tap_formula formulae
|
def link_tap_formula formulae
|
||||||
ignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
|
ignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
|
||||||
|
tapped = 0
|
||||||
|
|
||||||
cd HOMEBREW_LIBRARY/"Formula" do
|
cd HOMEBREW_LIBRARY/"Formula" do
|
||||||
formulae.each do |formula|
|
formulae.each do |formula|
|
||||||
|
from = HOMEBREW_LIBRARY.join("Taps/#{formula}").tap_ref
|
||||||
|
to = HOMEBREW_LIBRARY.join("Formula/#{formula.basename}").tap_ref
|
||||||
|
|
||||||
|
# Unexpected, but possible, lets proceed as if nothing happened
|
||||||
|
formula.delete if from == to
|
||||||
|
|
||||||
# using the system ln is the only way to get relative symlinks
|
# using the system ln is the only way to get relative symlinks
|
||||||
system "ln -s ../Taps/#{formula} 2>/dev/null"
|
system "ln -s ../Taps/#{formula} 2>/dev/null"
|
||||||
if $?.success?
|
if $?.success?
|
||||||
ignores << formula.basename.to_s
|
ignores << formula.basename.to_s
|
||||||
|
tapped += 1
|
||||||
else
|
else
|
||||||
from = Pathname.new("../Taps").join(formula).tap_ref
|
|
||||||
to = HOMEBREW_LIBRARY.join("Formula/#{formula.basename}").tap_ref
|
|
||||||
opoo "Could not tap #{Tty.white}#{from}#{Tty.reset} over #{Tty.white}#{to}#{Tty.reset}"
|
opoo "Could not tap #{Tty.white}#{from}#{Tty.reset} over #{Tty.white}#{to}#{Tty.reset}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tapped
|
||||||
end
|
end
|
||||||
|
|
||||||
HOMEBREW_LIBRARY.join("Formula/.gitignore").atomic_write(ignores.uniq.join("\n"))
|
HOMEBREW_LIBRARY.join("Formula/.gitignore").atomic_write(ignores.uniq.join("\n"))
|
||||||
@ -55,13 +64,13 @@ end
|
|||||||
|
|
||||||
class Pathname
|
class Pathname
|
||||||
def tap_ref
|
def tap_ref
|
||||||
case self.realpath.to_s
|
case self.to_s
|
||||||
when %r{^#{HOMEBREW_LIBRARY}/Taps/(\w+)-(\w+)/(.+)}
|
when %r{^#{HOMEBREW_LIBRARY}/Taps/(\w+)-(\w+)/(.+)}
|
||||||
"#$1/#$2/#{File.basename($3, '.rb')}"
|
"#$1/#$2/#{File.basename($3, '.rb')}"
|
||||||
when %r{^#{HOMEBREW_LIBRARY}/Formula/(.+)}
|
when %r{^#{HOMEBREW_LIBRARY}/Formula/(.+)}
|
||||||
"mxcl/master/#{File.basename($1, '.rb')}"
|
"mxcl/master/#{File.basename($1, '.rb')}"
|
||||||
else
|
else
|
||||||
self.basenname('.rb').to_s
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,15 +8,21 @@ module Homebrew extend self
|
|||||||
raise "No such tap!" unless tapd.directory?
|
raise "No such tap!" unless tapd.directory?
|
||||||
|
|
||||||
gitignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
|
gitignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
|
||||||
|
untapped = 0
|
||||||
|
|
||||||
tapd.find_formula do |pn|
|
tapd.find_formula do |pn|
|
||||||
bn = pn.basename.to_s
|
bn = pn.basename.to_s
|
||||||
pn = HOMEBREW_LIBRARY/"Formula/#{bn}"
|
pn = HOMEBREW_LIBRARY/"Formula/#{bn}"
|
||||||
pn.delete if pn.symlink? and pn.realpath.to_s =~ %r[^#{tapd.realpath}]
|
if pn.symlink? and pn.realpath.to_s =~ %r[^#{tapd.realpath}]
|
||||||
gitignores.delete(bn)
|
pn.delete
|
||||||
|
gitignores.delete(bn)
|
||||||
|
untapped += 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rm_rf tapd
|
rm_rf tapd
|
||||||
|
|
||||||
HOMEBREW_REPOSITORY.join("Library/Formula/.gitignore").atomic_write(gitignores * "\n")
|
HOMEBREW_REPOSITORY.join("Library/Formula/.gitignore").atomic_write(gitignores * "\n")
|
||||||
|
|
||||||
|
puts "Untapped #{untapped} formula"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user