Class: BuildTool::VCS::Mercurial

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

Overview

Implementation for the hg version control system.

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#apply_patches_after_rebase?, #check_for_sshkey, #configure, #gc, #local_path, #local_path_exist?, #patches_supported?, #prepare_for_fetch, #prepare_for_rebase, #ready_for_fetch, #ready_for_rebase, #recipe

Constructor Details

#initialize(config) ⇒ Mercurial

Returns a new instance of Mercurial.



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

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

Instance Method Details

#checkedout?Boolean

METHODS

Returns:

  • (Boolean)


70
71
72
73
74
75
76
# File 'lib/build-tool/vcs/mercurial.rb', line 70

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

#cloneObject

Initialize the local repository



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/build-tool/vcs/mercurial.rb', line 79

def clone
    # Check if path exists
    if local_path_exist?
        raise MercurialError, "Failed to create repository at '#{local_path}': Path exists"
    end
    FileUtils.mkdir_p Pathname.new( local_path ).dirname if ! $noop

    # Initialize the repository
    if hg( "clone #{config.url} #{local_path}", Pathname.new( local_path ).dirname) != 0
        raise MercurialError, "Error while initializing the repo `hg init #{local_path}'`: #{$?}"
    end

    fetch()
    rebase()
end

#fetch(verbose = false) ⇒ Object

Fetch from repository

Initializes the local clone if it does not exist.



98
99
100
101
102
103
104
105
106
# File 'lib/build-tool/vcs/mercurial.rb', line 98

def fetch( verbose = false )
    if !checkedout? and !$noop
        clone
    end
    cmd = "pull #{config.url}"
    if ( rc = hg( cmd ) ) != 0
        raise MercurialError, "Error while fetching: #{rc}"
    end
end

#fetching_supported?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/build-tool/vcs/mercurial.rb', line 62

def fetching_supported?
    true
end

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



108
109
110
111
112
113
114
# File 'lib/build-tool/vcs/mercurial.rb', line 108

def hg( command, wd = local_path, &block )
    rc = self.class.execute "hg #{command}", wd, &block
    if rc != 0
        raise MercurialError, "hg #{command || "" } failed with error code #{rc}";
    end
    rc
end

#nameObject

ATTRIBUTES



58
59
60
# File 'lib/build-tool/vcs/mercurial.rb', line 58

def name
    "mercurial"
end

#rebase(verbose = false) ⇒ Object



116
117
118
119
120
121
122
123
124
125
# File 'lib/build-tool/vcs/mercurial.rb', line 116

def rebase( verbose = false )

    if verbose
        logger.info( 'Verbose rebase not yet implemented for mercurial.' )
    end

    if 0 != ( hg "update #{config.track}" )
        raise MercurialSvnError, "Error while rebasing the repo with `hg update: #{$?}"
    end
end