Class: SC::Svn

Inherits:
Object
  • Object
show all
Defined in:
lib/sc/svn.rb

Class Method Summary collapse

Class Method Details

._svn(*args) ⇒ Object

Run a svn subcommand



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sc/svn.rb', line 29

def self._svn (*args)
  subcommand =  caller(0)[0].sub(/^.*:in\s`([^']+).*$/, '\1')
  shell_line = "#{subcommand} #{args.join(' ')}"

  Constants::TERMINAL.say(Constants::TERMINAL.color("svn #{shell_line}", :yellow)) if $DEBUG

  if block_given?
    `svn #{shell_line} 2>&1`.each {|line| yield(line)}
  else
    system("svn #{shell_line}") 
  end

  if $? != 0 and !['info', 'list', 'merge'].include?(subcommand)
    raise "svn command failed: #{shell_line}"
  end
  
  $? == 0
end

.branch(project, source, dest) ⇒ Object

create a branch using svn copy



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sc/svn.rb', line 60

def self.branch (project, source, dest)
  return if self.has_path(dest)

  relative_dest = dest.sub("#{project.url}/", '')
  dest_dirs = relative_dest.split(/\//)
  dest_dirs.pop # don't need the last one
  dest_path = project.url

  branch_or_tag = dest.match(/branches/) ? 'branch' : 'tag'

  dest_dirs.each do |dir|
    dest_path << "/#{dir}"
    self.mkdir('-m', "'#{Constants::ME}: creating #{branch_or_tag} path #{dest_path}'", dest_path) unless self.has_path(dest_path)
  end

  self.copy('-m', "'#{Constants::ME}: creating #{branch_or_tag} #{relative_dest}'", source, dest)
end

.has_path(path) ⇒ Object

Check to see if the given path exists in the repository



50
51
52
53
54
55
56
# File 'lib/sc/svn.rb', line 50

def self.has_path (path)
  self.list(path) do |line|
    return false if line.match(/^svn:/)
  end

  true
end