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_path, #local_path_exist?, #patches_supported?, #prepare_for_rebase, #recipe

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



214
215
216
217
218
219
220
221
222
223
224
# File 'lib/build-tool/vcs/git-svn.rb', line 214

def[]( var )
    case var

    when 'external'
        return @externals

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

#[]=(var, val) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/build-tool/vcs/git-svn.rb', line 226

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

#checkedout?Boolean

METHOD

Returns:

  • (Boolean)


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

def checkedout?
    return false if !local_path_exist?
    if !Pathname.new( local_path ).join( ".git" ).exist?
        raise Base::VcsError, "Checkout path #{local_path} is not a git repo!"
    end
    return true
end

#cloneObject



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

def clone
    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

    fetch( revision: "HEAD" )
end

#configureObject



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

def configure
    git.configure
end

#fetch(verbose = false, options = {}) ⇒ Object

Fetch from repository

Initializes the local clone if it does not exist.



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

def fetch( verbose = false, options = {} )
    revision = options[:revision] || nil

    if !checkedout? and !$noop # Beware of looping
        clone
    else
        # clone() calls those methods.
        git.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



157
158
159
# File 'lib/build-tool/vcs/git-svn.rb', line 157

def gc
    git.git( "gc" )
end

#gitObject



161
162
163
164
165
166
# File 'lib/build-tool/vcs/git-svn.rb', line 161

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



169
170
171
# File 'lib/build-tool/vcs/git-svn.rb', line 169

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



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

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



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

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



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

def ready_for_rebase
    git.ready_for_rebase
end

#rebase(verbose = false) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/build-tool/vcs/git-svn.rb', line 178

def rebase( verbose = false )
    git.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



204
205
206
# File 'lib/build-tool/vcs/git-svn.rb', line 204

def remote_path
    @config.remote_path
end

#update_externalsObject



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

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