Class: Gitlab::Git::Branch

Inherits:
Ref
  • Object
show all
Defined in:
lib/gitlab/git/branch.rb

Constant Summary collapse

STALE_BRANCH_THRESHOLD =
3.months

Constants included from EncodingHelper

EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD

Instance Attribute Summary

Attributes inherited from Ref

#dereferenced_target, #name, #target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ref

extract_branch_name

Methods included from RuggedImpl::Ref

dereference_object

Methods included from EncodingHelper

#binary_io, #detect_binary?, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8

Constructor Details

#initialize(repository, name, target, target_commit) ⇒ Branch

Returns a new instance of Branch.


16
17
18
# File 'lib/gitlab/git/branch.rb', line 16

def initialize(repository, name, target, target_commit)
  super(repository, name, target, target_commit)
end

Class Method Details

.find(repo, branch_name) ⇒ Object


8
9
10
11
12
13
14
# File 'lib/gitlab/git/branch.rb', line 8

def self.find(repo, branch_name)
  if branch_name.is_a?(Gitlab::Git::Branch)
    branch_name
  else
    repo.find_branch(branch_name)
  end
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/gitlab/git/branch.rb', line 20

def active?
  self.dereferenced_target.committed_date >= STALE_BRANCH_THRESHOLD.ago
end

#stale?Boolean

Returns:

  • (Boolean)

24
25
26
# File 'lib/gitlab/git/branch.rb', line 24

def stale?
  !active?
end

#stateObject


28
29
30
# File 'lib/gitlab/git/branch.rb', line 28

def state
  active? ? :active : :stale
end