Class: Autobuild::Hg

Inherits:
Importer show all
Defined in:
lib/autobuild/import/hg.rb

Instance Attribute Summary collapse

Attributes inherited from Importer

#interactive, #options, #post_hooks, #repository_id, #source_id

Instance Method Summary collapse

Methods inherited from Importer

#add_post_hook, add_post_hook, #apply, cache_dirs, #call_patch, #currently_applied_patches, default_cache_dirs, default_cache_dirs=, each_post_hook, #each_post_hook, #execute_post_hooks, fallback, #fallback, #fingerprint, #import, #interactive?, #parse_patch_list, #patch, #patchdir, #patches, #patches_fingerprint, #patchlist, #perform_checkout, #perform_update, #retry_count, #retry_count=, #save_patch_state, set_cache_dirs, #supports_relocation?, #unapply, unset_cache_dirs, #update_retry_count, #vcs_fingerprint

Constructor Details

#initialize(repository, options = {}) ⇒ Hg

Creates an importer which tracks the given repository and (optionally) a branch.

This importer uses the ‘hg’ tool to perform the import. It defaults to ‘hg’ and can be configured by doing

Autobuild.programs['hg'] = 'my_git_tool'

Parameters:

  • repository (String)

    the repository URL

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :branch (String) — default: default

    the branch to track



18
19
20
21
22
23
24
25
26
27
# File 'lib/autobuild/import/hg.rb', line 18

def initialize(repository, options = {})
    hgopts, _common = Kernel.filter_options options,
                                            branch: 'default'
    sourceopts, common = Kernel.filter_options options,
                                               :repository_id, :source_id

    super(common)
    @branch = hgopts[:branch]
    relocate(repository, sourceopts)
end

Instance Attribute Details

#branchObject

The tip this importer is tracking



44
45
46
# File 'lib/autobuild/import/hg.rb', line 44

def branch
  @branch
end

#repositoryObject

The remote repository URL.



41
42
43
# File 'lib/autobuild/import/hg.rb', line 41

def repository
  @repository
end

Instance Method Details

#checkout(package, _options = Hash.new) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/autobuild/import/hg.rb', line 70

def checkout(package, _options = Hash.new)
    base_dir = File.expand_path('..', package.importdir)
    FileUtils.mkdir_p(base_dir) unless File.directory?(base_dir)

    package.run(:import, Autobuild.tool('hg'), 'clone',
                '-u', branch, repository, package.importdir, retry: true)
end

#relocate(repository, options = Hash.new) ⇒ Object

Changes the repository this importer is pointing to



30
31
32
33
34
35
36
37
38
# File 'lib/autobuild/import/hg.rb', line 30

def relocate(repository, options = Hash.new)
    @repository = repository
    @repository_id =
        options[:repository_id] ||
        "hg:#{@repository}"
    @source_id =
        options[:source_id] ||
        "#{repository_id} branch=#{branch}"
end

#update(package, options = Hash.new) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/autobuild/import/hg.rb', line 56

def update(package, options = Hash.new)
    if options[:only_local]
        package.warn "%s: the Mercurial importer does not support "\
            "local updates, skipping"
        return false
    end
    validate_importdir(package)
    package.run(:import, Autobuild.tool('hg'), 'pull',
                repository, retry: true, working_directory: package.importdir)
    package.run(:import, Autobuild.tool('hg'), 'update',
                branch, working_directory: package.importdir)
    true # no easy to know if package was updated, keep previous behavior
end

#validate_importdir(package) ⇒ Object

Raises ConfigException if the current directory is not a hg repository



48
49
50
51
52
53
54
# File 'lib/autobuild/import/hg.rb', line 48

def validate_importdir(package)
    unless File.directory?(File.join(package.importdir, '.hg'))
        raise ConfigException.new(package, 'import'),
              "while importing #{package.name}, "\
              "#{package.importdir} is not a hg repository"
    end
end