1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Add subtree capability using :repo_tree variable

The variable `:repo_tree` now allows the specification of a sub-tree
that will be extracted from the repository when deploying. This is
useful when deploying a project that lives in a subdirectory of a larger
repository.  Implemented only for git and hg.  If not defined then the
behaviour is as previously and the whole repository is extracted.
All extraction is as before still subject to git-archive `.gitattributes`
This commit is contained in:
Nick Townsend 2014-10-10 15:42:32 -07:00
parent 121f884583
commit fcfe51bea6
6 changed files with 49 additions and 6 deletions

View file

@ -6,6 +6,14 @@ Reverse Chronological Order:
https://github.com/capistrano/capistrano/compare/v3.2.1...HEAD
* Enhancement (@townsen)
* Added the variable `:repo_tree` which allows the specification of a sub-tree that
will be extracted from the repository. This is useful when deploying a project
that lives in a subdirectory of a larger repository.
Implemented only for git and hg.
If not defined then the behaviour is as previously and the whole repository is
extracted (subject to git-archive `.gitattributes` of course).
* Enhancements (@townsen)
* Previously filtering would affect any generated configuration files so that
files newly deployed would not be the same as those on the hosts previously

View file

@ -257,6 +257,7 @@ The following variables are settable:
| Variable Name | Description | Notes |
|:---------------------:|----------------------------------------------------------------------|-----------------------------------------------------------------|
| `:repo_url` | The URL of your scm repository (git, hg, svn) | file://, https://, ssh://, or svn+ssh:// are all supported |
| `:repo_tree` | The subtree of the scm repository to deploy (git, hg) | Only implemented for git and hg repos. Extract just this tree |
| `:branch` | The branch you wish to deploy | This only has meaning for git and hg repos, to specify the branch of an svn repo, set `:repo_url` to the branch location. |
| `:scm` | The source control system used | `:git`, `:hg`, `:svn` are currently supported |
| `:tmp_dir` | The (optional) temp directory that will be used (default: /tmp) | if you have a shared web host, this setting may need to be set (i.e. /home/user/tmp/capistrano). |

View file

@ -30,7 +30,13 @@ class Capistrano::Git < Capistrano::SCM
end
def release
git :archive, fetch(:branch), '| tar -x -f - -C', release_path
if tree = fetch(:repo_tree)
tree = tree.slice %r#^/?(.*?)/?$#, 1
components = tree.split('/').size
git :archive, fetch(:branch), tree, "| tar -x --strip-components #{components} -f - -C", release_path
else
git :archive, fetch(:branch), '| tar -x -f - -C', release_path
end
end
def fetch_revision

View file

@ -27,7 +27,13 @@ class Capistrano::Hg < Capistrano::SCM
end
def release
hg "archive", release_path, "--rev", fetch(:branch)
if tree = fetch(:repo_tree)
tree = tree.slice %r#^/?(.*?)/?$#, 1
components = tree.split('/').size
hg "archive --type tgz -p . -I", tree, "--rev", fetch(:branch), "| tar -x --strip-components #{components} -f - -C", release_path
else
hg "archive", release_path, "--rev", fetch(:branch)
end
end
def fetch_revision

View file

@ -57,14 +57,25 @@ module Capistrano
end
describe "#release" do
it "should run git archive" do
context.expects(:fetch).returns(:branch)
it "should run git archive without a subtree" do
context.expects(:fetch).with(:repo_tree).returns(nil)
context.expects(:fetch).with(:branch).returns(:branch)
context.expects(:release_path).returns(:path)
context.expects(:execute).with(:git, :archive, :branch, '| tar -x -f - -C', :path)
subject.release
end
it "should run git archive with a subtree" do
context.expects(:fetch).with(:repo_tree).returns('tree')
context.expects(:fetch).with(:branch).returns(:branch)
context.expects(:release_path).returns(:path)
context.expects(:execute).with(:git, :archive, :branch, 'tree', '| tar -x --strip-components 1 -f - -C', :path)
subject.release
end
end
end
end

View file

@ -57,14 +57,25 @@ module Capistrano
end
describe "#release" do
it "should run hg archive" do
context.expects(:fetch).returns(:branch)
it "should run hg archive without a subtree" do
context.expects(:fetch).with(:repo_tree).returns(nil)
context.expects(:fetch).with(:branch).returns(:branch)
context.expects(:release_path).returns(:path)
context.expects(:execute).with(:hg, "archive", :path, "--rev", :branch)
subject.release
end
it "should run hg archive with a subtree" do
context.expects(:fetch).with(:repo_tree).returns('tree')
context.expects(:fetch).with(:branch).returns(:branch)
context.expects(:release_path).returns(:path)
context.expects(:execute).with(:hg, "archive --type tgz -p . -I", 'tree', "--rev", :branch, '| tar -x --strip-components 1 -f - -C', :path)
subject.release
end
end
end
end