Class: BuildTool::VCS::Svn

Inherits:
Base
  • Object
show all
Defined in:
lib/build-tool/vcs/svn.rb

Overview

Implementation for the subversion version control system.

Defined Under Namespace

Classes: SvnError

Instance Attribute Summary

Attributes inherited from Base

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#apply_patches_after_rebase?, #check_for_sshkey, #configure, #gc, #local_changes, #local_path, #local_path_exist?, #patches_supported?, #prepare_for_rebase, #ready_for_rebase, #recipe, #remote_changes

Constructor Details

#initialize(*args) ⇒ Svn

Returns a new instance of Svn.



60
61
62
63
64
# File 'lib/build-tool/vcs/svn.rb', line 60

def initialize( *args )
    super( *args )
    @remote_info = nil
    @local_info
end

Class Method Details

.svn(command, wd, &block) ⇒ Object



254
255
256
257
258
259
260
# File 'lib/build-tool/vcs/svn.rb', line 254

def self.svn( command, wd, &block )
    rc = self.execute( "svn " + command, wd, &block )
    if rc != 0
        raise SvnError, "Command 'svn #{command}' failed with error code #{rc}!"
    end
    rc
end

.svn_available?Boolean

Is the git executable available?

Returns:

  • (Boolean)


71
72
73
74
75
76
# File 'lib/build-tool/vcs/svn.rb', line 71

def svn_available?
    return @svn_available unless @svn_available.nil?
    %x( svn --version 2>&1 )
    @svn_available = $?.success?
    return @svn_available
end

Instance Method Details

#[](var) ⇒ Object



267
268
269
270
271
272
273
274
275
276
# File 'lib/build-tool/vcs/svn.rb', line 267

def[]( var )
    case var

    when nil

    else
        # *TODO* raise correct exception
        raise NotImplementedError, "#{var}"
    end
end

#[]=(var, val) ⇒ Object



278
279
280
281
282
283
284
285
286
287
# File 'lib/build-tool/vcs/svn.rb', line 278

def[]=( var, val )
    case var

    when nil

    else
        # *TODO* raise correct exception
        raise NotImplementedError, "#{var}"
    end
end

#check_configObject

Make sure the configuration is correct.



107
108
109
110
111
112
# File 'lib/build-tool/vcs/svn.rb', line 107

def check_config
    if self.url != "#{remote_url}"
        logger.info( "Relocating checkout to #{remote_url}" )
        svn( "switch --relocate #{self.url} #{remote_url}" )
    end
end

#checkedout?Boolean

METHODS

Returns:

  • (Boolean)


97
98
99
100
101
102
103
104
# File 'lib/build-tool/vcs/svn.rb', line 97

def checkedout?
    return false if !local_path_exist?
    if !File.exists? "#{local_path}/.svn"
        logger.debug("Checkout path #{local_path} is not a svn repo")
        return false
    end
    return true
end

#cloneObject

Initialize the local repository



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/build-tool/vcs/svn.rb', line 115

def clone
    # Check if local_path exists
    if local_path_exist?
        raise SvnError, "Failed to create repository at '#{local_path}': Path exists"
    end

    # Create the directories parent dir.
    FileUtils.mkdir_p( File.dirname( local_path ) ) if !$noop

    # Init the repository
    if config.only
        svn "checkout --depth=files #{remote_url} #{local_path}", local_path.dirname
        config.only.each do |elem|
            svn "update --depth=infinity #{elem}", local_path
        end
    else
        svn "checkout --depth=infinity #{remote_url} #{local_path}", local_path.dirname
    end

    check_config

    return true
end

#dirty?Boolean

Returns:

  • (Boolean)


226
227
228
229
230
231
232
# File 'lib/build-tool/vcs/svn.rb', line 226

def dirty?
    dirty = false
    svn( "status -q" ) do
        dirty = true
    end
    return dirty
end

#do_local_changes {|nil| ... } ⇒ Object

Yields:

  • (nil)


234
235
236
# File 'lib/build-tool/vcs/svn.rb', line 234

def do_local_changes
    yield nil
end

#do_remote_changes(&block) ⇒ Object



238
239
240
241
242
243
244
# File 'lib/build-tool/vcs/svn.rb', line 238

def do_remote_changes( &block )
    svn( "log -rHEAD:BASE --quiet" ) do |x|
        if not x.starts_with?( '----------' )
            yield x
        end
    end
end

#fetch(verbose = false) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/build-tool/vcs/svn.rb', line 147

def fetch( verbose = false )

    if !checkedout?
       return clone
    else
        # Micro optimization. clone calls check_config
        check_config
    end

    if verbose
        svn "log -r HEAD:BASE -q" do |line|
            logger.info( line )
        end
    end

    svn "update"

    return true
end

#fetching_supported?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/build-tool/vcs/svn.rb', line 88

def fetching_supported?
    false
end

#info(local = true) ⇒ Object

Run svn info and return the result in a hash



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/build-tool/vcs/svn.rb', line 168

def info( local = true )
    if local
        return @local_info if @local_info
        @local_info = Hash.new
        svn( "info" ) {
            |line|
            key, value = line.chomp.split( ':', 2 )
            @local_info[key] = value
        }
        return @local_info
    else
        return @remote_info if @remote_info
        @remote_info = Hash.new
        svn( "info #{remote_url}", nil ) {
            |line|
            key, value = line.chomp.split( ':', 2 )
            @remote_info[key] = value
        }
        return @remote_info
    end
end

#last_changed_revObject

Returns the last changed revision on the remote repository. Return 0 if the last changed revision could not be determined.

Raises:



192
193
194
195
196
197
# File 'lib/build-tool/vcs/svn.rb', line 192

def last_changed_rev
    return 777777 if $noop
    version = info( false )["Last Changed Rev"];
    raise SvnError, "Failed to determine revision for #{remote_url}" if version.nil?
    return version
end

#nameObject

ATTRIBUTES



84
85
86
# File 'lib/build-tool/vcs/svn.rb', line 84

def name
    "svn"
end

#prepare_for_fetchObject



207
208
209
210
# File 'lib/build-tool/vcs/svn.rb', line 207

def prepare_for_fetch
    # If our server has an associated ssh-key, add it to the ssh-agent.
    return check_for_sshkey( config.repository.sshkey )
end

#ready_for_fetchObject



139
140
141
142
143
144
145
# File 'lib/build-tool/vcs/svn.rb', line 139

def ready_for_fetch
    if not Svn.svn_available?
        logger.info( "#{config.module.name}: Calling `svn` failed!" )
        return false
    end
    return true
end

#rebase(verbose = false) ⇒ Object



262
263
264
265
# File 'lib/build-tool/vcs/svn.rb', line 262

def rebase( verbose = false )
    # Rebasing is not supported
    0
end

#remote_pathObject



212
213
214
# File 'lib/build-tool/vcs/svn.rb', line 212

def remote_path
    @config.remote_path
end

#remote_urlObject

convenience method



217
218
219
# File 'lib/build-tool/vcs/svn.rb', line 217

def remote_url
    "#{repository.url}/#{remote_path}"
end

#repositoryObject



222
223
224
# File 'lib/build-tool/vcs/svn.rb', line 222

def repository
    config.repository
end

#svn(command, wd = local_path, &block) ⇒ Object

Call svn with command



250
251
252
# File 'lib/build-tool/vcs/svn.rb', line 250

def svn( command, wd = local_path, &block )
    self.class.svn( command, wd, &block )
end

#urlObject

Return the currently active url

Raises:



200
201
202
203
204
205
# File 'lib/build-tool/vcs/svn.rb', line 200

def url
    return "http://example.com/my/example_repo" if $noop
    url = info( true )["URL"]
    raise SvnError, "Failed to determine url for #{remote_url}" if url.nil?
    return url
end