From 1518cb1155ada26ab2995f10d8868bc115eb1f67 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 16 Jun 2013 10:47:53 -0600 Subject: [PATCH] Remove .git suffix on destination directory if URL ends with it. For example, the following: homesick clone git://github.com/technicalpickles/pickled-vim.git should produce a castle directory of: $HOME/.homesick/repos/pickled-vim --- lib/homesick/actions.rb | 5 +---- spec/homesick_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index 0accf72..c170174 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -4,10 +4,7 @@ class Homesick # TODO move this to be more like thor's template, empty_directory, etc def git_clone(repo, config = {}) config ||= {} - destination = config[:destination] || begin - repo =~ /([^\/]+)(?:\.git)?$/ - $1 - end + destination = config[:destination] || File.basename(repo, '.git') destination = Pathname.new(destination) unless destination.kind_of?(Pathname) FileUtils.mkdir_p destination.dirname diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 7200508..824ceb5 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -40,6 +40,14 @@ describe "homesick" do end end + it "should clone git repo like file:///path/to.git" do + bare_repo = File.join(create_construct.to_s, "dotfiles.git") + system "git init --bare #{bare_repo} >/dev/null 2>&1" + + homesick.clone "file://#{bare_repo}" + File.directory?(File.join(home.to_s, '.homesick/repos/dotfiles')).should be_true + 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')