From 75dcad8ea4839ffd75527c027c45b6279c72c0fa Mon Sep 17 00:00:00 2001 From: Trae Robrock Date: Tue, 16 Jul 2013 21:13:03 -0700 Subject: [PATCH 1/4] Fix #19 homesickrc pathname needs a to_s to eval Also, moved the file evaluation into a new function so the script can be ran manually which should make testing these scripts easier. --- lib/homesick.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index 81b9a05..04a3d18 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -52,13 +52,21 @@ class Homesick < Thor end end + rc(destination) + end + end + + desc 'rc CASTLE', 'Run the .homesickrc for the specified castle' + def rc(name = DEFAULT_CASTLE_NAME) + inside repos_dir do + destination = Pathname.new(name) homesickrc = destination.join('.homesickrc').expand_path if homesickrc.exist? - proceed = shell.yes?("#{uri} has a .homesickrc. Proceed with evaling it? (This could be destructive)") + proceed = shell.yes?("#{name} has a .homesickrc. Proceed with evaling it? (This could be destructive)") if proceed shell.say_status 'eval', homesickrc inside destination do - eval homesickrc.read, binding, homesickrc.expand_path + eval homesickrc.read, binding, homesickrc.expand_path.to_s end else shell.say_status 'eval skip', "not evaling #{homesickrc}, #{destination} may need manual configuration", :blue From b043f2a5ed66f1dcf0aca6cc8eeacb58df383d2b Mon Sep 17 00:00:00 2001 From: Trae Robrock Date: Wed, 17 Jul 2013 07:23:35 -0700 Subject: [PATCH 2/4] Adding test for clone running homesickrc --- spec/homesick_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 173897c..6f30efe 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -11,6 +11,22 @@ describe 'homesick' do before { homesick.stub!(:repos_dir).and_return(castles) } describe 'clone' do + context 'has a .homesickrc' do + it 'should run the .homesickrc' do + somewhere = create_construct + local_repo = somewhere.directory('some_repo') + local_repo.file('.homesickrc') do |file| + file << "File.open(Dir.pwd + '/testing', 'w') { |f| f.print 'testing' }" + end + + expect($stdout).to receive(:print) + expect($stdin).to receive(:gets).and_return('y') + homesick.clone local_repo + + castles.join('some_repo').join('testing').should exist + end + end + context 'of a file' do it 'should symlink existing directories' do somewhere = create_construct From 8e06beced644b7e88b3947e881b6543e5bc3b9ad Mon Sep 17 00:00:00 2001 From: Trae Robrock Date: Wed, 17 Jul 2013 07:26:00 -0700 Subject: [PATCH 3/4] Ignore vendor --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e16687e..6fccad9 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,5 @@ pkg .idea/ *.iml -Gemfile.lock \ No newline at end of file +Gemfile.lock +vendor/ From 4b20c7224e5c655d21b3db086b2de3bbd39d5d76 Mon Sep 17 00:00:00 2001 From: Trae Robrock Date: Wed, 17 Jul 2013 08:04:34 -0700 Subject: [PATCH 4/4] Add tests for the rc command --- spec/homesick_spec.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 6f30efe..936e99c 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -100,6 +100,44 @@ describe 'homesick' do end end + describe 'rc' do + let(:castle) { given_castle('glencairn') } + + context 'when told to do so' do + before do + expect($stdout).to receive(:print) + expect($stdin).to receive(:gets).and_return('y') + end + + it 'executes the .homesickrc' do + castle.file('.homesickrc') do |file| + file << "File.open(Dir.pwd + '/testing', 'w') { |f| f.print 'testing' }" + end + + homesick.rc castle + + castle.join('testing').should exist + end + end + + context 'when told not to do so' do + before do + expect($stdout).to receive(:print) + expect($stdin).to receive(:gets).and_return('n') + end + + it 'does not execute the .homesickrc' do + castle.file('.homesickrc') do |file| + file << "File.open(Dir.pwd + '/testing', 'w') { |f| f.print 'testing' }" + end + + homesick.rc castle + + castle.join('testing').should_not exist + end + end + end + describe 'symlink' do let(:castle) { given_castle('glencairn') }