class R10K::SVN::WorkingDir
Manage an SVN working copy.
If SVN authentication is required, both username and password must be specified.
@api private @since 1.2.0
Attributes
password[R]
@!attribute [r] password
@return [String, nil] The SVN password, if provided @api private
path[R]
@attribute [r] path
@return [Pathname] The full path to the SVN working directory @api private
username[R]
@!attribute [r] username
@return [String, nil] The SVN username, if provided @api private
Public Class Methods
new(path, opts = {})
click to toggle source
@param path [Pathname] @param opts [Hash]
@option opts [String] :username @option opts [String] :password
# File lib/r10k/svn/working_dir.rb, line 37 def initialize(path, opts = {}) @path = path setopts(opts, {:username => :self, :password => :self}) if !!(@username) ^ !!(@password) raise ArgumentError, "Both username and password must be specified" end end
Public Instance Methods
checkout(url, revision = nil)
click to toggle source
# File lib/r10k/svn/working_dir.rb, line 73 def checkout(url, revision = nil) argv = ['checkout', url] argv << '-r' << revision if revision argv << @path.basename.to_s argv.concat(auth) argv << '-q' svn(argv, :cwd => @path.parent) end
is_svn?()
click to toggle source
Is the directory at this path actually an SVN repository?
# File lib/r10k/svn/working_dir.rb, line 48 def is_svn? dot_svn = @path + '.svn' dot_svn.exist? end
revision()
click to toggle source
# File lib/r10k/svn/working_dir.rb, line 53 def revision info.slice(/^Revision: (\d+)$/, 1) end
root()
click to toggle source
# File lib/r10k/svn/working_dir.rb, line 61 def root info.slice(/^Repository Root: (.*)$/, 1) end
update(revision = nil)
click to toggle source
# File lib/r10k/svn/working_dir.rb, line 65 def update(revision = nil) argv = %w[update] argv << '-r' << revision if revision argv.concat(auth) svn(argv, :cwd => @path) end
url()
click to toggle source
# File lib/r10k/svn/working_dir.rb, line 57 def url info.slice(/^URL: (.*)$/, 1) end
Private Instance Methods
auth()
click to toggle source
Format authentication information for SVN command args, if applicable
# File lib/r10k/svn/working_dir.rb, line 92 def auth auth = [] if @username auth << "--username" << @username auth << "--password" << @password end auth end
info()
click to toggle source
# File lib/r10k/svn/working_dir.rb, line 85 def info argv = %w[info] argv.concat(auth) svn(argv, :cwd => @path) end
svn(argv, opts = {})
click to toggle source
Wrap SVN commands
@param argv [Array<String>] @param opts [Hash]
@option opts [Pathname] :cwd The directory to run the command in
@return [String] The stdout from the given command
# File lib/r10k/svn/working_dir.rb, line 111 def svn(argv, opts = {}) argv.unshift('svn', '--non-interactive') subproc = R10K::Util::Subprocess.new(argv) subproc.raise_on_fail = true subproc.logger = self.logger subproc.cwd = opts[:cwd] result = subproc.execute result.stdout end