Class: BuildTool::VCS::GitSvn

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

Overview

Implementation for the git-svn version control system.

Defined Under Namespace

Classes: GitSvnError

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

Constructor Details

#initialize(*args) ⇒ GitSvn

Returns a new instance of GitSvn.



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

def initialize( *args )
    super( *args )
end

Class Method Details

.git_svn_availableObject

Is the git executable available?



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

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

Instance Method Details

#[](var) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
# File 'lib/build-tool/vcs/git-svn.rb', line 241

def[]( var )
    case var

    when 'external'
        return @externals

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

#[]=(var, val) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/build-tool/vcs/git-svn.rb', line 253

def[]=( var, val )
    case var

    when 'external'
        tmp = val.split( /#/ )
        @externals[tmp[0]] = tmp[1]

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

#check_configObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/build-tool/vcs/git-svn.rb', line 129

def check_config
    return if @already_checked_config
    git.check_config
    if checkedout?
        # Check that the remotes are the same as configured.
        gitconfig = Grit::RepoConfig.new(git.repo)
        svnurlrec = Pathname.new( config.repository.url ).join( Pathname.new(remote_path).cleanpath )
        svnurlcur = Pathname.new( gitconfig["svn-remote.svn.url"] )
        if svnurlcur.nil?
            if git.git( "svn init #{svnurl}" ) != 0
                raise GitError, "Error while initializing the repo `git svn init #{svnurlrec}`"
            end
        elsif svnurlcur != svnurlrec
            logger.info "repo: Setting remote.origin.url to #{svnurlrec}"
            gitconfig["svn-remote.svn.url"] = svnurlrec
        end
    end
end

#checkedout?Boolean

METHOD

Returns:

  • (Boolean)


105
106
107
# File 'lib/build-tool/vcs/git-svn.rb', line 105

def checkedout?
    git.checkedout?
end

#clone(verbose = false) ⇒ Object



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

def clone( verbose = false )
    if local_path_exist?
        raise GitSvnError, "Failed to create repository at '#{local_path}': Path exists"
    end
    # Create the directory
    FileUtils.mkdir_p( local_path ) if !$noop
    # Init the repository
    if 0 != ( git_svn "init #{config.repository.url}/#{remote_path}" )
        raise GitSvnError, "Error while initializing the repo `git svn init '#{config.repository}/#{remote_path}'`: #{$?}"
    end

    check_config

    fetch(false, "HEAD")
end

#configureObject



125
126
127
# File 'lib/build-tool/vcs/git-svn.rb', line 125

def configure
    git.configure
end

#dirty?Boolean

Returns:

  • (Boolean)


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

def dirty?
    return git.dirty?
end

#do_local_changes(&block) ⇒ Object



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

def do_local_changes( &block )
    return git.do_local_changes( &block )
end

#do_remote_changes(&block) ⇒ Object



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

def do_remote_changes( &block )
    return git.do_remote_changes( &block )
end

#fetch(verbose = false, revision = nil) ⇒ Object

Fetch from repository

Initializes the local clone if it does not exist.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/build-tool/vcs/git-svn.rb', line 151

def fetch( verbose = false, revision = nil )
    if !checkedout? and !$noop # Beware of looping
        clone( verbose )
    else
        # clone() calls those methods.
        check_config
    end

    if revision
        cmd = "fetch -r#{revision}"
    else
        cmd = "fetch"
    end

    if ( rc = git_svn( cmd ) ) != 0
        raise GitSvnError, "Error while fetching: #{rc}"
    end

    update_externals
end

#fetching_supported?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/build-tool/vcs/git-svn.rb', line 97

def fetching_supported?
    true
end

#gcObject



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

def gc
    git.git( "gc" )
end

#gitObject



176
177
178
179
180
181
# File 'lib/build-tool/vcs/git-svn.rb', line 176

def git
    if @git.nil?
        @git = Git.new( config )
    end
    @git
end

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

Call git-svn with command



184
185
186
# File 'lib/build-tool/vcs/git-svn.rb', line 184

def git_svn( command, wd = local_path, &block )
    self.class.execute( "git svn " + command, wd, &block )
end

#nameObject

ATTRIBUTES



93
94
95
# File 'lib/build-tool/vcs/git-svn.rb', line 93

def name
    "git-svn"
end

#prepare_for_fetchObject



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

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



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

def ready_for_fetch
    if not GitSvn.git_svn_available
        logger.info( "#{config.module.name}: Calling `git svn` failed!" )
    end
    return GitSvn.git_svn_available && git.ready_for_fetch
end

#ready_for_rebaseObject



227
228
229
# File 'lib/build-tool/vcs/git-svn.rb', line 227

def ready_for_rebase
    git.ready_for_rebase
end

#rebase(verbose = false) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/build-tool/vcs/git-svn.rb', line 193

def rebase( verbose = false )
    check_config
    remote_branch = "#{config.track_branch}"

    if verbose
        git.git('log --first-parent --pretty=oneline HEAD..%s' % remote_branch ) do |line|
            logger.info( line )
        end
    end

    if 0 != ( git.git "rebase #{remote_branch}" )
        raise GitSvnError, "Error while rebasing the repo with `#{remote_branch}': #{$?}"
    end
end

#remote_pathObject



231
232
233
# File 'lib/build-tool/vcs/git-svn.rb', line 231

def remote_path
    @config.remote_path
end

#update_externalsObject



235
236
237
238
239
# File 'lib/build-tool/vcs/git-svn.rb', line 235

def update_externals
    config.merged_externals.each do |local, remote|
        VCS::Svn::svn( "checkout #{remote}@HEAD #{local}", wd = local_path  )
    end
end