aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorMax Howell2012-03-16 17:11:40 +0000
committerMax Howell2012-03-16 21:06:18 +0000
commit919f36717c3bac2bcd139fd01acfe02f098e001c (patch)
treec8b857ff542df08c31f8f88a60e99c4cbf8fb17b /Library/Homebrew
parent0f02354073b3424a8829d3b139cbc07c0dac5958 (diff)
downloadbrew-919f36717c3bac2bcd139fd01acfe02f098e001c.tar.bz2
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.
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/cmd/tap.rb19
-rw-r--r--Library/Homebrew/cmd/untap.rb10
2 files changed, 22 insertions, 7 deletions
diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb
index 6f235fede..48237a2e5 100644
--- a/Library/Homebrew/cmd/tap.rb
+++ b/Library/Homebrew/cmd/tap.rb
@@ -19,24 +19,33 @@ module Homebrew extend self
files = []
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
def link_tap_formula formulae
ignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
+ tapped = 0
cd HOMEBREW_LIBRARY/"Formula" do
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
system "ln -s ../Taps/#{formula} 2>/dev/null"
if $?.success?
ignores << formula.basename.to_s
+ tapped += 1
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}"
end
end
+
+ tapped
end
HOMEBREW_LIBRARY.join("Formula/.gitignore").atomic_write(ignores.uniq.join("\n"))
@@ -55,13 +64,13 @@ end
class Pathname
def tap_ref
- case self.realpath.to_s
+ case self.to_s
when %r{^#{HOMEBREW_LIBRARY}/Taps/(\w+)-(\w+)/(.+)}
"#$1/#$2/#{File.basename($3, '.rb')}"
when %r{^#{HOMEBREW_LIBRARY}/Formula/(.+)}
"mxcl/master/#{File.basename($1, '.rb')}"
else
- self.basenname('.rb').to_s
+ nil
end
end
end
diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb
index 51d99d913..892229df4 100644
--- a/Library/Homebrew/cmd/untap.rb
+++ b/Library/Homebrew/cmd/untap.rb
@@ -8,15 +8,21 @@ module Homebrew extend self
raise "No such tap!" unless tapd.directory?
gitignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
+ untapped = 0
tapd.find_formula do |pn|
bn = pn.basename.to_s
pn = HOMEBREW_LIBRARY/"Formula/#{bn}"
- pn.delete if pn.symlink? and pn.realpath.to_s =~ %r[^#{tapd.realpath}]
- gitignores.delete(bn)
+ if pn.symlink? and pn.realpath.to_s =~ %r[^#{tapd.realpath}]
+ pn.delete
+ gitignores.delete(bn)
+ untapped += 1
+ end
end
rm_rf tapd
HOMEBREW_REPOSITORY.join("Library/Formula/.gitignore").atomic_write(gitignores * "\n")
+
+ puts "Untapped #{untapped} formula"
end
end