Allow symlinking existing directories into repos, instead of cloning.
This commit is contained in:
@@ -9,7 +9,7 @@ class Homesick < Thor
|
||||
|
||||
add_runtime_options!
|
||||
|
||||
GITHUB_NAME_REPO_PATTERN = /\A([A-Za-z_-]+)\/([A-Za-z_-]+)\Z/
|
||||
GITHUB_NAME_REPO_PATTERN = /\A([A-Za-z_-]+\/[A-Za-z_-]+)\Z/
|
||||
|
||||
def initialize(args=[], options={}, config={})
|
||||
super
|
||||
@@ -19,8 +19,10 @@ class Homesick < Thor
|
||||
desc "clone URI", "Clone +uri+ as a castle for homesick"
|
||||
def clone(uri)
|
||||
inside repos_dir do
|
||||
if uri =~ GITHUB_NAME_REPO_PATTERN
|
||||
git_clone "git://github.com/#{$1}/#{$2}.git", :destination => "#{$1}/#{$2}"
|
||||
if File.exist?(uri)
|
||||
ln_s uri, File.basename(uri)
|
||||
elsif uri =~ GITHUB_NAME_REPO_PATTERN
|
||||
git_clone "git://github.com/#{$1}.git", :destination => $1
|
||||
else
|
||||
git_clone uri
|
||||
end
|
||||
|
||||
@@ -20,6 +20,7 @@ class Homesick
|
||||
end
|
||||
|
||||
def ln_s(source, destination, config = {})
|
||||
source = Pathname.new(source)
|
||||
destination = Pathname.new(destination)
|
||||
|
||||
if destination.symlink?
|
||||
|
||||
@@ -6,6 +6,15 @@ describe Homesick do
|
||||
end
|
||||
|
||||
describe "clone" do
|
||||
it "should symlink existing directories" do
|
||||
somewhere = create_construct
|
||||
somewhere.directory('wtf')
|
||||
wtf = somewhere + 'wtf'
|
||||
|
||||
@homesick.should_receive(:ln_s).with(wtf.to_s, wtf.basename.to_s)
|
||||
|
||||
@homesick.clone wtf.to_s
|
||||
end
|
||||
it "should clone git repo like git://host/path/to.git" do
|
||||
@homesick.should_receive(:git_clone).with('git://github.com/technicalpickles/pickled-vim.git')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user