Class: Circus::Repos::Mercurial

Inherits:
Object
  • Object
show all
Defined in:
lib/circus/repos/mercurial.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Mercurial

Returns a new instance of Mercurial.



20
21
22
# File 'lib/circus/repos/mercurial.rb', line 20

def initialize(dir)
  @dir = dir
end

Class Method Details

.accepts_dir?(dir_name) ⇒ Boolean

Checks if the current directory (or a parent) are Hg working trees. Uses a call to hg status to test (which will fail with a non-zero exit if the tree isn’t a valid git tree)

Returns:

  • (Boolean)


7
8
9
10
# File 'lib/circus/repos/mercurial.rb', line 7

def self.accepts_dir? dir_name
  `hg st >/dev/null 2>/dev/null`
  $? == 0
end

.accepts_id?(key) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/circus/repos/mercurial.rb', line 12

def self.accepts_id?(key)
  key == 'hg' || key == 'mercurial'
end

.type_idObject



16
17
18
# File 'lib/circus/repos/mercurial.rb', line 16

def self.type_id
  'hg'
end

Instance Method Details

#current_revisionObject



31
32
33
# File 'lib/circus/repos/mercurial.rb', line 31

def current_revision
  `(cd #{@dir}; hg id -i)`[0..11]
end

#repo_urlObject



24
25
26
27
28
29
# File 'lib/circus/repos/mercurial.rb', line 24

def repo_url
  first_path = `(cd #{@dir}; hg paths)`.lines.first
  return nil unless first_path
  
  first_path.split('=', 2)[1].strip
end

#write_patch(patch_fn) ⇒ Object



35
36
37
# File 'lib/circus/repos/mercurial.rb', line 35

def write_patch(patch_fn)
  `(cd #{@dir}; hg diff >#{patch_fn})`.strip
end