diff --git a/lib/homesick.rb b/lib/homesick.rb index 0a6eb08..313117e 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -27,12 +27,11 @@ class Homesick < Thor elsif uri =~ GITHUB_NAME_REPO_PATTERN destination = Pathname.new($1) git_clone "git://github.com/#{$1}.git", :destination => destination - else - if uri =~ /\/([^\/]*).git\Z/ - destination = Pathname.new($1) - end - + elsif uri =~ /\/([^\/]*)(\.git)?\Z/ + destination = Pathname.new($1) git_clone uri + else + raise "Unknown URI format: #{uri}" end if destination.join('.gitmodules').exist? diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index c1ccf0f..2da7971 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -34,6 +34,24 @@ describe Homesick do @homesick.clone 'http://github.com/technicalpickles/pickled-vim.git' end + it "should clone git repo like http://host/path/to" do + @homesick.should_receive(:git_clone).with('http://github.com/technicalpickles/pickled-vim') + + @homesick.clone 'http://github.com/technicalpickles/pickled-vim' + end + + it "should not try to clone a malformed uri like malformed" do + @homesick.should_not_receive(:git_clone) + + @homesick.clone 'malformed' rescue nil + end + + it "should throw an exception when trying to clone a malformed uri like malformed" do + lambda { + @homesick.clone 'malformed' + }.should raise_error + end + it "should clone a github repo" do @homesick.should_receive(:git_clone).with('git://github.com/wfarr/dotfiles.git', :destination => Pathname.new('wfarr/dotfiles'))