Class: RSCM::Subversion

Inherits:
Base show all
Includes:
FileUtils, PathConverter
Defined in:
lib/rscm/scm/subversion.rb

Overview

RSCM implementation for Subversion.

You need the svn/svnadmin executable on the PATH in order for it to work.

NOTE: On Cygwin these have to be the win32 builds of svn/svnadmin and not the Cygwin ones.

Instance Attribute Summary collapse

Attributes inherited from Base

#checkout_dir

Instance Method Summary collapse

Methods included from PathConverter

ensure_trailing_slash, filepath_to_nativepath, filepath_to_nativeurl, nativepath_to_filepath

Methods inherited from Base

#==, classes, #edit, register, #to_yaml_properties

Constructor Details

#initialize(url = "", path = "") ⇒ Subversion

Returns a new instance of Subversion.



35
36
37
# File 'lib/rscm/scm/subversion.rb', line 35

def initialize(url="", path="")
  @url, @path = url, path
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



29
30
31
# File 'lib/rscm/scm/subversion.rb', line 29

def password
  @password
end

#pathObject

Returns the value of attribute path.



33
34
35
# File 'lib/rscm/scm/subversion.rb', line 33

def path
  @path
end

#urlObject

Returns the value of attribute url.



21
22
23
# File 'lib/rscm/scm/subversion.rb', line 21

def url
  @url
end

#usernameObject

Returns the value of attribute username.



25
26
27
# File 'lib/rscm/scm/subversion.rb', line 25

def username
  @username
end

Instance Method Details

#add(relative_filename) ⇒ Object



39
40
41
# File 'lib/rscm/scm/subversion.rb', line 39

def add(relative_filename)
  svn(@checkout_dir, "add #{relative_filename}")
end

#can_create_central?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/rscm/scm/subversion.rb', line 122

def can_create_central?
  local?
end

#central_exists?Boolean

Returns:

  • (Boolean)


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/rscm/scm/subversion.rb', line 130

def central_exists?
  if(local?)
    File.exists?("#{svnrootdir}/db")
  else
    # Do a simple command over the network
    # If the repo/path doesn't exist, we'll get zero output
    # on stdout (and an error msg on std err).
    exists = false
    cmd = "svn log #{url} -r HEAD"
    Better.popen(cmd) do |stdout|
      stdout.each_line do |line|
        exists = true
      end
    end
    exists
  end
end

#checked_out?Boolean

Returns:

  • (Boolean)


216
217
218
219
220
# File 'lib/rscm/scm/subversion.rb', line 216

def checked_out?
  rootentries = File.expand_path("#{checkout_dir}/.svn/entries")
  result = File.exists?(rootentries)
  result
end

#checkout(to_identifier = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rscm/scm/subversion.rb', line 51

def checkout(to_identifier=nil)
  checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
  mkdir_p(@checkout_dir)
  checked_out_files = []
  path_regex = /^[A|D|U]\s+(.*)/
  if(checked_out?)
    svn(@checkout_dir, update_command(to_identifier)) do |line|
      if(line =~ path_regex)
        absolute_path = "#{checkout_dir}/#{$1}"
        relative_path = $1.chomp
        relative_path = relative_path.gsub(/\\/, "/") if WINDOWS
        checked_out_files << relative_path
        yield relative_path if block_given?
      end
    end
  else
    svn(@checkout_dir, checkout_command(to_identifier)) do |line|
      if(line =~ path_regex)
        native_absolute_path = $1
        absolute_path = PathConverter.nativepath_to_filepath(native_absolute_path)
        if(File.exist?(absolute_path) && !File.directory?(absolute_path))
          native_checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
#              relative_path = native_absolute_path[native_checkout_dir.length+1..-1].chomp
# not sure about this old code - this seems to work. keep it here till it's verified on win32
          relative_path = absolute_path
          relative_path = relative_path.gsub(/\\/, "/") if WINDOWS
          checked_out_files << relative_path
          yield relative_path if block_given?
        end
      end
    end
  end
  checked_out_files
end

#checkout_commandlineObject



86
87
88
# File 'lib/rscm/scm/subversion.rb', line 86

def checkout_commandline
  "svn checkout #{revision_option(nil)}"
end

#commit(message) ⇒ Object



103
104
105
106
107
# File 'lib/rscm/scm/subversion.rb', line 103

def commit(message)
  svn(@checkout_dir, commit_command(message))
  # We have to do an update to get the local revision right
  svn(@checkout_dir, "update")
end

#create_centralObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/rscm/scm/subversion.rb', line 155

def create_central
  native_path = PathConverter.filepath_to_nativepath(svnrootdir, true)
  mkdir_p(PathConverter.nativepath_to_filepath(native_path))
  svnadmin(svnrootdir, "create #{native_path}")
  if(@path && @path != "")
    # create the directories
    paths = @path.split("/")
    paths.each_with_index do |p,i|
      p = paths[0..i]
      u = "#{repourl}/#{p.join('/')}"
      svn(".", "mkdir #{u} -m \"Adding directories\"")
    end
  end
end

#destroy_centralObject



126
127
128
# File 'lib/rscm/scm/subversion.rb', line 126

def destroy_central
  FileUtils.rm_rf(svnrootdir)
end

#diff(file, &block) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/rscm/scm/subversion.rb', line 113

def diff(file, &block)
  with_working_dir(@checkout_dir) do
    cmd = "svn diff -r #{file.previous_native_revision_identifier}:#{file.native_revision_identifier} \"#{url}/#{file.path}\""
    Better.popen(cmd) do |io|
      return(yield(io))
    end
  end
end

#import_central(dir, message) ⇒ Object



188
189
190
191
# File 'lib/rscm/scm/subversion.rb', line 188

def import_central(dir, message)
  import_cmd = "import #{url} -m \"#{message}\""
  svn(dir, import_cmd)
end

#install_trigger(trigger_command, damagecontrol_install_dir) ⇒ Object



170
171
172
173
174
175
176
# File 'lib/rscm/scm/subversion.rb', line 170

def install_trigger(trigger_command, damagecontrol_install_dir)
  if (WINDOWS)
    install_win_trigger(trigger_command, damagecontrol_install_dir)
  else
    install_unix_trigger(trigger_command, damagecontrol_install_dir)
  end
end

#labelObject



109
110
111
# File 'lib/rscm/scm/subversion.rb', line 109

def label
  local_revision_identifier.to_s
end

#move(relative_src, relative_dest) ⇒ Object



43
44
45
# File 'lib/rscm/scm/subversion.rb', line 43

def move(relative_src, relative_dest)
  svn(@checkout_dir, "mv #{relative_src} #{relative_dest}")
end

#repourlObject

url pointing to the root of the repo



211
212
213
214
# File 'lib/rscm/scm/subversion.rb', line 211

def repourl
  last = (path.nil? || path == "") ? -1 : -(path.length)-2
  url[0..last]
end

#revisions(from_identifier, to_identifier = Time.infinity) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/rscm/scm/subversion.rb', line 193

def revisions(from_identifier, to_identifier=Time.infinity)
  # Return empty revision if the requested revision doesn't exist yet.
  return Revisions.new if(from_identifier.is_a?(Integer) && head_revision_identifier <= from_identifier)

  checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
  revisions = nil
  command = "svn #{changes_command(from_identifier, to_identifier)}"

  with_working_dir(@checkout_dir) do
    Better.popen(command) do |stdout|
      parser = SubversionLogParser.new(stdout, @url)
      revisions = parser.parse_revisions
    end
  end
  revisions
end

#supports_trigger?Boolean

Returns:

  • (Boolean)


148
149
150
151
152
153
# File 'lib/rscm/scm/subversion.rb', line 148

def supports_trigger?
  true
  # we'll assume it supports trigger even if not local. this is to ensure user interfaces
  # can display appropriate options, even if the object is not 'fully initialised'
  # local?
end

#transactional?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/rscm/scm/subversion.rb', line 47

def transactional?
  true
end

#trigger_installed?(trigger_command, trigger_files_checkout_dir) ⇒ Boolean

Returns:

  • (Boolean)


182
183
184
185
186
# File 'lib/rscm/scm/subversion.rb', line 182

def trigger_installed?(trigger_command, trigger_files_checkout_dir)
  return false unless File.exist?(post_commit_file)
  not_already_commented = LineEditor.comment_out(File.new(post_commit_file), /#{Regexp.escape(trigger_command)}/, "# ", "")
  not_already_commented
end

#uninstall_trigger(trigger_command, trigger_files_checkout_dir) ⇒ Object



178
179
180
# File 'lib/rscm/scm/subversion.rb', line 178

def uninstall_trigger(trigger_command, trigger_files_checkout_dir)
  File.comment_out(post_commit_file, /#{Regexp.escape(trigger_command)}/, nil)
end

#update_commandlineObject



90
91
92
# File 'lib/rscm/scm/subversion.rb', line 90

def update_commandline
  "svn update #{url} #{checkout_dir}"
end

#uptodate?(identifier) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
97
98
99
100
101
# File 'lib/rscm/scm/subversion.rb', line 94

def uptodate?(identifier)
  if(!checked_out?)
    false
  else
    rev = identifier ? identifier : head_revision_identifier
    local_revision_identifier == rev
  end
end