Class: Capistrano::SCM::Perforce
- Defined in:
- lib/capistrano/scm/perforce.rb
Overview
An SCM module for using perforce as your source control tool. This module can explicitly selected by placing the following line in your configuration:
set :scm, :perforce
Also, this module accepts a :p4
configuration variable, which (if specified) will be used as the full path to the p4 executable on the remote machine:
set :p4, "/usr/local/bin/p4"
This module accepts another :p4sync_flags
configuration variable, which (if specified) can add extra options. This setting defaults to the value “-f” which forces resynchronization.
set :p4sync_flags, "-f"
This module accepts another :p4client_root
configuration variable to handle mapping adjustments. Perforce doesn’t have the ability to sync to a specific directory (e.g. the release_path); the location being synced to is defined by the client-spec. As such, we sync the client-spec (defined by p4client
and then copy from the determined root of the client-spec mappings to the release_path. In the unlikely event that your client-spec mappings introduces directory structure above the rails structure, you can override the may need to specify the directory
set :p4client_root, "/user/rmcmahon/project1/code"
Finally, the module accepts a p4diff2_options
configuration variable. This can be used to manipulate the output when running a diff between what is deployed, and another revision. This option defaults to “-u”. Run ‘p4 help diff2’ for other options.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#checkout(actor) ⇒ Object
Syncronizes (on all servers associated with the current task) the head revision of the code.
-
#current_revision(actor) ⇒ Object
Return the number of the revision currently deployed.
-
#diff(actor, from = nil, to = nil) ⇒ Object
Return a string containing the diff between the two revisions.
- #latest_revision ⇒ Object
- #update(actor) ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Capistrano::SCM::Base
Instance Method Details
#checkout(actor) ⇒ Object
Syncronizes (on all servers associated with the current task) the head revision of the code. Uses the given actor instance to execute the command.
79 80 81 82 83 84 |
# File 'lib/capistrano/scm/perforce.rb', line 79 def checkout(actor) p4sync_flags = configuration[:p4sync_flags] || "-f" p4client_root = configuration[:p4client_root] || "`#{remote_p4} client -o | grep ^Root | cut -f2`" command = "#{remote_p4} sync #{p4sync_flags} && cp -rf #{p4client_root} #{actor.release_path};" run_checkout(actor, command, &p4_stream_handler(actor)) end |
#current_revision(actor) ⇒ Object
Return the number of the revision currently deployed.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/capistrano/scm/perforce.rb', line 50 def current_revision(actor) latest = actor.releases.last grep = %(grep " #{latest}$" #{configuration.deploy_to}/revisions.log) result = "" actor.run(grep, :once => true) do |ch, str, out| result << out if str == :out raise "could not determine current revision" if str == :err end date, time, user, rev, dir = result.split raise "current revision not found in revisions.log" unless dir == latest rev.to_i end |
#diff(actor, from = nil, to = nil) ⇒ Object
Return a string containing the diff between the two revisions. from
and to
may be in any format that p4 recognizes as a valid revision identifiers. If from
is nil
, it defaults to the last deployed revision. If to
is nil
, it defaults to #head.
68 69 70 71 72 73 74 |
# File 'lib/capistrano/scm/perforce.rb', line 68 def diff(actor, from=nil, to=nil) from ||= "@#{current_revision(actor)}" to ||= "#head" p4client = configuration[:p4client] = configuration[:p4diff2_options]||"-u -db" `#{local_p4} diff2 #{} //#{p4client}/...#{from} //#{p4client}/...#{to}` end |
#latest_revision ⇒ Object
43 44 45 46 47 |
# File 'lib/capistrano/scm/perforce.rb', line 43 def latest_revision configuration.logger.debug "querying latest revision..." unless @latest_revision @latest_revision = `#{local_p4} counter change`.strip @latest_revision end |
#update(actor) ⇒ Object
86 87 88 |
# File 'lib/capistrano/scm/perforce.rb', line 86 def update(actor) raise "#{self.class} doesn't support update(actor)" end |