capistrano 2.0.0 → 2.15.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +7 -0
- data/CHANGELOG +737 -18
- data/Gemfile +13 -0
- data/README.md +94 -0
- data/Rakefile +11 -0
- data/bin/cap +0 -0
- data/bin/capify +37 -22
- data/capistrano.gemspec +40 -0
- data/lib/capistrano/callback.rb +5 -1
- data/lib/capistrano/cli/execute.rb +10 -7
- data/lib/capistrano/cli/help.rb +39 -16
- data/lib/capistrano/cli/help.txt +44 -16
- data/lib/capistrano/cli/options.rb +71 -11
- data/lib/capistrano/cli/ui.rb +13 -1
- data/lib/capistrano/cli.rb +5 -5
- data/lib/capistrano/command.rb +215 -58
- data/lib/capistrano/configuration/actions/file_transfer.rb +29 -14
- data/lib/capistrano/configuration/actions/inspect.rb +3 -3
- data/lib/capistrano/configuration/actions/invocation.rb +224 -22
- data/lib/capistrano/configuration/alias_task.rb +26 -0
- data/lib/capistrano/configuration/callbacks.rb +26 -27
- data/lib/capistrano/configuration/connections.rb +130 -52
- data/lib/capistrano/configuration/execution.rb +34 -18
- data/lib/capistrano/configuration/loading.rb +99 -6
- data/lib/capistrano/configuration/log_formatters.rb +75 -0
- data/lib/capistrano/configuration/namespaces.rb +45 -12
- data/lib/capistrano/configuration/roles.rb +28 -2
- data/lib/capistrano/configuration/servers.rb +51 -10
- data/lib/capistrano/configuration/variables.rb +3 -3
- data/lib/capistrano/configuration.rb +20 -4
- data/lib/capistrano/errors.rb +12 -8
- data/lib/capistrano/ext/multistage.rb +67 -0
- data/lib/capistrano/ext/string.rb +5 -0
- data/lib/capistrano/extensions.rb +1 -1
- data/lib/capistrano/fix_rake_deprecated_dsl.rb +8 -0
- data/lib/capistrano/logger.rb +112 -5
- data/lib/capistrano/processable.rb +55 -0
- data/lib/capistrano/recipes/compat.rb +2 -2
- data/lib/capistrano/recipes/deploy/assets.rb +201 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +2 -2
- data/lib/capistrano/recipes/deploy/local_dependency.rb +10 -2
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +54 -2
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +31 -11
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +14 -14
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +11 -9
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +12 -1
- data/lib/capistrano/recipes/deploy/scm/git.rb +293 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +23 -15
- data/lib/capistrano/recipes/deploy/scm/none.rb +55 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +54 -28
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +36 -18
- data/lib/capistrano/recipes/deploy/scm.rb +1 -1
- data/lib/capistrano/recipes/deploy/strategy/base.rb +32 -4
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +238 -43
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +1 -1
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +11 -1
- data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +21 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +1 -1
- data/lib/capistrano/recipes/deploy.rb +265 -123
- data/lib/capistrano/recipes/standard.rb +1 -1
- data/lib/capistrano/role.rb +102 -0
- data/lib/capistrano/server_definition.rb +6 -1
- data/lib/capistrano/shell.rb +30 -33
- data/lib/capistrano/ssh.rb +46 -60
- data/lib/capistrano/task_definition.rb +16 -8
- data/lib/capistrano/transfer.rb +218 -0
- data/lib/capistrano/version.rb +6 -17
- data/lib/capistrano.rb +4 -1
- data/test/cli/execute_test.rb +3 -3
- data/test/cli/help_test.rb +33 -7
- data/test/cli/options_test.rb +109 -6
- data/test/cli/ui_test.rb +2 -2
- data/test/cli_test.rb +3 -3
- data/test/command_test.rb +144 -124
- data/test/configuration/actions/file_transfer_test.rb +41 -20
- data/test/configuration/actions/inspect_test.rb +21 -7
- data/test/configuration/actions/invocation_test.rb +123 -30
- data/test/configuration/alias_task_test.rb +118 -0
- data/test/configuration/callbacks_test.rb +41 -46
- data/test/configuration/connections_test.rb +187 -36
- data/test/configuration/execution_test.rb +18 -2
- data/test/configuration/loading_test.rb +33 -4
- data/test/configuration/namespace_dsl_test.rb +54 -5
- data/test/configuration/roles_test.rb +114 -4
- data/test/configuration/servers_test.rb +97 -4
- data/test/configuration/variables_test.rb +12 -2
- data/test/configuration_test.rb +9 -13
- data/test/deploy/local_dependency_test.rb +76 -0
- data/test/deploy/remote_dependency_test.rb +146 -0
- data/test/deploy/scm/accurev_test.rb +23 -0
- data/test/deploy/scm/base_test.rb +1 -1
- data/test/deploy/scm/bzr_test.rb +51 -0
- data/test/deploy/scm/darcs_test.rb +37 -0
- data/test/deploy/scm/git_test.rb +274 -0
- data/test/deploy/scm/mercurial_test.rb +134 -0
- data/test/deploy/scm/none_test.rb +35 -0
- data/test/deploy/scm/perforce_test.rb +23 -0
- data/test/deploy/scm/subversion_test.rb +68 -0
- data/test/deploy/strategy/copy_test.rb +240 -26
- data/test/extensions_test.rb +2 -2
- data/test/logger_formatting_test.rb +149 -0
- data/test/logger_test.rb +13 -2
- data/test/recipes_test.rb +25 -0
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +15 -2
- data/test/shell_test.rb +33 -1
- data/test/ssh_test.rb +40 -24
- data/test/task_definition_test.rb +18 -2
- data/test/transfer_test.rb +168 -0
- data/test/utils.rb +28 -33
- metadata +215 -101
- data/MIT-LICENSE +0 -20
- data/README +0 -43
- data/examples/sample.rb +0 -14
- data/lib/capistrano/gateway.rb +0 -131
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/recipes/upgrade.rb +0 -33
- data/lib/capistrano/upload.rb +0 -146
- data/test/gateway_test.rb +0 -167
- data/test/upload_test.rb +0 -131
- data/test/version_test.rb +0 -24
|
@@ -63,15 +63,16 @@ module Capistrano
|
|
|
63
63
|
scm cvs_root, :log, range_arg
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
# Unfortunately, cvs doesn't support the concept of a revision number like
|
|
66
|
+
# Unfortunately, cvs doesn't support the concept of a revision number like
|
|
67
67
|
# subversion and other SCM's do. For now, we'll rely on getting the timestamp
|
|
68
68
|
# of the latest checkin under the revision that's passed to us.
|
|
69
69
|
def query_revision(revision)
|
|
70
70
|
return revision if revision_type(revision) == :date
|
|
71
71
|
revision = yield(scm(cvs_root, :log, "-r#{revision}")).
|
|
72
|
-
|
|
72
|
+
split("\n").
|
|
73
|
+
select { |line| line =~ /^date:/ }.
|
|
73
74
|
map { |line| line[/^date: (.*?);/, 1] }.
|
|
74
|
-
sort.last
|
|
75
|
+
sort.last + " UTC"
|
|
75
76
|
return revision
|
|
76
77
|
end
|
|
77
78
|
|
|
@@ -83,7 +84,7 @@ module Capistrano
|
|
|
83
84
|
case text
|
|
84
85
|
when /\bpassword.*:/i
|
|
85
86
|
# prompting for a password
|
|
86
|
-
"#{variable(:scm_password) || variable(:password)}\n
|
|
87
|
+
%("#{variable(:scm_password) || variable(:password)}"\n)
|
|
87
88
|
when %r{\(yes/no\)}
|
|
88
89
|
# let's be agreeable...
|
|
89
90
|
"yes\n"
|
|
@@ -98,7 +99,7 @@ module Capistrano
|
|
|
98
99
|
root << "-d #{repository} " if repository
|
|
99
100
|
root
|
|
100
101
|
end
|
|
101
|
-
|
|
102
|
+
|
|
102
103
|
# Constructs the destination dir command-line option
|
|
103
104
|
def cvs_destination(destination)
|
|
104
105
|
dest = ""
|
|
@@ -108,23 +109,24 @@ module Capistrano
|
|
|
108
109
|
end
|
|
109
110
|
dest
|
|
110
111
|
end
|
|
111
|
-
|
|
112
|
+
|
|
112
113
|
# attempts to guess what type of revision we're working with
|
|
113
114
|
def revision_type(rev)
|
|
115
|
+
return :date if rev =~ /^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2} UTC$/ # i.e 2007-05-15 08:13:25 UTC
|
|
114
116
|
return :date if rev =~ /^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}$/ # i.e 2007-05-15 08:13:25
|
|
115
117
|
return :revision if rev =~ /^\d/ # i.e. 1.2.1
|
|
116
118
|
return :tag # i.e. RELEASE_1_2
|
|
117
119
|
end
|
|
118
|
-
|
|
120
|
+
|
|
119
121
|
# constructs the appropriate command-line switch for specifying a
|
|
120
122
|
# "revision" in CVS. This could be a tag, branch, revision (i.e. 1.3)
|
|
121
123
|
# or a date (to be used with -d)
|
|
122
124
|
def cvs_revision(rev)
|
|
123
125
|
revision = ""
|
|
124
126
|
revision << case revision_type(rev)
|
|
125
|
-
when :date
|
|
127
|
+
when :date
|
|
126
128
|
"-D \"#{rev}\"" if revision_type(rev) == :date
|
|
127
|
-
when :revision
|
|
129
|
+
when :revision
|
|
128
130
|
"-r #{rev}"
|
|
129
131
|
else
|
|
130
132
|
"-r #{head}"
|
|
@@ -18,11 +18,22 @@ module Capistrano
|
|
|
18
18
|
:head
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def to_match(revision)
|
|
22
|
+
if revision.nil? || revision == self.head
|
|
23
|
+
nil
|
|
24
|
+
else
|
|
25
|
+
"--to-match='hash #{revision}'"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
21
29
|
# Returns the command that will check out the given revision to the
|
|
22
30
|
# given destination. The 'revision' parameter must be the 'hash' value
|
|
23
31
|
# for the revision in question, as given by 'darcs changes --xml-output'.
|
|
24
32
|
def checkout(revision, destination)
|
|
25
|
-
scm :get, verbose,
|
|
33
|
+
scm :get, *[verbose,
|
|
34
|
+
"--repo-name=#{destination}",
|
|
35
|
+
to_match(revision),
|
|
36
|
+
repository].compact
|
|
26
37
|
end
|
|
27
38
|
|
|
28
39
|
# Tries to update the destination repository in-place, to bring it up
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
require 'capistrano/recipes/deploy/scm/base'
|
|
2
|
+
|
|
3
|
+
module Capistrano
|
|
4
|
+
module Deploy
|
|
5
|
+
module SCM
|
|
6
|
+
|
|
7
|
+
# An SCM module for using Git as your source control tool with Capistrano
|
|
8
|
+
# 2.0. If you are using Capistrano 1.x, use this plugin instead:
|
|
9
|
+
#
|
|
10
|
+
# http://scie.nti.st/2007/3/16/capistrano-with-git-shared-repository
|
|
11
|
+
#
|
|
12
|
+
# Assumes you are using a shared Git repository.
|
|
13
|
+
#
|
|
14
|
+
# Parts of this plugin borrowed from Scott Chacon's version, which I
|
|
15
|
+
# found on the Capistrano mailing list but failed to be able to get
|
|
16
|
+
# working.
|
|
17
|
+
#
|
|
18
|
+
# FEATURES:
|
|
19
|
+
#
|
|
20
|
+
# * Very simple, only requiring 2 lines in your deploy.rb.
|
|
21
|
+
# * Can deploy different branches, tags, or any SHA1 easily.
|
|
22
|
+
# * Supports prompting for password / passphrase upon checkout.
|
|
23
|
+
# (I am amazed at how some plugins don't do this)
|
|
24
|
+
# * Supports :scm_command, :scm_password, :scm_passphrase Capistrano
|
|
25
|
+
# directives.
|
|
26
|
+
#
|
|
27
|
+
# CONFIGURATION
|
|
28
|
+
# -------------
|
|
29
|
+
#
|
|
30
|
+
# Use this plugin by adding the following line in your config/deploy.rb:
|
|
31
|
+
#
|
|
32
|
+
# set :scm, :git
|
|
33
|
+
#
|
|
34
|
+
# Set <tt>:repository</tt> to the path of your Git repo:
|
|
35
|
+
#
|
|
36
|
+
# set :repository, "someuser@somehost:/home/myproject"
|
|
37
|
+
#
|
|
38
|
+
# The above two options are required to be set, the ones below are
|
|
39
|
+
# optional.
|
|
40
|
+
#
|
|
41
|
+
# You may set <tt>:branch</tt>, which is the reference to the branch, tag,
|
|
42
|
+
# or any SHA1 you are deploying, for example:
|
|
43
|
+
#
|
|
44
|
+
# set :branch, "master"
|
|
45
|
+
#
|
|
46
|
+
# Otherwise, HEAD is assumed. I strongly suggest you set this. HEAD is
|
|
47
|
+
# not always the best assumption.
|
|
48
|
+
#
|
|
49
|
+
# You may also set <tt>:remote</tt>, which will be used as a name for remote
|
|
50
|
+
# tracking of repositories. This option is intended for use with the
|
|
51
|
+
# <tt>:remote_cache</tt> strategy in a distributed git environment.
|
|
52
|
+
#
|
|
53
|
+
# For example in the projects <tt>config/deploy.rb</tt>:
|
|
54
|
+
#
|
|
55
|
+
# set :repository, "#{scm_user}@somehost:~/projects/project.git"
|
|
56
|
+
# set :remote, "#{scm_user}"
|
|
57
|
+
#
|
|
58
|
+
# Then each person with deploy priveledges can add the following to their
|
|
59
|
+
# local <tt>~/.caprc</tt> file:
|
|
60
|
+
#
|
|
61
|
+
# set :scm_user, 'someuser'
|
|
62
|
+
#
|
|
63
|
+
# Now any time a person deploys the project, their repository will be
|
|
64
|
+
# setup as a remote git repository within the cached repository.
|
|
65
|
+
#
|
|
66
|
+
# The <tt>:scm_command</tt> configuration variable, if specified, will
|
|
67
|
+
# be used as the full path to the git executable on the *remote* machine:
|
|
68
|
+
#
|
|
69
|
+
# set :scm_command, "/opt/local/bin/git"
|
|
70
|
+
#
|
|
71
|
+
# For compatibility with deploy scripts that may have used the 1.x
|
|
72
|
+
# version of this plugin before upgrading, <tt>:git</tt> is still
|
|
73
|
+
# recognized as an alias for :scm_command.
|
|
74
|
+
#
|
|
75
|
+
# Set <tt>:scm_password</tt> to the password needed to clone your repo
|
|
76
|
+
# if you don't have password-less (public key) entry:
|
|
77
|
+
#
|
|
78
|
+
# set :scm_password, "my_secret'
|
|
79
|
+
#
|
|
80
|
+
# Otherwise, you will be prompted for a password.
|
|
81
|
+
#
|
|
82
|
+
# <tt>:scm_passphrase</tt> is also supported.
|
|
83
|
+
#
|
|
84
|
+
# The remote cache strategy is also supported.
|
|
85
|
+
#
|
|
86
|
+
# set :repository_cache, "git_master"
|
|
87
|
+
# set :deploy_via, :remote_cache
|
|
88
|
+
#
|
|
89
|
+
# For faster clone, you can also use shallow cloning. This will set the
|
|
90
|
+
# '--depth' flag using the depth specified. This *cannot* be used
|
|
91
|
+
# together with the :remote_cache strategy
|
|
92
|
+
#
|
|
93
|
+
# set :git_shallow_clone, 1
|
|
94
|
+
#
|
|
95
|
+
# For those that don't like to leave your entire repository on
|
|
96
|
+
# your production server you can:
|
|
97
|
+
#
|
|
98
|
+
# set :deploy_via, :export
|
|
99
|
+
#
|
|
100
|
+
# To deploy from a local repository:
|
|
101
|
+
#
|
|
102
|
+
# set :repository, "file://."
|
|
103
|
+
# set :deploy_via, :copy
|
|
104
|
+
#
|
|
105
|
+
# AUTHORS
|
|
106
|
+
# -------
|
|
107
|
+
#
|
|
108
|
+
# Garry Dolley http://scie.nti.st
|
|
109
|
+
# Contributions by Geoffrey Grosenbach http://topfunky.com
|
|
110
|
+
# Scott Chacon http://jointheconversation.org
|
|
111
|
+
# Alex Arnell http://twologic.com
|
|
112
|
+
# and Phillip Goldenburg
|
|
113
|
+
|
|
114
|
+
class Git < Base
|
|
115
|
+
# Sets the default command name for this SCM on your *local* machine.
|
|
116
|
+
# Users may override this by setting the :scm_command variable.
|
|
117
|
+
default_command "git"
|
|
118
|
+
|
|
119
|
+
# When referencing "head", use the branch we want to deploy or, by
|
|
120
|
+
# default, Git's reference of HEAD (the latest changeset in the default
|
|
121
|
+
# branch, usually called "master").
|
|
122
|
+
def head
|
|
123
|
+
variable(:branch) || 'HEAD'
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def origin
|
|
127
|
+
variable(:remote) || 'origin'
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Performs a clone on the remote machine, then checkout on the branch
|
|
131
|
+
# you want to deploy.
|
|
132
|
+
def checkout(revision, destination)
|
|
133
|
+
git = command
|
|
134
|
+
remote = origin
|
|
135
|
+
|
|
136
|
+
args = []
|
|
137
|
+
|
|
138
|
+
# Add an option for the branch name so :git_shallow_clone works with branches
|
|
139
|
+
args << "-b #{variable(:branch)}" unless variable(:branch).nil? || variable(:branch) == revision
|
|
140
|
+
args << "-o #{remote}" unless remote == 'origin'
|
|
141
|
+
if depth = variable(:git_shallow_clone)
|
|
142
|
+
args << "--depth #{depth}"
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
execute = []
|
|
146
|
+
execute << "#{git} clone #{verbose} #{args.join(' ')} #{variable(:repository)} #{destination}"
|
|
147
|
+
|
|
148
|
+
# checkout into a local branch rather than a detached HEAD
|
|
149
|
+
execute << "cd #{destination} && #{git} checkout #{verbose} -b deploy #{revision}"
|
|
150
|
+
|
|
151
|
+
if variable(:git_enable_submodules)
|
|
152
|
+
execute << "#{git} submodule #{verbose} init"
|
|
153
|
+
execute << "#{git} submodule #{verbose} sync"
|
|
154
|
+
if false == variable(:git_submodules_recursive)
|
|
155
|
+
execute << "#{git} submodule #{verbose} update --init"
|
|
156
|
+
else
|
|
157
|
+
execute << %Q(export GIT_RECURSIVE=$([ ! "`#{git} --version`" \\< "git version 1.6.5" ] && echo --recursive))
|
|
158
|
+
execute << "#{git} submodule #{verbose} update --init $GIT_RECURSIVE"
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
execute.compact.join(" && ").gsub(/\s+/, ' ')
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# An expensive export. Performs a checkout as above, then
|
|
166
|
+
# removes the repo.
|
|
167
|
+
def export(revision, destination)
|
|
168
|
+
checkout(revision, destination) << " && rm -Rf #{destination}/.git"
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Merges the changes to 'head' since the last fetch, for remote_cache
|
|
172
|
+
# deployment strategy
|
|
173
|
+
def sync(revision, destination)
|
|
174
|
+
git = command
|
|
175
|
+
remote = origin
|
|
176
|
+
|
|
177
|
+
execute = []
|
|
178
|
+
execute << "cd #{destination}"
|
|
179
|
+
|
|
180
|
+
# Use git-config to setup a remote tracking branches. Could use
|
|
181
|
+
# git-remote but it complains when a remote of the same name already
|
|
182
|
+
# exists, git-config will just silenty overwrite the setting every
|
|
183
|
+
# time. This could cause wierd-ness in the remote cache if the url
|
|
184
|
+
# changes between calls, but as long as the repositories are all
|
|
185
|
+
# based from each other it should still work fine.
|
|
186
|
+
if remote != 'origin'
|
|
187
|
+
execute << "#{git} config remote.#{remote}.url #{variable(:repository)}"
|
|
188
|
+
execute << "#{git} config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/*"
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# since we're in a local branch already, just reset to specified revision rather than merge
|
|
192
|
+
execute << "#{git} fetch #{verbose} #{remote} && #{git} fetch --tags #{verbose} #{remote} && #{git} reset #{verbose} --hard #{revision}"
|
|
193
|
+
|
|
194
|
+
if variable(:git_enable_submodules)
|
|
195
|
+
execute << "#{git} submodule #{verbose} init"
|
|
196
|
+
execute << "#{git} submodule #{verbose} sync"
|
|
197
|
+
if false == variable(:git_submodules_recursive)
|
|
198
|
+
execute << "#{git} submodule #{verbose} update --init"
|
|
199
|
+
else
|
|
200
|
+
execute << %Q(export GIT_RECURSIVE=$([ ! "`#{git} --version`" \\< "git version 1.6.5" ] && echo --recursive))
|
|
201
|
+
execute << "#{git} submodule #{verbose} update --init $GIT_RECURSIVE"
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
# Make sure there's nothing else lying around in the repository (for
|
|
206
|
+
# example, a submodule that has subsequently been removed).
|
|
207
|
+
execute << "#{git} clean #{verbose} -d -x -f"
|
|
208
|
+
|
|
209
|
+
execute.join(" && ")
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Returns a string of diffs between two revisions
|
|
213
|
+
def diff(from, to=nil)
|
|
214
|
+
return scm :diff, from unless to
|
|
215
|
+
scm :diff, "#{from}..#{to}"
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# Returns a log of changes between the two revisions (inclusive).
|
|
219
|
+
def log(from, to=nil)
|
|
220
|
+
scm :log, "#{from}..#{to}"
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# Getting the actual commit id, in case we were passed a tag
|
|
224
|
+
# or partial sha or something - it will return the sha if you pass a sha, too
|
|
225
|
+
def query_revision(revision)
|
|
226
|
+
raise ArgumentError, "Deploying remote branches is no longer supported. Specify the remote branch as a local branch for the git repository you're deploying from (ie: '#{revision.gsub('origin/', '')}' rather than '#{revision}')." if revision =~ /^origin\//
|
|
227
|
+
return revision if revision =~ /^[0-9a-f]{40}$/
|
|
228
|
+
command = scm('ls-remote', repository, revision)
|
|
229
|
+
result = yield(command)
|
|
230
|
+
revdata = result.split(/[\t\n]/)
|
|
231
|
+
newrev = nil
|
|
232
|
+
revdata.each_slice(2) do |refs|
|
|
233
|
+
rev, ref = *refs
|
|
234
|
+
if ref.sub(/refs\/.*?\//, '').strip == revision.to_s
|
|
235
|
+
newrev = rev
|
|
236
|
+
break
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
return newrev if newrev =~ /^[0-9a-f]{40}$/
|
|
240
|
+
|
|
241
|
+
# If sha is not found on remote, try expanding from local repository
|
|
242
|
+
command = scm('rev-parse --revs-only', revision)
|
|
243
|
+
newrev = yield(command).to_s.strip
|
|
244
|
+
|
|
245
|
+
raise "Unable to resolve revision for '#{revision}' on repository '#{repository}'." unless newrev =~ /^[0-9a-f]{40}$/
|
|
246
|
+
return newrev
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def command
|
|
250
|
+
# For backwards compatibility with 1.x version of this module
|
|
251
|
+
variable(:git) || super
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# Determines what the response should be for a particular bit of text
|
|
255
|
+
# from the SCM. Password prompts, connection requests, passphrases,
|
|
256
|
+
# etc. are handled here.
|
|
257
|
+
def handle_data(state, stream, text)
|
|
258
|
+
host = state[:channel][:host]
|
|
259
|
+
logger.info "[#{host} :: #{stream}] #{text}"
|
|
260
|
+
case text
|
|
261
|
+
when /\bpassword.*:/i
|
|
262
|
+
# git is prompting for a password
|
|
263
|
+
unless pass = variable(:scm_password)
|
|
264
|
+
pass = Capistrano::CLI.password_prompt
|
|
265
|
+
end
|
|
266
|
+
%("#{pass}"\n)
|
|
267
|
+
when %r{\(yes/no\)}
|
|
268
|
+
# git is asking whether or not to connect
|
|
269
|
+
"yes\n"
|
|
270
|
+
when /passphrase/i
|
|
271
|
+
# git is asking for the passphrase for the user's key
|
|
272
|
+
unless pass = variable(:scm_passphrase)
|
|
273
|
+
pass = Capistrano::CLI.password_prompt
|
|
274
|
+
end
|
|
275
|
+
%("#{pass}"\n)
|
|
276
|
+
when /accept \(t\)emporarily/
|
|
277
|
+
# git is asking whether to accept the certificate
|
|
278
|
+
"t\n"
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
private
|
|
283
|
+
|
|
284
|
+
# If verbose output is requested, return nil, otherwise return the
|
|
285
|
+
# command-line switch for "quiet" ("-q").
|
|
286
|
+
def verbose
|
|
287
|
+
variable(:scm_verbose) ? nil : "-q"
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
@@ -18,7 +18,7 @@ module Capistrano
|
|
|
18
18
|
# For mercurial HEAD == tip except that it bases this assumption on what
|
|
19
19
|
# tip is in the current repository (so push before you deploy)
|
|
20
20
|
def head
|
|
21
|
-
"tip"
|
|
21
|
+
variable(:branch) || "tip"
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
# Clone the repository and update to the specified changeset.
|
|
@@ -59,7 +59,7 @@ module Capistrano
|
|
|
59
59
|
cmd = scm :log,
|
|
60
60
|
verbose,
|
|
61
61
|
"-r #{changeset}",
|
|
62
|
-
|
|
62
|
+
'--template "{node|short}"'
|
|
63
63
|
yield cmd
|
|
64
64
|
end
|
|
65
65
|
|
|
@@ -67,22 +67,24 @@ module Capistrano
|
|
|
67
67
|
# user/pass can come from ssh and http distribution methods
|
|
68
68
|
# yes/no is for when ssh asks you about fingerprints
|
|
69
69
|
def handle_data(state, stream, text)
|
|
70
|
-
|
|
70
|
+
host = state[:channel][:host]
|
|
71
|
+
logger.info "[#{host} :: #{stream}] #{text}"
|
|
71
72
|
case text
|
|
72
73
|
when /^user:/mi
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
# support :scm_user for backwards compatibility of this module
|
|
75
|
+
if user = variable(:scm_username) || variable(:scm_user)
|
|
76
|
+
%("#{user}"\n)
|
|
75
77
|
else
|
|
76
|
-
raise "No variable :
|
|
78
|
+
raise "No variable :scm_username specified and Mercurial asked!\n" +
|
|
77
79
|
"Prompt was: #{text}"
|
|
78
80
|
end
|
|
79
|
-
when
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
else
|
|
81
|
+
when /\bpassword:/mi
|
|
82
|
+
unless pass = scm_password_or_prompt
|
|
83
|
+
# fall back on old behavior of erroring out with msg
|
|
83
84
|
raise "No variable :scm_password specified and Mercurial asked!\n" +
|
|
84
85
|
"Prompt was: #{text}"
|
|
85
86
|
end
|
|
87
|
+
%("#{pass}"\n)
|
|
86
88
|
when /yes\/no/i
|
|
87
89
|
"yes\n"
|
|
88
90
|
end
|
|
@@ -91,7 +93,7 @@ module Capistrano
|
|
|
91
93
|
private
|
|
92
94
|
|
|
93
95
|
# Fine grained mercurial commands
|
|
94
|
-
def clone(destination)
|
|
96
|
+
def clone(destination)
|
|
95
97
|
scm :clone,
|
|
96
98
|
verbose,
|
|
97
99
|
"--noupdate", # do not update to tip when cloning is done
|
|
@@ -117,13 +119,19 @@ module Capistrano
|
|
|
117
119
|
# verbosity configuration grokking :)
|
|
118
120
|
def verbose
|
|
119
121
|
case variable(:scm_verbose)
|
|
120
|
-
when nil
|
|
121
|
-
when false
|
|
122
|
-
else
|
|
122
|
+
when nil then nil
|
|
123
|
+
when false then "--quiet"
|
|
124
|
+
else "--verbose"
|
|
123
125
|
end
|
|
124
126
|
end
|
|
125
127
|
|
|
128
|
+
# honor Cap 2.1+'s :scm_prefer_prompt if present
|
|
129
|
+
def scm_password_or_prompt
|
|
130
|
+
@scm_password_or_prompt ||= variable(:scm_password) ||
|
|
131
|
+
(Capistrano::CLI.password_prompt("hg password: ") if variable(:scm_prefer_prompt))
|
|
132
|
+
end
|
|
133
|
+
|
|
126
134
|
end
|
|
127
135
|
end
|
|
128
136
|
end
|
|
129
|
-
end
|
|
137
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'capistrano/recipes/deploy/scm/base'
|
|
2
|
+
|
|
3
|
+
module Capistrano
|
|
4
|
+
module Deploy
|
|
5
|
+
module SCM
|
|
6
|
+
|
|
7
|
+
# A trivial SCM wrapper for representing the current working directory
|
|
8
|
+
# as a repository. Obviously, not all operations are available for this
|
|
9
|
+
# SCM, but it works sufficiently for use with the "copy" deployment
|
|
10
|
+
# strategy.
|
|
11
|
+
#
|
|
12
|
+
# Use of this module is _not_ recommended; in general, it is good
|
|
13
|
+
# practice to use some kind of source code management even for anything
|
|
14
|
+
# you are wanting to deploy. However, this module is provided in
|
|
15
|
+
# acknowledgement of the cases where trivial deployment of your current
|
|
16
|
+
# working directory is desired.
|
|
17
|
+
#
|
|
18
|
+
# set :repository, "."
|
|
19
|
+
# set :scm, :none
|
|
20
|
+
# set :deploy_via, :copy
|
|
21
|
+
#
|
|
22
|
+
# Dereference symbolic links. Copy files instead. Handy when you
|
|
23
|
+
# reference files and directory outside of your deployment root.
|
|
24
|
+
# set :copy_dereference_symlink, true
|
|
25
|
+
|
|
26
|
+
class None < Base
|
|
27
|
+
# No versioning, thus, no head. Returns the empty string.
|
|
28
|
+
def head
|
|
29
|
+
""
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Simply does a copy from the :repository directory to the
|
|
33
|
+
# :destination directory.
|
|
34
|
+
def checkout(revision, destination)
|
|
35
|
+
!Capistrano::Deploy::LocalDependency.on_windows? ? "cp -R#{configuration[:copy_dereference_symlink]?'L':''} #{repository} #{destination}" : "xcopy #{repository} \"#{destination}\" /S/I/Y/Q/E"
|
|
36
|
+
end
|
|
37
|
+
alias_method :export, :checkout
|
|
38
|
+
|
|
39
|
+
# No versioning, so this just returns the argument, with no
|
|
40
|
+
# modification.
|
|
41
|
+
def query_revision(revision)
|
|
42
|
+
revision
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# log: There's no log, so it just echos from and to.
|
|
46
|
+
|
|
47
|
+
def log(from="", to="")
|
|
48
|
+
"No SCM: #{from} - #{to}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
require 'capistrano/recipes/deploy/scm/base'
|
|
2
2
|
|
|
3
|
-
# Notes:
|
|
3
|
+
# Notes:
|
|
4
4
|
# no global verbose flag for scm_verbose
|
|
5
5
|
# sync, checkout and export are just sync in p4
|
|
6
|
-
#
|
|
6
|
+
#
|
|
7
7
|
module Capistrano
|
|
8
8
|
module Deploy
|
|
9
9
|
module SCM
|
|
@@ -25,23 +25,23 @@ module Capistrano
|
|
|
25
25
|
# destination directory. The perforce client has a fixed destination so
|
|
26
26
|
# the files must be copied from there to their intended resting place.
|
|
27
27
|
def checkout(revision, destination)
|
|
28
|
-
p4_sync(revision, destination,
|
|
28
|
+
p4_sync(revision, destination, p4sync_flags)
|
|
29
29
|
end
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
# Returns the command that will sync the given revision to the given
|
|
32
32
|
# destination directory. The perforce client has a fixed destination so
|
|
33
33
|
# the files must be copied from there to their intended resting place.
|
|
34
34
|
def sync(revision, destination)
|
|
35
|
-
p4_sync(revision, destination,
|
|
35
|
+
p4_sync(revision, destination, p4sync_flags)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# Returns the command that will sync the given revision to the given
|
|
39
39
|
# destination directory. The perforce client has a fixed destination so
|
|
40
40
|
# the files must be copied from there to their intended resting place.
|
|
41
41
|
def export(revision, destination)
|
|
42
|
-
p4_sync(revision, destination,
|
|
42
|
+
p4_sync(revision, destination, p4sync_flags)
|
|
43
43
|
end
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
# Returns the command that will do an "p4 diff2" for the two revisions.
|
|
46
46
|
def diff(from, to=head)
|
|
47
47
|
scm authentication, :diff2, "-u -db", "//#{p4client}/...#{rev_no(from)}", "//#{p4client}/...#{rev_no(to)}"
|
|
@@ -49,7 +49,7 @@ module Capistrano
|
|
|
49
49
|
|
|
50
50
|
# Returns a "p4 changes" command for the two revisions.
|
|
51
51
|
def log(from=1, to=head)
|
|
52
|
-
scm authentication, :changes, "-s submitted", "//#{p4client}/...#{rev_no(from)},#
|
|
52
|
+
scm authentication, :changes, "-s submitted", "//#{p4client}/...#{rev_no(from)},#{rev_no(to)}"
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def query_revision(revision)
|
|
@@ -58,39 +58,44 @@ module Capistrano
|
|
|
58
58
|
yield(command)[/Change (\d+) on/, 1]
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
+
# Increments the given revision number and returns it.
|
|
62
|
+
def next_revision(revision)
|
|
63
|
+
revision.to_i + 1
|
|
64
|
+
end
|
|
65
|
+
|
|
61
66
|
# Determines what the response should be for a particular bit of text
|
|
62
67
|
# from the SCM. Password prompts, connection requests, passphrases,
|
|
63
68
|
# etc. are handled here.
|
|
64
69
|
def handle_data(state, stream, text)
|
|
65
70
|
case text
|
|
66
71
|
when /\(P4PASSWD\) invalid or unset\./i
|
|
67
|
-
|
|
72
|
+
raise Capistrano::Error, "scm_password (or p4passwd) is incorrect or unset"
|
|
68
73
|
when /Can.t create a new user.*/i
|
|
69
|
-
|
|
70
|
-
when /Perforce client error\:/i
|
|
71
|
-
|
|
74
|
+
raise Capistrano::Error, "scm_username (or p4user) is incorrect or unset"
|
|
75
|
+
when /Perforce client error\:/i
|
|
76
|
+
raise Capistrano::Error, "p4port is incorrect or unset"
|
|
72
77
|
when /Client \'[\w\-\_\.]+\' unknown.*/i
|
|
73
|
-
|
|
74
|
-
end
|
|
78
|
+
raise Capistrano::Error, "p4client is incorrect or unset"
|
|
79
|
+
end
|
|
75
80
|
end
|
|
76
81
|
|
|
77
82
|
private
|
|
78
83
|
|
|
79
84
|
# Builds the set of authentication switches that perforce understands.
|
|
80
85
|
def authentication
|
|
81
|
-
[ p4port
|
|
82
|
-
p4user
|
|
83
|
-
p4passwd
|
|
84
|
-
p4client
|
|
86
|
+
[ p4port && "-p #{p4port}",
|
|
87
|
+
p4user && "-u #{p4user}",
|
|
88
|
+
p4passwd && "-P #{p4passwd}",
|
|
89
|
+
p4client && "-c #{p4client}",
|
|
90
|
+
p4charset && "-C #{p4charset}" ].compact.join(" ")
|
|
85
91
|
end
|
|
86
92
|
|
|
87
93
|
# Returns the command that will sync the given revision to the given
|
|
88
|
-
# destination directory with specific options. The perforce client has
|
|
89
|
-
# a fixed destination so the files must be copied from there to their
|
|
90
|
-
# intended resting place.
|
|
94
|
+
# destination directory with specific options. The perforce client has
|
|
95
|
+
# a fixed destination so the files must be copied from there to their
|
|
96
|
+
# intended resting place.
|
|
91
97
|
def p4_sync(revision, destination, options="")
|
|
92
|
-
|
|
93
|
-
scm authentication, :sync, options, "#{rev_no(revision)}", "&& cp -rf #{p4client_root} #{destination}"
|
|
98
|
+
scm authentication, :sync, options, "#{rev_no(revision)}", "&& cp -rf #{p4client_root} #{destination}"
|
|
94
99
|
end
|
|
95
100
|
|
|
96
101
|
def p4client
|
|
@@ -104,20 +109,41 @@ module Capistrano
|
|
|
104
109
|
def p4user
|
|
105
110
|
variable(:p4user) || variable(:scm_username)
|
|
106
111
|
end
|
|
107
|
-
|
|
112
|
+
|
|
108
113
|
def p4passwd
|
|
109
114
|
variable(:p4passwd) || variable(:scm_password)
|
|
110
115
|
end
|
|
111
|
-
|
|
112
|
-
def
|
|
116
|
+
|
|
117
|
+
def p4charset
|
|
118
|
+
variable(:p4charset)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def p4sync_flags
|
|
122
|
+
variable(:p4sync_flags) || "-f"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def p4client_root
|
|
126
|
+
variable(:p4client_root) || "`#{command} #{authentication} client -o | grep ^Root | cut -f2`"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def rev_no(revision)
|
|
130
|
+
if variable(:p4_label)
|
|
131
|
+
p4_label = if variable(:p4_label) =~ /\A@/
|
|
132
|
+
variable(:p4_label)
|
|
133
|
+
else
|
|
134
|
+
"@#{variable(:p4_label)}"
|
|
135
|
+
end
|
|
136
|
+
return p4_label
|
|
137
|
+
end
|
|
138
|
+
|
|
113
139
|
case revision.to_s
|
|
114
140
|
when "head"
|
|
115
141
|
"#head"
|
|
116
|
-
when /^\d+/
|
|
142
|
+
when /^\d+/
|
|
117
143
|
"@#{revision}"
|
|
118
144
|
else
|
|
119
145
|
revision
|
|
120
|
-
end
|
|
146
|
+
end
|
|
121
147
|
end
|
|
122
148
|
end
|
|
123
149
|
|