follow Ruby Style Guide for some points
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
require 'pathname'
|
||||
lib = Pathname.new(__FILE__).dirname.join('..', 'lib').expand_path
|
||||
$LOAD_PATH.unshift lib.to_s
|
||||
$LOAD_PATH.unshift lib.to_s
|
||||
|
||||
require 'homesick'
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class Homesick < Thor
|
||||
GITHUB_NAME_REPO_PATTERN = /\A([A-Za-z_-]+\/[A-Za-z_-]+)\Z/
|
||||
SUBDIR_FILENAME = '.homesick_subdir'
|
||||
|
||||
def initialize(args=[], options={}, config={})
|
||||
def initialize(args = [], options = {}, config = {})
|
||||
super
|
||||
self.shell = Homesick::Shell.new
|
||||
end
|
||||
@@ -34,7 +34,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/
|
||||
@@ -68,7 +68,7 @@ class Homesick < Thor
|
||||
|
||||
desc 'pull CASTLE', 'Update the specified castle'
|
||||
method_option :all, :type => :boolean, :default => false, :required => false, :desc => 'Update all cloned castles'
|
||||
def pull(name='')
|
||||
def pull(name = '')
|
||||
if options[:all]
|
||||
inside_each_castle do |castle|
|
||||
shell.say castle.to_s.gsub(repos_dir.to_s + '/', '') + ':'
|
||||
@@ -150,9 +150,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'
|
||||
@@ -226,7 +224,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
|
||||
|
||||
@@ -280,7 +280,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
|
||||
@@ -326,7 +328,7 @@ class Homesick < Thor
|
||||
def symlink_each(castle, basedir, subdirs)
|
||||
absolute_basedir = Pathname.new(basedir).expand_path
|
||||
inside basedir do
|
||||
files = Pathname.glob('{.*,*}').reject{|a| ['.', '..'].include?(a.to_s)}
|
||||
files = Pathname.glob('{.*,*}').reject{ |a| ['.', '..'].include?(a.to_s) }
|
||||
files.each do |path|
|
||||
absolute_path = path.expand_path
|
||||
castle_home = castle_dir(castle)
|
||||
|
||||
@@ -21,7 +21,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
|
||||
@@ -34,7 +34,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
|
||||
|
||||
@@ -31,7 +31,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
|
||||
@@ -81,7 +86,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
|
||||
@@ -130,7 +140,6 @@ describe 'homesick' do
|
||||
end
|
||||
|
||||
it 'can override existing directory' do
|
||||
somewhere_else = create_construct
|
||||
existing_dotdir = home.directory('.vim')
|
||||
|
||||
dotdir = castle.directory('.vim')
|
||||
@@ -169,22 +178,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
|
||||
|
||||
@@ -16,13 +16,13 @@ RSpec.configure do |config|
|
||||
homesick.stub(:say_status)
|
||||
end
|
||||
|
||||
def given_castle(path, subdirs=[])
|
||||
def given_castle(path, subdirs = [])
|
||||
name = Pathname.new(path).basename
|
||||
castles.directory(path) do |castle|
|
||||
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