Merge branch 'rweng-named_castles'
This commit is contained in:
@@ -34,23 +34,24 @@ module Homesick
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'clone URI', 'Clone +uri+ as a castle for homesick'
|
desc 'clone URI CASTLE_NAME', 'Clone +uri+ as a castle with name CASTLE_NAME for homesick'
|
||||||
def clone(uri)
|
def clone(uri, destination=nil)
|
||||||
|
destination = Pathname.new(destination) unless destination.nil?
|
||||||
|
|
||||||
inside repos_dir do
|
inside repos_dir do
|
||||||
destination = nil
|
|
||||||
if File.exist?(uri)
|
if File.exist?(uri)
|
||||||
uri = Pathname.new(uri).expand_path
|
uri = Pathname.new(uri).expand_path
|
||||||
fail "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s)
|
fail "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s)
|
||||||
|
|
||||||
destination = uri.basename
|
destination = uri.basename if destination.nil?
|
||||||
|
|
||||||
ln_s uri, destination
|
ln_s uri, destination
|
||||||
elsif uri =~ GITHUB_NAME_REPO_PATTERN
|
elsif uri =~ GITHUB_NAME_REPO_PATTERN
|
||||||
destination = Pathname.new(uri).basename
|
destination = Pathname.new(uri).basename if destination.nil?
|
||||||
git_clone "https://github.com/#{Regexp.last_match[1]}.git",
|
git_clone "https://github.com/#{Regexp.last_match[1]}.git",
|
||||||
destination: destination
|
destination: destination
|
||||||
elsif uri =~ /%r([^%r]*?)(\.git)?\Z/ || uri =~ /[^:]+:([^:]+)(\.git)?\Z/
|
elsif uri =~ /%r([^%r]*?)(\.git)?\Z/ || uri =~ /[^:]+:([^:]+)(\.git)?\Z/
|
||||||
destination = Pathname.new(Regexp.last_match[1].gsub(/\.git$/, '')).basename
|
destination = Pathname.new(Regexp.last_match[1].gsub(/\.git$/, '')).basename if destination.nil?
|
||||||
git_clone uri, destination: destination
|
git_clone uri, destination: destination
|
||||||
else
|
else
|
||||||
fail "Unknown URI format: #{uri}"
|
fail "Unknown URI format: #{uri}"
|
||||||
|
|||||||
@@ -155,6 +155,14 @@ describe Homesick::CLI do
|
|||||||
|
|
||||||
homesick.clone 'wfarr/dotfiles'
|
homesick.clone 'wfarr/dotfiles'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'accepts a destination', :focus do
|
||||||
|
expect(homesick).to receive(:git_clone)
|
||||||
|
.with('https://github.com/wfarr/dotfiles.git',
|
||||||
|
destination: Pathname.new('other-name'))
|
||||||
|
|
||||||
|
homesick.clone 'wfarr/dotfiles', 'other-name'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'rc' do
|
describe 'rc' do
|
||||||
|
|||||||
Reference in New Issue
Block a user