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, #initialize, #local_path, #local_path_exist?, #patches_supported?, #prepare_for_rebase, #ready_for_rebase, #recipe

Constructor Details

This class inherits a constructor from BuildTool::VCS::Base

Class Method Details

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



185
186
187
188
189
190
191
# File 'lib/build-tool/vcs/svn.rb', line 185

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)


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

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



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

def[]( var )
    case var

    when nil

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

#[]=(var, val) ⇒ Object



209
210
211
212
213
214
215
216
217
218
# File 'lib/build-tool/vcs/svn.rb', line 209

def[]=( var, val )
    case var

    when nil

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

#checkedout?Boolean

METHODS

Returns:

  • (Boolean)


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

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



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/build-tool/vcs/svn.rb', line 105

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 #{repository.url}/#{remote_path} #{local_path}", local_path.dirname
        config.only.each do |elem|
            svn "update --depth=infinity #{elem}", local_path
        end
    else
        svn "checkout --depth=infinity #{repository.url}/#{remote_path} #{local_path}", local_path.dirname
    end
    return true
end

#fetch(verbose = false) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/build-tool/vcs/svn.rb', line 134

def fetch( verbose = false )

    if !checkedout?
       return clone
    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)


86
87
88
# File 'lib/build-tool/vcs/svn.rb', line 86

def fetching_supported?
    false
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:



153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/build-tool/vcs/svn.rb', line 153

def last_changed_rev
    info = Hash.new
    svn( "info #{repository.url}/#{remote_path}", nil ) {
        |line|
        key, value = line.chomp.split( ':', 2 )
        info[key] = value
    }
    return 777777 if $noop
    version = info["Last Changed Rev"];
    raise SvnError, "Failed to determine revision for #{repository.url}/#{remote_path}" if version.nil?
    return version
end

#nameObject

ATTRIBUTES



82
83
84
# File 'lib/build-tool/vcs/svn.rb', line 82

def name
    "svn"
end

#prepare_for_fetchObject



166
167
168
169
# File 'lib/build-tool/vcs/svn.rb', line 166

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



126
127
128
129
130
131
132
# File 'lib/build-tool/vcs/svn.rb', line 126

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



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

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

#remote_pathObject



171
172
173
# File 'lib/build-tool/vcs/svn.rb', line 171

def remote_path
    @config.remote_path
end

#repositoryObject



175
176
177
# File 'lib/build-tool/vcs/svn.rb', line 175

def repository
    config.repository
end

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

Call svn with command



181
182
183
# File 'lib/build-tool/vcs/svn.rb', line 181

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