Class: BuildTool::VCS::Bazar

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

Overview

Implementation for the bzr version control system.

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

Constructor Details

#initialize(config) ⇒ Bazar

Returns a new instance of Bazar.



42
43
44
45
# File 'lib/build-tool/vcs/bazar.rb', line 42

def initialize( config )
    super( config )
    @vcs = nil
end

Class Method Details

.bzr_available?Boolean

Is the git executable available?

Returns:

  • (Boolean)


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

def bzr_available?()
    return @bzr_available unless @bzr_available.nil?
    %x( bzr --version 2>&1 )
    @bzr_available = $?.success?
    return @bzr_available
end

Instance Method Details

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

Execute command in directory wd and yield every line of output.



133
134
135
# File 'lib/build-tool/vcs/bazar.rb', line 133

def bzr( command, wd = local_path, &block )
    self.class.execute "bzr #{command}", wd, &block
end

#checkedout?Boolean

METHODS

Returns:

  • (Boolean)


62
63
64
65
66
67
68
# File 'lib/build-tool/vcs/bazar.rb', line 62

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

#cloneObject

Initialize the local repository



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/build-tool/vcs/bazar.rb', line 71

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

#dirty?Boolean

Returns:

  • (Boolean)


142
143
144
145
146
147
148
# File 'lib/build-tool/vcs/bazar.rb', line 142

def dirty?
    # Check if the index is dirty.
    if bzr( "diff" ) != 0
        return true
    end
    return false
end

#do_local_changes {|nil| ... } ⇒ Object

Yields:

  • (nil)


154
155
156
# File 'lib/build-tool/vcs/bazar.rb', line 154

def do_local_changes
    yield nil
end

#do_remote_changes {|nil| ... } ⇒ Object

Yields:

  • (nil)


150
151
152
# File 'lib/build-tool/vcs/bazar.rb', line 150

def do_remote_changes
    yield nil
end

#fetch(verbose = false) ⇒ Object

Fetch from repository

Initializes the local clone if it does not exist.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/build-tool/vcs/bazar.rb', line 109

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

#fetching_supported?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/build-tool/vcs/bazar.rb', line 54

def fetching_supported?
    false
end

#nameObject

ATTRIBUTES



50
51
52
# File 'lib/build-tool/vcs/bazar.rb', line 50

def name
    "bazar"
end

#ready_for_fetchObject



84
85
86
87
88
89
90
# File 'lib/build-tool/vcs/bazar.rb', line 84

def ready_for_fetch
    if not self.class.bzr_available?
        logger.error( "#{config.module.name}: Calling `bzr` failed!" )
        return false
    end
    return true
end

#ready_for_rebaseObject



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/build-tool/vcs/bazar.rb', line 92

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

#rebase(verbose = false) ⇒ Object



137
138
139
140
# File 'lib/build-tool/vcs/bazar.rb', line 137

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