Module: Buildr::Svn

Defined in:
lib/buildr/core/build.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.commit(file, message) ⇒ Object



209
210
211
# File 'lib/buildr/core/build.rb', line 209

def commit(file, message)
  svn 'commit', '-m', message, file
end

.copy(dir, url, message) ⇒ Object



234
235
236
# File 'lib/buildr/core/build.rb', line 234

def copy(dir, url, message)
  svn 'copy', '--parents', dir, url, '-m', message
end

.remove(url, message) ⇒ Object



238
239
240
# File 'lib/buildr/core/build.rb', line 238

def remove(url, message)
  svn 'remove', url, '-m', message
end

.repo_urlObject

Return the current SVN URL



230
231
232
# File 'lib/buildr/core/build.rb', line 230

def repo_url
  svn('info', '--xml')[/<url>(.*?)<\/url>/, 1].strip
end

.svn(*args) ⇒ Object

:call-seq:

svn(*args)

Executes a SVN command and returns the output. Throws exception if the exit status is not zero. For example:

svn 'commit'


192
193
194
195
196
# File 'lib/buildr/core/build.rb', line 192

def svn(*args)
  output = `svn #{args.shift} #{args.map { |arg| arg.inspect }.join(' ')}`
  fail "SVN command failed with status #{$?.exitstatus}" unless $?.exitstatus == 0
  return output
end

.tag(tag_name) ⇒ Object



198
199
200
201
202
# File 'lib/buildr/core/build.rb', line 198

def tag(tag_name)
  url = tag_url repo_url, tag_name
  remove url, 'Removing old copy' rescue nil
  copy Dir.pwd, url, "Release #{tag_name}"
end

.tag_url(svn_url, tag) ⇒ Object

:call-seq:

tag_url(svn_url, version) => tag_url

Returns the SVN url for the tag. Can tag from the trunk or from branches. Can handle the two standard repository layouts.

- http://my.repo/foo/trunk => http://my.repo/foo/tags/1.0.0
- http://my.repo/trunk/foo => http://my.repo/tags/foo/1.0.0


221
222
223
224
225
226
227
# File 'lib/buildr/core/build.rb', line 221

def tag_url(svn_url, tag)
  trunk_or_branches = Regexp.union(%r{^(.*)/trunk(.*)$}, %r{^(.*)/branches(.*)/([^/]*)$})
  match = trunk_or_branches.match(svn_url)
  prefix = match[1] || match[3]
  suffix = match[2] || match[4]
  prefix + '/tags' + suffix + '/' + tag
end

.uncommitted_filesObject

Status check reveals modified files, but also SVN externals which we can safely ignore.



205
206
207
# File 'lib/buildr/core/build.rb', line 205

def uncommitted_files
  svn('status', '--ignore-externals').split("\n").reject { |line| line =~ /^X\s/ }
end