follow Ruby Style Guide for some points
This commit is contained in:
@@ -33,7 +33,7 @@ class Homesick < Thor
|
||||
elsif uri =~ GITHUB_NAME_REPO_PATTERN
|
||||
destination = Pathname.new($1)
|
||||
git_clone "git://github.com/#{$1}.git", :destination => destination
|
||||
elsif uri =~ /\/([^\/]*?)(\.git)?\Z/
|
||||
elsif uri =~ /%r([^%r]*?)(\.git)?\Z/
|
||||
destination = Pathname.new($1)
|
||||
git_clone uri
|
||||
elsif uri =~ /[^:]+:([^:]+)(\.git)?\Z/
|
||||
@@ -149,9 +149,7 @@ class Homesick < Thor
|
||||
end
|
||||
|
||||
# are we tracking something nested? Add the parent dir to the manifest
|
||||
unless relative_dir.eql?(Pathname.new('.'))
|
||||
subdir_add(castle, relative_dir)
|
||||
end
|
||||
subdir_add(castle, relative_dir) unless relative_dir.eql?(Pathname.new('.'))
|
||||
end
|
||||
|
||||
desc 'list', 'List cloned castles'
|
||||
@@ -208,7 +206,9 @@ class Homesick < Thor
|
||||
dirs = Pathname.glob("#{repos_dir}/**/.git", File::FNM_DOTMATCH)
|
||||
# reject paths that lie inside another castle, like git submodules
|
||||
return dirs.reject do |dir|
|
||||
dirs.any? {|other| dir != other && dir.fnmatch(other.parent.join('*').to_s) }
|
||||
dirs.any? do |other|
|
||||
dir != other && dir.fnmatch(other.parent.join('*').to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -262,7 +262,9 @@ class Homesick < Thor
|
||||
def subdir_add(castle, path)
|
||||
subdir_filepath = subdir_file(castle)
|
||||
File.open(subdir_filepath, 'a+') do |subdir|
|
||||
subdir.puts path unless subdir.readlines.inject(false) { |memo, line| line.eql?("#{path.to_s}\n") || memo }
|
||||
subdir.puts path unless subdir.readlines.reduce(false) do |memo, line|
|
||||
line.eql?("#{path.to_s}\n") || memo
|
||||
end
|
||||
end
|
||||
|
||||
inside castle_dir(castle) do
|
||||
|
||||
@@ -20,7 +20,7 @@ class Homesick
|
||||
path = Pathname.new(path)
|
||||
|
||||
inside path do
|
||||
unless path.join('.git').exist?
|
||||
if !path.join('.git').exist?
|
||||
say_status 'git init', '' unless options[:quiet]
|
||||
system 'git init >/dev/null' unless options[:pretend]
|
||||
else
|
||||
@@ -33,7 +33,7 @@ class Homesick
|
||||
existing_remote = `git config remote.#{name}.url`.chomp
|
||||
existing_remote = nil if existing_remote == ''
|
||||
|
||||
unless existing_remote
|
||||
if !existing_remote
|
||||
say_status 'git remote', "add #{name} #{url}" unless options[:quiet]
|
||||
system "git remote add #{name} #{url}" unless options[:pretend]
|
||||
else
|
||||
|
||||
@@ -30,7 +30,12 @@ describe 'homesick' do
|
||||
it 'should not symlink' do
|
||||
homesick.should_not_receive(:git_clone)
|
||||
|
||||
homesick.clone @existing_dir.to_s rescue nil
|
||||
begin
|
||||
homesick.clone @existing_dir.to_s
|
||||
fail 'homesick.clone should raise'
|
||||
rescue => e
|
||||
e.message.should match 'Castle already cloned to'
|
||||
end
|
||||
end
|
||||
|
||||
it 'should raise an error' do
|
||||
@@ -80,7 +85,12 @@ describe 'homesick' do
|
||||
it 'should not try to clone a malformed uri like malformed' do
|
||||
homesick.should_not_receive(:git_clone)
|
||||
|
||||
homesick.clone 'malformed' rescue nil
|
||||
begin
|
||||
homesick.clone 'malformed'
|
||||
fail 'homesick.clone should raise'
|
||||
rescue => e
|
||||
e.message.should match 'Unknown URI format: malformed'
|
||||
end
|
||||
end
|
||||
|
||||
it 'should throw an exception when trying to clone a malformed uri like malformed' do
|
||||
@@ -129,7 +139,6 @@ describe 'homesick' do
|
||||
end
|
||||
|
||||
it 'can override existing directory' do
|
||||
somewhere_else = create_construct
|
||||
existing_dotdir = home.directory('.vim')
|
||||
|
||||
dotdir = castle.directory('.vim')
|
||||
@@ -168,22 +177,22 @@ describe 'homesick' do
|
||||
end
|
||||
end
|
||||
|
||||
context "with '.config' and '.config/appA' in .homesick_subdir" do
|
||||
let(:castle) { given_castle('glencairn', ['.config', '.config/appA']) }
|
||||
it 'can symlink under both of .config and .config/appA' do
|
||||
context "with '.config' and '.config/someapp' in .homesick_subdir" do
|
||||
let(:castle) { given_castle('glencairn', ['.config', '.config/someapp']) }
|
||||
it 'can symlink under both of .config and .config/someapp' do
|
||||
config_dir = castle.directory('.config')
|
||||
config_dotfile = config_dir.file('.some_dotfile')
|
||||
appA_dir = config_dir.directory('appA')
|
||||
appA_dotfile = appA_dir.file('.some_appfile')
|
||||
someapp_dir = config_dir.directory('someapp')
|
||||
someapp_dotfile = someapp_dir.file('.some_appfile')
|
||||
|
||||
homesick.symlink('glencairn')
|
||||
|
||||
home_config_dir = home.join('.config')
|
||||
home_appA_dir = home_config_dir.join('appA')
|
||||
home_someapp_dir = home_config_dir.join('someapp')
|
||||
home_config_dir.symlink?.should be == false
|
||||
home_config_dir.join('.some_dotfile').readlink.should be == config_dotfile
|
||||
home_appA_dir.symlink?.should be == false
|
||||
home_appA_dir.join('.some_appfile').readlink.should == appA_dotfile
|
||||
home_someapp_dir.symlink?.should be == false
|
||||
home_someapp_dir.join('.some_appfile').readlink.should == someapp_dotfile
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.configure do |config|
|
||||
Dir.chdir(castle) do
|
||||
system 'git init >/dev/null 2>&1'
|
||||
system "git remote add origin git://github.com/technicalpickles/#{name}.git >/dev/null 2>&1"
|
||||
if subdirs then
|
||||
if subdirs
|
||||
subdir_file = castle.join(Homesick::SUBDIR_FILENAME)
|
||||
subdirs.each do |subdir|
|
||||
system "echo #{subdir} >> #{subdir_file}"
|
||||
|
||||
Reference in New Issue
Block a user