Class: BuildTool::VCS::Mercurial
- Inherits:
-
Base
- Object
- Base
- BuildTool::VCS::Mercurial
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
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) ⇒ 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
|
Class Method Details
.hg_available? ⇒ Boolean
173
174
175
176
177
178
|
# File 'lib/build-tool/vcs/mercurial.rb', line 173
def hg_available?()
return @hg_available unless @hg_available.nil?
%x( hg --version 2>&1 )
@hg_available = $?.success?
return @hg_available
end
|
Instance Method Details
#checkedout? ⇒ 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
|
#clone ⇒ Object
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
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
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
|
#dirty? ⇒ Boolean
149
150
151
152
153
154
155
|
# File 'lib/build-tool/vcs/mercurial.rb', line 149
def dirty?
dirty = false
hg( "status -q" ) do
dirty = true
end
return dirty
end
|
#do_local_changes {|nil| ... } ⇒ Object
161
162
163
|
# File 'lib/build-tool/vcs/mercurial.rb', line 161
def do_local_changes
yield nil
end
|
#do_remote_changes {|nil| ... } ⇒ Object
157
158
159
|
# File 'lib/build-tool/vcs/mercurial.rb', line 157
def do_remote_changes
yield nil
end
|
#fetch(verbose = false) ⇒ Object
Fetch from repository
Initializes the local clone if it does not exist.
121
122
123
124
125
126
127
128
129
|
# File 'lib/build-tool/vcs/mercurial.rb', line 121
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
62
63
64
|
# File 'lib/build-tool/vcs/mercurial.rb', line 62
def fetching_supported?
true
end
|
#hg(command, wd = local_path, &block) ⇒ Object
131
132
133
134
135
136
137
|
# File 'lib/build-tool/vcs/mercurial.rb', line 131
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
|
#name ⇒ Object
58
59
60
|
# File 'lib/build-tool/vcs/mercurial.rb', line 58
def name
"mercurial"
end
|
#ready_for_fetch ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/build-tool/vcs/mercurial.rb', line 95
def ready_for_fetch
if not self.class.hg_available?
logger.error( "#{config.module.name}: Calling `hg` failed!" )
return false
end
return true
end
|
#ready_for_rebase ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/build-tool/vcs/mercurial.rb', line 103
def ready_for_rebase
if checkedout?
if dirty?
logger.info( "#{config.module.name}: Local changes will prevent the update." )
hg( "status -q" ) do |line|
logger.info line.chomp
end
return false
end
end
return true
end
|
#rebase(verbose = false) ⇒ Object
139
140
141
142
143
144
145
146
147
|
# File 'lib/build-tool/vcs/mercurial.rb', line 139
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
|