# encoding: utf-8 # require 'kde-build/vcs/base' module BuildTool; module VCS class GitSvnConfiguration < BaseConfiguration option( "externals", "List of externals to fetch" ). on_write { |val| if val.instance_of?( Array ) a = val.inject([]) { |arr, v| v.each_pair { |val, key| arr << val << key } arr } val = Hash[*a] else throw :todo raise Exception, "FIXME" end val } def initialize super self.name = "git-svn" end end # Git-SVN Error class GitSvnError < BuildToolError end # Implementation for the git-svn version control system # (http://git-scm.org) class GitSVN < Base def initialize( repository, path ) super repository, path end # Check if the local checkout exists. # # calls VCS::Base::checkedout? and checks if there is a '.git' # directory at +path+ def checkedout? return false if !super if !File.exists? "#{path}/.git" $log.debug("Checkout path #{path} is not a git repo") return false end return true end def self.config GitSvnConfiguration end # Execute a git command in the context of the local git repository def git_svn( command, wd = path ) self.class.execute "git svn #{command}", wd end # Fetch from +repository+ # # Initializes the local clone if it does not exist. def fetch( revision = nil ) if !checkedout? and !$noop init 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 # Initialize the local repository def init( revision = nil ) # Check if path exists if File.exists? path raise GitSvnError, "Failed to create repository at '#{path}': Path exists" end # Make sure we have a revision if !revision revision = SVN.new( repository ).last_changed_rev end if !revision or revision == 0 raise GitSvnError, "Failed to retrieve revision to clone from '#{repository}'" end # Create the directory FileUtils.mkdir_p( path ) if !$noop # Init the repository if !git_svn "init #{repository}" raise GitSvnError, "Error while initializing the repo `git svn init '#{repository}'`: #{$?}" end fetch( revision ) update_externals end def info super puts " Externals: #{configuration.externals.inspect}" if configuration.externals end # Returns Git-SVN def name "Git-SVN" end def rebase return git_svn "rebase -l master" end def update_externals return if !configuration.externals configuration.externals.each do |local, remote| SVN::svn( "checkout #{remote}@HEAD #{local}", wd = path ) end end end end; end