Class: Svn
- Inherits:
-
Object
- Object
- Svn
- Defined in:
- lib/version_control/svn.rb
Overview
Base class for working with Subversion
Instance Method Summary collapse
-
#add_files(options = {}) ⇒ Object
Adds any new files in the local repo to the svn commit list.
-
#checkout(init = false) ⇒ Object
Performs an svn checkout.
-
#commit(message = "Automation pushed changes") ⇒ Object
Performs an svn commit.
-
#export(target = "", revision = "") ⇒ Object
Performs an svn export.
-
#get ⇒ Object
Performs an svn checkout.
-
#initialize(svn, params, options) ⇒ Svn
constructor
Initializes an instance of the class.
-
#parse_uri(svn_uri, reset_values = false) ⇒ Object
Parses a complex svn uri into parts.
-
#status ⇒ Object
Performs an svn status.
-
#tag(source_path, tag_name, message) ⇒ Object
Performs an svn tag.
Constructor Details
#initialize(svn, params, options) ⇒ Svn
Initializes an instance of the class
Attributes
-
svn
- path to the svn executable -
params
- params hash -
options
- hash of options includes:… url - url for svn repository… base_path - path for the local repository… username - repository user username… password - repository user password… verbose - true for verbose output (default = false)… rebase - starting path for checkouts… simulate - simulate command - echo it (default = false)… prerun_lines - pass any text to run before svn (such as env variables)… command_options - options to pass on command line e.g. –non-interactive
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/version_control/svn.rb', line 23 def initialize(svn, params, ) self.extend Utilities @url = required_option(,"url") @base_path = required_option(,"base_path") user = get_option(,"username") @password = get_option(,"password") @verbose = get_option(,"verbose", false) @prerun = get_option(, "prerun_lines") @command_options = get_option(, "command_options") @command_options += " --non-interactive" unless @command_options.include?("non-interactive") @rebase = get_option(, "rebase") @rebase = @url.split("/")[-1] if @rebase == "" @simulate = get_option(,"simulate", false) make_credential(user, @password) @svn = svn end |
Instance Method Details
#add_files(options = {}) ⇒ Object
Adds any new files in the local repo to the svn commit list
Attributes
-
exclude_regex
- regex to filter add files (file !=~ filter)
Returns
-
command output
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/version_control/svn.rb', line 169 def add_files( = {}) result = status msg = "" exclude = get_option(,"exclude_regex") result.split("\n").each do |item| if item.start_with?("?") file = item.gsub("?","").strip cmd = "#{@svn} add #{file}" if exclude == "" msg += process_cmd(cmd) else msg += process_cmd(cmd) if file =~ /#{exclude}/ end res = `#{cmd}` end end "#{result}\n#{msg}" end |
#checkout(init = false) ⇒ Object
Performs an svn checkout
Attributes
-
init
- true to initilize the checkout and local repo
Returns
-
command output
75 76 77 78 79 80 81 82 83 |
# File 'lib/version_control/svn.rb', line 75 def checkout(init = false) FileUtils.cd(@base_path, :verbose => true) if init cmd = "#{@svn} checkout #{@url} #{@rebase} #{@credential} #{@command_options}" else cmd = "#{@svn} checkout #{@command_options}" end process_cmd(cmd) end |
#commit(message = "Automation pushed changes") ⇒ Object
Performs an svn commit
Attributes
-
message
- commit string
Returns
-
command output
126 127 128 129 130 |
# File 'lib/version_control/svn.rb', line 126 def commit( = "Automation pushed changes") # /usr/bin/svn commit . -m "PSENG-0000 Adding PSENG files" cmd = "#{@svn} commit . -m \"#{}\"" process_cmd(cmd) end |
#export(target = "", revision = "") ⇒ Object
Performs an svn export
Attributes
-
revision
- revision to export (options - defaults to latest)
Returns
-
command output
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/version_control/svn.rb', line 93 def export(target = "", revision = "") url_items = URI.parse(@url) target = url_items.path if target == "" = @command_options += " --no-auth-cache --trust-server-cert --force" if == " --non-interactive" base_cmd = "#{@svn} export #{@credential} #{@command_options} #{@url}" FileUtils.cd(@base_path, :verbose => true) if revision == "" cmd = "#{base_cmd} ." else cmd = "#{base_cmd} -r #{revision} ." end process_cmd(cmd) end |
#get ⇒ Object
Performs an svn checkout
Returns
-
command output
113 114 115 116 |
# File 'lib/version_control/svn.rb', line 113 def get cmd = "#{@svn} checkout --non-interactive" process_cmd(cmd) end |
#parse_uri(svn_uri, reset_values = false) ⇒ Object
Parses a complex svn uri into parts
Attributes
-
svn_url
- svn url, like this:…
user:password@host:port/path/path[#revision]… user:[email protected]:9050/svn/16667/appreldep/RLM/artifacts/CATE[7777777]
-
reset_values
- resets the svn object parameters host, password etc from url (default=false)
Returns
-
parse result, like this:…
=> URIGemResult, “revision” => “”
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/version_control/svn.rb', line 53 def parse_uri(svn_uri, reset_values = false) result = {"uri_result" => nil, "revision" => ""} k = svn_uri.scan(/\[.*\]/) result["revision"] = k[0].gsub("[","").gsub("]","") if k.size > 0 rev = k.size > 0 ? "[#{result["revision"]}]" : "__ZZZ__" parts = URI.parse(svn_uri.gsub(rev,"")) result["uri_result"] = parts if reset_values @url = "#{parts.scheme}://#{parts.host}:#{parts.port}#{parts.path}" make_credential(parts.user, parts.password) unless parts.password.nil? end result end |
#status ⇒ Object
Performs an svn status
Returns
-
command output
156 157 158 |
# File 'lib/version_control/svn.rb', line 156 def status process_cmd("#{@svn} status") end |
#tag(source_path, tag_name, message) ⇒ Object
Performs an svn tag
Attributes
-
source_path
- path in repo to tag -
tag_name
- name for tag -
message
- message to add to tag
Returns
-
command output
143 144 145 146 147 148 149 |
# File 'lib/version_control/svn.rb', line 143 def tag(source_path, tag_name, ) ipos = @url.index("trunk") raise "Cannot locate trunk path" if ipos.nil? tag_path = @url[0..ipos] + "tags/" + tag_name cmd = "#{@svn} copy #{source_path} #{tag_path} -m \"#{}\"" process_cmd(cmd) end |