mbailey-capistrano 2.5.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.
- data/CHANGELOG.rdoc +761 -0
- data/Manifest +104 -0
- data/README.rdoc +66 -0
- data/Rakefile +34 -0
- data/bin/cap +4 -0
- data/bin/capify +78 -0
- data/examples/sample.rb +14 -0
- data/lib/capistrano/callback.rb +45 -0
- data/lib/capistrano/cli/execute.rb +84 -0
- data/lib/capistrano/cli/help.rb +125 -0
- data/lib/capistrano/cli/help.txt +75 -0
- data/lib/capistrano/cli/options.rb +224 -0
- data/lib/capistrano/cli/ui.rb +40 -0
- data/lib/capistrano/cli.rb +47 -0
- data/lib/capistrano/command.rb +283 -0
- data/lib/capistrano/configuration/actions/file_transfer.rb +47 -0
- data/lib/capistrano/configuration/actions/inspect.rb +46 -0
- data/lib/capistrano/configuration/actions/invocation.rb +293 -0
- data/lib/capistrano/configuration/callbacks.rb +148 -0
- data/lib/capistrano/configuration/connections.rb +200 -0
- data/lib/capistrano/configuration/execution.rb +132 -0
- data/lib/capistrano/configuration/loading.rb +197 -0
- data/lib/capistrano/configuration/namespaces.rb +197 -0
- data/lib/capistrano/configuration/roles.rb +73 -0
- data/lib/capistrano/configuration/servers.rb +85 -0
- data/lib/capistrano/configuration/variables.rb +127 -0
- data/lib/capistrano/configuration.rb +43 -0
- data/lib/capistrano/errors.rb +15 -0
- data/lib/capistrano/extensions.rb +57 -0
- data/lib/capistrano/logger.rb +59 -0
- data/lib/capistrano/processable.rb +53 -0
- data/lib/capistrano/recipes/compat.rb +32 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
- data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +105 -0
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +196 -0
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +83 -0
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +152 -0
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
- data/lib/capistrano/recipes/deploy/scm/git.rb +271 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
- data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +133 -0
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
- data/lib/capistrano/recipes/deploy/scm.rb +19 -0
- data/lib/capistrano/recipes/deploy/strategy/base.rb +79 -0
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +210 -0
- data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +56 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/deploy.rb +562 -0
- data/lib/capistrano/recipes/standard.rb +37 -0
- data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/upgrade.rb +33 -0
- data/lib/capistrano/role.rb +102 -0
- data/lib/capistrano/server_definition.rb +56 -0
- data/lib/capistrano/shell.rb +260 -0
- data/lib/capistrano/ssh.rb +99 -0
- data/lib/capistrano/task_definition.rb +70 -0
- data/lib/capistrano/transfer.rb +216 -0
- data/lib/capistrano/version.rb +18 -0
- data/lib/capistrano.rb +2 -0
- data/setup.rb +1346 -0
- data/test/cli/execute_test.rb +132 -0
- data/test/cli/help_test.rb +165 -0
- data/test/cli/options_test.rb +317 -0
- data/test/cli/ui_test.rb +28 -0
- data/test/cli_test.rb +17 -0
- data/test/command_test.rb +286 -0
- data/test/configuration/actions/file_transfer_test.rb +61 -0
- data/test/configuration/actions/inspect_test.rb +65 -0
- data/test/configuration/actions/invocation_test.rb +224 -0
- data/test/configuration/callbacks_test.rb +220 -0
- data/test/configuration/connections_test.rb +349 -0
- data/test/configuration/execution_test.rb +175 -0
- data/test/configuration/loading_test.rb +132 -0
- data/test/configuration/namespace_dsl_test.rb +311 -0
- data/test/configuration/roles_test.rb +144 -0
- data/test/configuration/servers_test.rb +121 -0
- data/test/configuration/variables_test.rb +184 -0
- data/test/configuration_test.rb +88 -0
- data/test/deploy/local_dependency_test.rb +76 -0
- data/test/deploy/remote_dependency_test.rb +114 -0
- data/test/deploy/scm/accurev_test.rb +23 -0
- data/test/deploy/scm/base_test.rb +55 -0
- data/test/deploy/scm/git_test.rb +167 -0
- data/test/deploy/scm/mercurial_test.rb +129 -0
- data/test/deploy/strategy/copy_test.rb +258 -0
- data/test/extensions_test.rb +69 -0
- data/test/fixtures/cli_integration.rb +5 -0
- data/test/fixtures/config.rb +5 -0
- data/test/fixtures/custom.rb +3 -0
- data/test/logger_test.rb +123 -0
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +121 -0
- data/test/shell_test.rb +90 -0
- data/test/ssh_test.rb +104 -0
- data/test/task_definition_test.rb +101 -0
- data/test/transfer_test.rb +160 -0
- data/test/utils.rb +38 -0
- metadata +205 -0
@@ -0,0 +1,271 @@
|
|
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
|
+
configuration[:branch] || 'HEAD'
|
124
|
+
end
|
125
|
+
|
126
|
+
def origin
|
127
|
+
configuration[: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
|
+
args << "-o #{remote}" unless remote == 'origin'
|
138
|
+
if depth = configuration[:git_shallow_clone]
|
139
|
+
args << "--depth #{depth}"
|
140
|
+
end
|
141
|
+
|
142
|
+
execute = []
|
143
|
+
if args.empty?
|
144
|
+
execute << "#{git} clone #{verbose} #{configuration[:repository]} #{destination}"
|
145
|
+
else
|
146
|
+
execute << "#{git} clone #{verbose} #{args.join(' ')} #{configuration[:repository]} #{destination}"
|
147
|
+
end
|
148
|
+
|
149
|
+
# checkout into a local branch rather than a detached HEAD
|
150
|
+
execute << "cd #{destination} && #{git} checkout #{verbose} -b deploy #{revision}"
|
151
|
+
|
152
|
+
if configuration[:git_enable_submodules]
|
153
|
+
execute << "#{git} submodule #{verbose} init"
|
154
|
+
execute << "#{git} submodule #{verbose} update"
|
155
|
+
end
|
156
|
+
|
157
|
+
execute.join(" && ")
|
158
|
+
end
|
159
|
+
|
160
|
+
# An expensive export. Performs a checkout as above, then
|
161
|
+
# removes the repo.
|
162
|
+
def export(revision, destination)
|
163
|
+
checkout(revision, destination) << " && rm -Rf #{destination}/.git"
|
164
|
+
end
|
165
|
+
|
166
|
+
# Merges the changes to 'head' since the last fetch, for remote_cache
|
167
|
+
# deployment strategy
|
168
|
+
def sync(revision, destination)
|
169
|
+
git = command
|
170
|
+
remote = origin
|
171
|
+
|
172
|
+
execute = []
|
173
|
+
execute << "cd #{destination}"
|
174
|
+
|
175
|
+
# Use git-config to setup a remote tracking branches. Could use
|
176
|
+
# git-remote but it complains when a remote of the same name already
|
177
|
+
# exists, git-config will just silenty overwrite the setting every
|
178
|
+
# time. This could cause wierd-ness in the remote cache if the url
|
179
|
+
# changes between calls, but as long as the repositories are all
|
180
|
+
# based from each other it should still work fine.
|
181
|
+
if remote != 'origin'
|
182
|
+
execute << "#{git} config remote.#{remote}.url #{configuration[:repository]}"
|
183
|
+
execute << "#{git} config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/*"
|
184
|
+
end
|
185
|
+
|
186
|
+
# since we're in a local branch already, just reset to specified revision rather than merge
|
187
|
+
execute << "#{git} fetch #{verbose} #{remote} && #{git} reset #{verbose} --hard #{revision}"
|
188
|
+
|
189
|
+
if configuration[:git_enable_submodules]
|
190
|
+
execute << "#{git} submodule #{verbose} init"
|
191
|
+
execute << "#{git} submodule #{verbose} update"
|
192
|
+
end
|
193
|
+
|
194
|
+
execute.join(" && ")
|
195
|
+
end
|
196
|
+
|
197
|
+
# Returns a string of diffs between two revisions
|
198
|
+
def diff(from, to=nil)
|
199
|
+
from << "..#{to}" if to
|
200
|
+
scm :diff, from
|
201
|
+
end
|
202
|
+
|
203
|
+
# Returns a log of changes between the two revisions (inclusive).
|
204
|
+
def log(from, to=nil)
|
205
|
+
scm :log, "#{from}..#{to}"
|
206
|
+
end
|
207
|
+
|
208
|
+
# Getting the actual commit id, in case we were passed a tag
|
209
|
+
# or partial sha or something - it will return the sha if you pass a sha, too
|
210
|
+
def query_revision(revision)
|
211
|
+
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\//
|
212
|
+
return revision if revision =~ /^[0-9a-f]{40}$/
|
213
|
+
command = scm('ls-remote', repository, revision)
|
214
|
+
result = yield(command)
|
215
|
+
revdata = result.split(/[\t\n]/)
|
216
|
+
newrev = nil
|
217
|
+
revdata.each_slice(2) do |refs|
|
218
|
+
rev, ref = *refs
|
219
|
+
if ref.sub(/refs\/.*?\//, '').strip == revision
|
220
|
+
newrev = rev
|
221
|
+
break
|
222
|
+
end
|
223
|
+
end
|
224
|
+
raise "Unable to resolve revision for '#{revision}' on repository '#{repository}'." unless newrev =~ /^[0-9a-f]{40}$/
|
225
|
+
return newrev
|
226
|
+
end
|
227
|
+
|
228
|
+
def command
|
229
|
+
# For backwards compatibility with 1.x version of this module
|
230
|
+
configuration[:git] || super
|
231
|
+
end
|
232
|
+
|
233
|
+
# Determines what the response should be for a particular bit of text
|
234
|
+
# from the SCM. Password prompts, connection requests, passphrases,
|
235
|
+
# etc. are handled here.
|
236
|
+
def handle_data(state, stream, text)
|
237
|
+
host = state[:channel][:host]
|
238
|
+
logger.info "[#{host} :: #{stream}] #{text}"
|
239
|
+
case text
|
240
|
+
when /\bpassword.*:/i
|
241
|
+
# git is prompting for a password
|
242
|
+
unless pass = configuration[:scm_password]
|
243
|
+
pass = Capistrano::CLI.password_prompt
|
244
|
+
end
|
245
|
+
"#{pass}\n"
|
246
|
+
when %r{\(yes/no\)}
|
247
|
+
# git is asking whether or not to connect
|
248
|
+
"yes\n"
|
249
|
+
when /passphrase/i
|
250
|
+
# git is asking for the passphrase for the user's key
|
251
|
+
unless pass = configuration[:scm_passphrase]
|
252
|
+
pass = Capistrano::CLI.password_prompt
|
253
|
+
end
|
254
|
+
"#{pass}\n"
|
255
|
+
when /accept \(t\)emporarily/
|
256
|
+
# git is asking whether to accept the certificate
|
257
|
+
"t\n"
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
private
|
262
|
+
|
263
|
+
# If verbose output is requested, return nil, otherwise return the
|
264
|
+
# command-line switch for "quiet" ("-q").
|
265
|
+
def verbose
|
266
|
+
variable(:scm_verbose) ? nil : "-q"
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# Copyright 2007 Matthew Elder <sseses@gmail.com>
|
2
|
+
# based on work by Tobias Luetke
|
3
|
+
|
4
|
+
require 'capistrano/recipes/deploy/scm/base'
|
5
|
+
|
6
|
+
module Capistrano
|
7
|
+
module Deploy
|
8
|
+
module SCM
|
9
|
+
|
10
|
+
# Implements the Capistrano SCM interface for the Mercurial revision
|
11
|
+
# control system (http://www.selenic.com/mercurial/).
|
12
|
+
# Latest updates at http://tackletechnology.org/oss/cap2-mercurial
|
13
|
+
class Mercurial < Base
|
14
|
+
# Sets the default command name for this SCM. Users may override this
|
15
|
+
# by setting the :scm_command variable.
|
16
|
+
default_command "hg"
|
17
|
+
|
18
|
+
# For mercurial HEAD == tip except that it bases this assumption on what
|
19
|
+
# tip is in the current repository (so push before you deploy)
|
20
|
+
def head
|
21
|
+
"tip"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Clone the repository and update to the specified changeset.
|
25
|
+
def checkout(changeset, destination)
|
26
|
+
clone(destination) + " && " + update(changeset, destination)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Pull from the repository and update to the specified changeset.
|
30
|
+
def sync(changeset, destination)
|
31
|
+
pull(destination) + " && " + update(changeset, destination)
|
32
|
+
end
|
33
|
+
|
34
|
+
# One day we will have hg archive, although i think its not needed
|
35
|
+
def export(revision, destination)
|
36
|
+
raise NotImplementedError, "`diff' is not implemented by #{self.class.name}" +
|
37
|
+
"use checkout strategy"
|
38
|
+
end
|
39
|
+
|
40
|
+
# Compute the difference between the two changesets +from+ and +to+
|
41
|
+
# as a unified diff.
|
42
|
+
def diff(from, to=nil)
|
43
|
+
scm :diff,
|
44
|
+
"--rev #{from}",
|
45
|
+
(to ? "--rev #{to}" : nil)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Return a log of all changes between the two specified changesets,
|
49
|
+
# +from+ and +to+, inclusive or the log for +from+ if +to+ is omitted.
|
50
|
+
def log(from, to=nil)
|
51
|
+
scm :log,
|
52
|
+
verbose,
|
53
|
+
"--rev #{from}" +
|
54
|
+
(to ? ":#{to}" : "")
|
55
|
+
end
|
56
|
+
|
57
|
+
# Translates a tag to a changeset if needed or just returns changeset.
|
58
|
+
def query_revision(changeset)
|
59
|
+
cmd = scm :log,
|
60
|
+
verbose,
|
61
|
+
"-r #{changeset}",
|
62
|
+
"--template '{node|short}'"
|
63
|
+
yield cmd
|
64
|
+
end
|
65
|
+
|
66
|
+
# Determine response for SCM prompts
|
67
|
+
# user/pass can come from ssh and http distribution methods
|
68
|
+
# yes/no is for when ssh asks you about fingerprints
|
69
|
+
def handle_data(state, stream, text)
|
70
|
+
host = state[:channel][:host]
|
71
|
+
logger.info "[#{host} :: #{stream}] #{text}"
|
72
|
+
case text
|
73
|
+
when /^user:/mi
|
74
|
+
# support :scm_user for backwards compatibility of this module
|
75
|
+
if user = variable(:scm_username) || variable(:scm_user)
|
76
|
+
"#{user}\n"
|
77
|
+
else
|
78
|
+
raise "No variable :scm_username specified and Mercurial asked!\n" +
|
79
|
+
"Prompt was: #{text}"
|
80
|
+
end
|
81
|
+
when /\bpassword:/mi
|
82
|
+
unless pass = scm_password_or_prompt
|
83
|
+
# fall back on old behavior of erroring out with msg
|
84
|
+
raise "No variable :scm_password specified and Mercurial asked!\n" +
|
85
|
+
"Prompt was: #{text}"
|
86
|
+
end
|
87
|
+
"#{pass}\n"
|
88
|
+
when /yes\/no/i
|
89
|
+
"yes\n"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
# Fine grained mercurial commands
|
96
|
+
def clone(destination)
|
97
|
+
scm :clone,
|
98
|
+
verbose,
|
99
|
+
"--noupdate", # do not update to tip when cloning is done
|
100
|
+
repository, # clone which repository?
|
101
|
+
destination # and put the clone where?
|
102
|
+
end
|
103
|
+
|
104
|
+
def pull(destination)
|
105
|
+
scm :pull,
|
106
|
+
verbose,
|
107
|
+
"--repository #{destination}", # pull changes into what?
|
108
|
+
repository # and pull the changes from?
|
109
|
+
end
|
110
|
+
|
111
|
+
def update(changeset, destination)
|
112
|
+
scm :update,
|
113
|
+
verbose,
|
114
|
+
"--repository #{destination}", # update what?
|
115
|
+
"--clean", # ignore untracked changes
|
116
|
+
changeset # update to this changeset
|
117
|
+
end
|
118
|
+
|
119
|
+
# verbosity configuration grokking :)
|
120
|
+
def verbose
|
121
|
+
case variable(:scm_verbose)
|
122
|
+
when nil then nil
|
123
|
+
when false then "--quiet"
|
124
|
+
else "--verbose"
|
125
|
+
end
|
126
|
+
end
|
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
|
+
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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
|
+
class None < Base
|
22
|
+
# No versioning, thus, no head. Returns the empty string.
|
23
|
+
def head
|
24
|
+
""
|
25
|
+
end
|
26
|
+
|
27
|
+
# Simply does a copy from the :repository directory to the
|
28
|
+
# :destination directory.
|
29
|
+
def checkout(revision, destination)
|
30
|
+
!Capistrano::Deploy::LocalDependency.on_windows? ? "cp -R #{repository} #{destination}" : "xcopy #{repository} \"#{destination}\" /S/I/Y/Q/E"
|
31
|
+
end
|
32
|
+
|
33
|
+
alias_method :export, :checkout
|
34
|
+
|
35
|
+
# No versioning, so this just returns the argument, with no
|
36
|
+
# modification.
|
37
|
+
def query_revision(revision)
|
38
|
+
revision
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/scm/base'
|
2
|
+
|
3
|
+
# Notes:
|
4
|
+
# no global verbose flag for scm_verbose
|
5
|
+
# sync, checkout and export are just sync in p4
|
6
|
+
#
|
7
|
+
module Capistrano
|
8
|
+
module Deploy
|
9
|
+
module SCM
|
10
|
+
|
11
|
+
# Implements the Capistrano SCM interface for the Perforce revision
|
12
|
+
# control system (http://www.perforce.com).
|
13
|
+
class Perforce < Base
|
14
|
+
# Sets the default command name for this SCM. Users may override this
|
15
|
+
# by setting the :scm_command variable.
|
16
|
+
default_command "p4"
|
17
|
+
|
18
|
+
# Perforce understands '#head' to refer to the latest revision in the
|
19
|
+
# depot.
|
20
|
+
def head
|
21
|
+
'head'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the command that will sync the given revision to the given
|
25
|
+
# destination directory. The perforce client has a fixed destination so
|
26
|
+
# the files must be copied from there to their intended resting place.
|
27
|
+
def checkout(revision, destination)
|
28
|
+
p4_sync(revision, destination, p4sync_flags)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the command that will sync the given revision to the given
|
32
|
+
# destination directory. The perforce client has a fixed destination so
|
33
|
+
# the files must be copied from there to their intended resting place.
|
34
|
+
def sync(revision, destination)
|
35
|
+
p4_sync(revision, destination, p4sync_flags)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns the command that will sync the given revision to the given
|
39
|
+
# destination directory. The perforce client has a fixed destination so
|
40
|
+
# the files must be copied from there to their intended resting place.
|
41
|
+
def export(revision, destination)
|
42
|
+
p4_sync(revision, destination, p4sync_flags)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns the command that will do an "p4 diff2" for the two revisions.
|
46
|
+
def diff(from, to=head)
|
47
|
+
scm authentication, :diff2, "-u -db", "//#{p4client}/...#{rev_no(from)}", "//#{p4client}/...#{rev_no(to)}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns a "p4 changes" command for the two revisions.
|
51
|
+
def log(from=1, to=head)
|
52
|
+
scm authentication, :changes, "-s submitted", "//#{p4client}/...#{rev_no(from)},#(rev_no(to)}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def query_revision(revision)
|
56
|
+
return revision if revision.to_s =~ /^\d+$/
|
57
|
+
command = scm(authentication, :changes, "-s submitted", "-m 1", "//#{p4client}/...#{rev_no(revision)}")
|
58
|
+
yield(command)[/Change (\d+) on/, 1]
|
59
|
+
end
|
60
|
+
|
61
|
+
# Determines what the response should be for a particular bit of text
|
62
|
+
# from the SCM. Password prompts, connection requests, passphrases,
|
63
|
+
# etc. are handled here.
|
64
|
+
def handle_data(state, stream, text)
|
65
|
+
case text
|
66
|
+
when /\(P4PASSWD\) invalid or unset\./i
|
67
|
+
raise Capistrano::Error, "scm_password (or p4passwd) is incorrect or unset"
|
68
|
+
when /Can.t create a new user.*/i
|
69
|
+
raise Capistrano::Error, "scm_username (or p4user) is incorrect or unset"
|
70
|
+
when /Perforce client error\:/i
|
71
|
+
raise Capistrano::Error, "p4port is incorrect or unset"
|
72
|
+
when /Client \'[\w\-\_\.]+\' unknown.*/i
|
73
|
+
raise Capistrano::Error, "p4client is incorrect or unset"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
# Builds the set of authentication switches that perforce understands.
|
80
|
+
def authentication
|
81
|
+
[ p4port && "-p #{p4port}",
|
82
|
+
p4user && "-u #{p4user}",
|
83
|
+
p4passwd && "-P #{p4passwd}",
|
84
|
+
p4client && "-c #{p4client}" ].compact.join(" ")
|
85
|
+
end
|
86
|
+
|
87
|
+
# 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.
|
91
|
+
def p4_sync(revision, destination, options="")
|
92
|
+
scm authentication, :sync, options, "#{rev_no(revision)}", "&& cp -rf #{p4client_root} #{destination}"
|
93
|
+
end
|
94
|
+
|
95
|
+
def p4client
|
96
|
+
variable(:p4client)
|
97
|
+
end
|
98
|
+
|
99
|
+
def p4port
|
100
|
+
variable(:p4port)
|
101
|
+
end
|
102
|
+
|
103
|
+
def p4user
|
104
|
+
variable(:p4user) || variable(:scm_username)
|
105
|
+
end
|
106
|
+
|
107
|
+
def p4passwd
|
108
|
+
variable(:p4passwd) || variable(:scm_password)
|
109
|
+
end
|
110
|
+
|
111
|
+
def p4sync_flags
|
112
|
+
variable(:p4sync_flags) || "-f"
|
113
|
+
end
|
114
|
+
|
115
|
+
def p4client_root
|
116
|
+
variable(:p4client_root) || "`#{command} #{authentication} client -o | grep ^Root | cut -f2`"
|
117
|
+
end
|
118
|
+
|
119
|
+
def rev_no(revision)
|
120
|
+
case revision.to_s
|
121
|
+
when "head"
|
122
|
+
"#head"
|
123
|
+
when /^\d+/
|
124
|
+
"@#{revision}"
|
125
|
+
else
|
126
|
+
revision
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|