diff options
-rw-r--r-- | railties/lib/rails/app_rails_loader.rb | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/railties/lib/rails/app_rails_loader.rb b/railties/lib/rails/app_rails_loader.rb index ef6fcd81b4..aae628290d 100644 --- a/railties/lib/rails/app_rails_loader.rb +++ b/railties/lib/rails/app_rails_loader.rb @@ -6,15 +6,15 @@ module Rails EXECUTABLES = ['bin/rails', 'script/rails'] def self.exec_app_rails - cwd = Dir.pwd - pathname = Pathname.new(Dir.pwd) + original_cwd = Dir.pwd until exe = find_executable - # Return to working directory if root is hit without finding executable - Dir.chdir(cwd) and return if pathname.root? - # Otherwise keep moving upwards in search of executable - Dir.chdir("..") - pathname = pathname.parent + # If we exhaust the search there is no executable, this could be a + # call to generate a new application, so restore the original cwd. + Dir.chdir(original_cwd) and return if Pathname.new(Dir.pwd).root? + + # Otherwise keep moving upwards in search of a executable. + Dir.chdir('..') end contents = File.read(exe) @@ -58,6 +58,5 @@ generate it and add it to source control: def self.find_executable EXECUTABLES.find { |exe| File.exists?(exe) } end - end end |