Class: Capistrano::Deploy::SCM::Subversion

Inherits:
Base
  • Object
show all
Defined in:
lib/capistrano/recipes/deploy/scm/subversion.rb

Overview

Implements the Capistrano SCM interface for the Subversion revision control system (subversion.tigris.org).

Instance Attribute Summary

Attributes inherited from Base

#configuration

Instance Method Summary collapse

Methods inherited from Base

#command, default_command, #initialize, #local, #local?, #scm

Constructor Details

This class inherits a constructor from Capistrano::Deploy::SCM::Base

Instance Method Details

#checkout(revision, destination) ⇒ Object

Returns the command that will check out the given revision to the given destination.



23
24
25
# File 'lib/capistrano/recipes/deploy/scm/subversion.rb', line 23

def checkout(revision, destination)
  scm :checkout, arguments, verbose, authentication, "-r#{revision}", repository, destination
end

#diff(from, to = nil) ⇒ Object

Returns the command that will do an “svn diff” for the two revisions.



40
41
42
# File 'lib/capistrano/recipes/deploy/scm/subversion.rb', line 40

def diff(from, to=nil)
  scm :diff, repository, authentication, "-r#{from}:#{to || head}"
end

#export(revision, destination) ⇒ Object

Returns the command that will do an “svn export” of the given revision to the given destination.



35
36
37
# File 'lib/capistrano/recipes/deploy/scm/subversion.rb', line 35

def export(revision, destination)
  scm :export, arguments, verbose, authentication, "-r#{revision}", repository, destination
end

#handle_data(state, stream, text) ⇒ Object

Determines what the response should be for a particular bit of text from the SCM. Password prompts, connection requests, passphrases, etc. are handled here.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/capistrano/recipes/deploy/scm/subversion.rb', line 70

def handle_data(state, stream, text)
  host = state[:channel][:host]
 logger.info "[#{host} :: #{stream}] #{text}"
  case text
  when /\bpassword.*:/i
    # subversion is prompting for a password
    "#{scm_password_prompt}\n"
  when %r{\(yes/no\)}
    # subversion is asking whether or not to connect
    "yes\n"
  when /passphrase/i
    # subversion is asking for the passphrase for the user's key
    "#{variable(:scm_passphrase)}\n"
  when /The entry \'(.+?)\' is no longer a directory/
    raise Capistrano::Error, "subversion can't update because directory '#{$1}' was replaced. Please add it to svn:ignore."
  when /accept \(t\)emporarily/
    # subversion is asking whether to accept the certificate
    "t\n"
  end
end

#headObject

Subversion understands ‘HEAD’ to refer to the latest revision in the repository.



17
18
19
# File 'lib/capistrano/recipes/deploy/scm/subversion.rb', line 17

def head
  "HEAD"
end

#log(from, to = nil) ⇒ Object

Returns an “svn log” command for the two revisions.



45
46
47
# File 'lib/capistrano/recipes/deploy/scm/subversion.rb', line 45

def log(from, to=nil)
  scm :log, repository, authentication, "-r#{from}:#{to || head}"
end

#next_revision(revision) ⇒ Object

Increments the given revision number and returns it.



63
64
65
# File 'lib/capistrano/recipes/deploy/scm/subversion.rb', line 63

def next_revision(revision)
  revision.to_i + 1
end

#query_revision(revision) ⇒ Object

Attempts to translate the given revision identifier to a “real” revision. If the identifier is an integer, it will simply be returned. Otherwise, this will yield a string of the commands it needs to be executed (svn info), and will extract the revision from the response.



53
54
55
56
57
58
59
60
# File 'lib/capistrano/recipes/deploy/scm/subversion.rb', line 53

def query_revision(revision)
  return revision if revision =~ /^\d+$/
  command = scm(:info, repository, authentication, "-r#{revision}")
  result = yield(command)
  yaml = YAML.load(result)
  raise "tried to run `#{command}' and got unexpected result #{result.inspect}" unless Hash === yaml
  yaml['Last Changed Rev'] || yaml['Revision']
end

#sync(revision, destination) ⇒ Object

Returns the command that will do an “svn update” to the given revision, for the working copy at the given destination.



29
30
31
# File 'lib/capistrano/recipes/deploy/scm/subversion.rb', line 29

def sync(revision, destination)
  scm :update, arguments, verbose, authentication, "-r#{revision}", destination
end