mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Allow cap to be run within subdir and still work
Much like rake can find its Rakefile even when run in a subdirectory, cap can now find its Capfile. Since cap is built on top of rake, this was really just restoring default behavior that was accidentally overridden. Also add a feature test to ensure it works.
This commit is contained in:
parent
2475485e1a
commit
ba8115a8f7
5 changed files with 29 additions and 6 deletions
|
@ -21,6 +21,7 @@ https://github.com/capistrano/capistrano/compare/v3.7.2...HEAD
|
|||
* Run `svn switch` to work with svn branches if repo_url is changed
|
||||
* [#1856](https://github.com/capistrano/capistrano/pull/1856): Fix hg repo_tree implementation - [@mattbrictson](https://github.com/mattbrictson)
|
||||
* [#1857](https://github.com/capistrano/capistrano/pull/1857): Don't emit doctor warning when repo_tree is set - [@mattbrictson](https://github.com/mattbrictson)
|
||||
* [#1860](https://github.com/capistrano/capistrano/pull/1860): Allow cap to be run within subdir and still work - [@mattbrictson](https://github.com/mattbrictson)
|
||||
* Your contribution here!
|
||||
|
||||
## `3.7.2` (2017-01-27)
|
||||
|
|
|
@ -2,6 +2,10 @@ When(/^I run cap "(.*?)"$/) do |task|
|
|||
@success, @output = TestApp.cap(task)
|
||||
end
|
||||
|
||||
When(/^I run cap "(.*?)" within the "(.*?)" directory$/) do |task, directory|
|
||||
@success, @output = TestApp.cap(task, directory)
|
||||
end
|
||||
|
||||
When(/^I run cap "(.*?)" as part of a release$/) do |task|
|
||||
TestApp.cap("deploy:new_release_path #{task}")
|
||||
end
|
||||
|
|
9
features/subdirectory.feature
Normal file
9
features/subdirectory.feature
Normal file
|
@ -0,0 +1,9 @@
|
|||
Feature: cap can be run from a subdirectory, and will still find the Capfile
|
||||
|
||||
Background:
|
||||
Given a test app with the default configuration
|
||||
And servers with the roles app and web
|
||||
|
||||
Scenario: Running cap from a subdirectory
|
||||
When I run cap "git:check" within the "config" directory
|
||||
Then the task is successful
|
|
@ -2,7 +2,7 @@ module Capistrano
|
|||
class Application < Rake::Application
|
||||
def initialize
|
||||
super
|
||||
@rakefiles = %w{capfile Capfile capfile.rb Capfile.rb} << capfile
|
||||
@rakefiles = %w{capfile Capfile capfile.rb Capfile.rb}
|
||||
end
|
||||
|
||||
def name
|
||||
|
@ -76,6 +76,15 @@ module Capistrano
|
|||
end
|
||||
end
|
||||
|
||||
# allows the `cap install` task to load without a capfile
|
||||
def find_rakefile_location
|
||||
if (location = super).nil?
|
||||
[capfile, Dir.pwd]
|
||||
else
|
||||
location
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def backtrace_pattern
|
||||
|
@ -96,7 +105,6 @@ module Capistrano
|
|||
super
|
||||
end
|
||||
|
||||
# allows the `cap install` task to load without a capfile
|
||||
def capfile
|
||||
File.expand_path(File.join(File.dirname(__FILE__), "..", "Capfile"))
|
||||
end
|
||||
|
|
|
@ -90,13 +90,14 @@ module TestApp
|
|||
File.open(shared_path.join(path), "w")
|
||||
end
|
||||
|
||||
def cap(task)
|
||||
run "bundle exec cap #{stage} #{task}"
|
||||
def cap(task, subdirectory=nil)
|
||||
run "bundle exec cap #{stage} #{task}", subdirectory
|
||||
end
|
||||
|
||||
def run(command)
|
||||
def run(command, subdirectory=nil)
|
||||
output = nil
|
||||
Dir.chdir(test_app_path) do
|
||||
dir = subdirectory ? test_app_path.join(subdirectory) : test_app_path
|
||||
Dir.chdir(dir) do
|
||||
output = `#{command}`
|
||||
end
|
||||
[$CHILD_STATUS.success?, output]
|
||||
|
|
Loading…
Reference in a new issue