# -*- coding: UTF-8 -*- require 'mj/mixins/inherited_attributes' require 'build-tool/vcs/base' require 'build-tool/errors' module BuildTool; module VCS class BazarError < BuildTool::Error; end class BazarConfiguration < BaseConfiguration include MJ::Mixins::InheritedAttributes def name "bazar" end def initialize super @url = nil end def vcs( mod ) raise StandardError if @module and ! mod.equal?( @module ) @module = mod Bazar.new( self ) end inherited_attr_accessor :url def copy_configuration( other ) super end end # # Implementation for the bzr version control system. # class Bazar < Base def initialize( config ) super( config ) @vcs = nil end # ### ATTRIBUTES # def name "bazar" end def fetching_supported? false end # ### METHODS # def checkedout? return false if !local_path_exist? if !Pathname.new( local_path ).join( ".bzr" ).exist? raise Base::VcsError, "Checkout path #{local_path} is not a bazar repo!" end return true end # Initialize the local repository def clone # Check if path exists if local_path_exist? raise BazarError, "Failed to create repository at '#{local_path}': Path exists" end FileUtils.mkdir_p Pathname.new( local_path ).dirname if ! $noop # Initialize the repository if bzr( "branch #{config.url} #{local_path}", Pathname.new( local_path ).dirname) != 0 raise BazarError, "Error while initializing the repo `bzr branch #{config.url} #{local_path}'`: #{$?}" end end def ready_for_fetch if not self.class.bzr_available? logger.error( "#{config.module.name}: Calling `bzr` failed!" ) return false end return true end def ready_for_rebase if checkedout? # Check if the index is dirty. if dirty? logger.info( "#{config.module.name}: Local changes will prevent the update." ) bzr( "status --short --versioned" ) do |line| logger.info line.chomp end return false end end return true end # Fetch from +repository+ # # Initializes the local clone if it does not exist. def fetch( verbose = false ) if !checkedout? and !$noop clone end if verbose cmd = "update -v" else cmd = "update" end rc = bzr( cmd ) do |line| if verbose logger.info( line ) end end if rc != 0 raise BazarError, "Error while update: #{rc}" end end # Execute +command+ in directory +wd+ and yield every line of output. def bzr( command, wd = local_path, &block ) self.class.execute "bzr #{command}", wd, &block end def rebase( verbose = false ) # Rebasing is not supported 0 end def dirty? # Check if the index is dirty. if bzr( "diff" ) != 0 return true end return false end def do_remote_changes yield nil end def do_local_changes yield nil end # ### CLASS METHODS # class << self @bzr_available = nil # Is the git executable available? def bzr_available?() return @bzr_available unless @bzr_available.nil? %x( bzr --version 2>&1 ) @bzr_available = $?.success? return @bzr_available end end end # class Bazar end; end # module BuildTool::VCS