Class: Mercurial::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/mercurial-ruby/branch.rb

Overview

The class represents Mercurial branch. Obtained by running an hg branches command.

The class represents Branch object itself, BranchFactory is responsible for assembling instances of Branch. For the list of all possible branch-related operations check BranchFactory.

For general information on Mercurial branches:

mercurial.selenic.com/wiki/Branch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, name, options = {}) ⇒ Branch

Returns a new instance of Branch.



28
29
30
31
32
33
# File 'lib/mercurial-ruby/branch.rb', line 28

def initialize(repository, name, options={})
  @repository    = repository
  @name          = name.strip
  @status        = ['closed', 'inactive'].include?(options[:status]) ? options[:status] : 'active'
  @hash_id       = options[:commit]
end

Instance Attribute Details

#hash_idObject (readonly)

ID of a commit associated with the branch. 40-chars long SHA1 hash.



26
27
28
# File 'lib/mercurial-ruby/branch.rb', line 26

def hash_id
  @hash_id
end

#nameObject (readonly)

Name of the branch.



20
21
22
# File 'lib/mercurial-ruby/branch.rb', line 20

def name
  @name
end

#repositoryObject (readonly)

Instance of Repository.



17
18
19
# File 'lib/mercurial-ruby/branch.rb', line 17

def repository
  @repository
end

#statusObject (readonly)

State of the branch: closed or active.



23
24
25
# File 'lib/mercurial-ruby/branch.rb', line 23

def status
  @status
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/mercurial-ruby/branch.rb', line 39

def active?
  status == 'active'
end

#closed?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/mercurial-ruby/branch.rb', line 47

def closed?
  status == 'closed'
end

#commitObject



35
36
37
# File 'lib/mercurial-ruby/branch.rb', line 35

def commit
  repository.commits.by_hash_id(hash_id)
end

#inactive?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/mercurial-ruby/branch.rb', line 43

def inactive?
  status == 'inactive'
end