Adapt to homebrew's move of the tap directory

Closes #4035. Closes #4029. Closes #4026.
This commit is contained in:
Roland Walker 2014-04-25 13:01:32 -04:00
parent c1df09c12b
commit 400433be20
12 changed files with 57 additions and 41 deletions

View File

@ -15,7 +15,7 @@ shopt -s nocasematch # case-insensitive regular expressions
### configurable global variables
###
tap_subdir="Library/Taps/phinze-cask"
tap_subdir="Library/Taps/phinze/homebrew-cask"
###
### functions

View File

@ -15,7 +15,7 @@ shopt -s nocasematch # case-insensitive regular expressions
### configurable global variables
###
tap_subdir="Library/Taps/phinze-cask"
tap_subdir="Library/Taps/phinze/homebrew-cask"
###
### functions

View File

@ -88,16 +88,17 @@ class Cask::CLI
def self.nice_listing(cask_list)
casks = {}
cask_list.each { |c|
repo, name = c.split "/"
user, repo, name = c.split '/'
repo.sub!(/^homebrew-/i, '')
casks[name] ||= []
casks[name].push repo
casks[name].push "#{user}/#{repo}"
}
list = []
casks.each { |name,repos|
if repos.length == 1
casks.each { |name,taps|
if taps.length == 1
list.push name
else
repos.each { |r| list.push [r,name].join "/" }
taps.each { |r| list.push [r,name].join '/' }
end
}
list.sort

View File

@ -30,10 +30,21 @@ PURPOSE
end
def self.github_info(cask)
tap = cask.title
tap = cask.class.all_titles.grep(/#{tap}$/).first unless tap =~ /\//
tap, name = tap.split "/"
user, repo = tap.split "-"
title = cask.title
title = cask.class.all_titles.grep(/#{title}$/).first unless title =~ /\//
path_elements = title.split '/'
if path_elements.count == 2
# eg phinze-cask/google-chrome.
# Not certain this form is needed, but it was supported in the past.
name = path_elements[1]
dash_elements = path_elements[0].split('-')
repo = dash_elements.pop
dash_elements.pop if dash_elements.count > 1 and dash_elements[-1] + '-' == repo_prefix
user = dash_elements.join('-')
else
user, repo, name = path_elements
end
repo.sub!(/^homebrew-/i, '')
"https://github.com/#{user}/homebrew-#{repo}/commits/master/Casks/#{name}.rb"
end

View File

@ -4,8 +4,10 @@ class Cask::CLI::Search
end
def self.extract_regexp(string)
%r{^/(.*)/$}.match(string) do |match|
match.captures.first
if %r{^/(.*)/$}.match(string) then
$1
else
false
end
end
@ -19,9 +21,9 @@ class Cask::CLI::Search
partial_matches = Cask::CLI.nice_listing(Cask.all_titles).grep(/#{search_regexp}/i)
else
# suppressing search of the font Tap is a quick hack until behavior can be made configurable
all_titles = Cask::CLI.nice_listing Cask.all_titles.reject{ |t| %r{^caskroom-fonts/}.match(t)}
simplified_titles = all_titles.map { |t| t.gsub(/[^a-z0-9]+/i, '') }
simplified_search_term = search_term.sub(/\.rb$/i,'').gsub(/[^a-z0-9]+/i, '')
all_titles = Cask::CLI.nice_listing Cask.all_titles.reject{ |t| %r{^caskroom/homebrew-fonts/}.match(t)}
simplified_titles = all_titles.map { |t| t.sub(/^.*\//, '').gsub(/[^a-z0-9]+/i, '') }
simplified_search_term = search_term.sub(/\.rb$/i, '').gsub(/[^a-z0-9]+/i, '')
exact_match = simplified_titles.grep(/^#{simplified_search_term}$/i) { |t| all_titles[simplified_titles.index(t)] }.first
partial_matches = simplified_titles.grep(/#{simplified_search_term}/i) { |t| all_titles[simplified_titles.index(t)] }
partial_matches.delete(exact_match)

View File

@ -97,7 +97,7 @@ module Cask::Locations
end
def default_tap
@default_tap ||= 'phinze-cask'
@default_tap ||= 'phinze/homebrew-cask'
end
def default_tap=(_tap)
@ -109,14 +109,16 @@ module Cask::Locations
cask_with_tap = cask_title
else
cask_with_tap = all_titles.detect { |tap_and_title|
_, title = tap_and_title.split('/')
user, repo, title = tap_and_title.split('/')
title == cask_title
}
end
if cask_with_tap
tap, cask = cask_with_tap.split('/')
tapspath.join(tap, 'Casks', "#{cask}.rb")
user, repo, cask = cask_with_tap.split('/')
# bug/todo: handle old-style 1-slash form: phinze-cask/name
repo = 'homebrew-' + repo unless repo.match(/^homebrew-/)
tapspath.join(user, repo, 'Casks', "#{cask}.rb")
else
tapspath.join(default_tap, 'Casks', "#{cask_title}.rb")
end

View File

@ -9,16 +9,16 @@ module Cask::Scopes
end
def all_titles
cask_titles = Dir[tapspath.join("*", "Casks", "*.rb")]
cask_titles = Dir[tapspath.join('*', '*', 'Casks', '*.rb')]
cask_titles.map { |c|
# => "/usr/local/Library/Taps/example-tap/Casks/example.rb"
# => "/usr/local/Library/Taps/caskroom/example-tap/Casks/example.rb"
c.sub!(/\.rb$/, '')
# => ".../example"
c = c.split("/").last 3
# => ["example-tap", "Casks", "example"]
c.delete_at 1
c = c.split('/').last 4
# => ["caskroom", "example-tap", "Casks", "example"]
c.delete_at(-2)
# => ["example-tap", "example"]
c = c.join "/"
c = c.join '/'
}
end

View File

@ -6,8 +6,8 @@ class Cask::Source::Tapped
def self.path_for_query(query)
cask_with_tap = Cask.all_titles.find { |t| t.split('/').last == query.sub(/\.rb$/i,'') }
if cask_with_tap
tap, cask = cask_with_tap.split('/')
Cask.tapspath.join(tap, 'Casks', "#{cask}.rb")
user, repo, cask = cask_with_tap.split('/')
Cask.tapspath.join(user, repo, 'Casks', "#{cask}.rb")
else
Cask.tapspath.join(Cask.default_tap, 'Casks', "#{query.sub(/\.rb$/i,'')}.rb")
end

View File

@ -8,7 +8,7 @@ class Cask::Source::TappedQualified < Cask::Source::Tapped
def self.path_for_query(query)
user, repo, cask = Cask::QualifiedCaskName::parse(query)
cask.sub!(/\.rb$/i,'')
tap = "#{user}-#{repo}"
tap = "#{user}/homebrew-#{repo}"
Cask.tapspath.join(tap, 'Casks', "#{cask}.rb")
end
end

View File

@ -5,7 +5,7 @@ class Cask::Source::UntappedQualified < Cask::Source::TappedQualified
def self.path_for_query(query)
user, repo, cask = Cask::QualifiedCaskName::parse(query)
cask.sub!(/\.rb$/i,'')
tap = "#{user}-#{repo}"
tap = "#{user}/homebrew-#{repo}"
unless Cask.tapspath.join(tap).exist?
ohai "Adding new tap '#{tap}'"
Homebrew.install_tap(user, repo)

View File

@ -3,13 +3,13 @@ require 'test_helper'
describe Cask::CLI do
it "lists the taps for casks that show up in two taps" do
Cask::CLI.nice_listing(%w[
phinze-cask/adium
phinze-cask/google-chrome
passcod-cask/adium
phinze/cask/adium
phinze/cask/google-chrome
passcod/homebrew-cask/adium
]).must_equal(%w[
google-chrome
passcod-cask/adium
phinze-cask/adium
passcod/cask/adium
phinze/cask/adium
])
end

View File

@ -9,7 +9,7 @@ HOMEBREW_BREW_FILE = '/usr/local/bin/brew'
# add cask lib to load path
brew_cask_path = Pathname.new(File.expand_path(__FILE__+'/../../'))
casks_path = brew_cask_path.join('casks')
casks_path = brew_cask_path.join('Casks')
lib_path = brew_cask_path.join('lib')
$:.push(lib_path)
@ -39,7 +39,7 @@ Mocha::Integration::MiniTest.activate
require 'cask'
# look for casks in testcasks by default
Cask.default_tap = 'phinze-testcasks'
Cask.default_tap = 'phinze/homebrew-testcasks'
# our own testy caskroom
Cask.caskroom = HOMEBREW_PREFIX.join('TestCaskroom')
@ -98,13 +98,13 @@ require 'tempfile'
# pretend like we installed the cask tap
project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../"))
taps_dest = HOMEBREW_LIBRARY/"Taps"
taps_dest = HOMEBREW_LIBRARY/"Taps/phinze"
# create directories
taps_dest.mkdir
FileUtils.mkdir_p taps_dest
HOMEBREW_PREFIX.join('bin').mkdir
FileUtils.ln_s project_root, taps_dest/"phinze-cask"
FileUtils.ln_s project_root, taps_dest/"homebrew-cask"
# Common superclass for tests casks for when we need to filter them out
class TestCask < Cask; end
@ -115,4 +115,4 @@ FileUtils.ln_s '/usr/local/bin/unar', HOMEBREW_PREFIX.join('bin/unar')
FileUtils.ln_s '/usr/local/bin/lsar', HOMEBREW_PREFIX.join('bin/lsar')
# also jack in some test casks
FileUtils.ln_s project_root/'test'/'support', taps_dest/"phinze-testcasks"
FileUtils.ln_s project_root/'test'/'support', taps_dest/"homebrew-testcasks"