From 9a22513ba48a388b4ec3fce53e8116cf1f15170c Mon Sep 17 00:00:00 2001 From: Joshua Nichols Date: Thu, 1 Apr 2010 21:19:25 -0400 Subject: [PATCH] Allow symlinking existing directories into repos, instead of cloning. --- lib/homesick.rb | 8 +++++--- lib/homesick/actions.rb | 1 + spec/homesick_spec.rb | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index dcb6376..dbec486 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -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 diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index 2cf5b63..df7fa1d 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -20,6 +20,7 @@ class Homesick end def ln_s(source, destination, config = {}) + source = Pathname.new(source) destination = Pathname.new(destination) if destination.symlink? diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 70ea89d..3064ab1 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -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')