diff --git a/lib/homesick.rb b/lib/homesick.rb index 15d1764..74a9e88 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 diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 5b9117a..360cf26 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 @@ -84,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') }