From 0440cd672db9fb149223f5983376d447eae18e63 Mon Sep 17 00:00:00 2001 From: Jacob Atzen Date: Tue, 17 Aug 2010 10:04:59 +0200 Subject: [PATCH] Don't try to clone uri's without a corresponding destination The code throws the exception undefined method `join' for nil:NilClass if destionation doesn't exist - so it's better to not call git_clone if destination is not present. --- lib/homesick.rb | 9 ++++----- spec/homesick_spec.rb | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) 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'))