Class: Rfix::Branch::Main

Inherits:
Name
  • Object
show all
Defined in:
lib/rfix/branch/main.rb

Defined Under Namespace

Classes: NoMainBranchSetError

Constant Summary collapse

KEY =
"rfix.main.branch"

Class Method Summary collapse

Methods inherited from Name

#resolve

Methods inherited from Base

#resolve, #to_s

Class Method Details

.call(repository: Rugged::Repository.discover) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rfix/branch/main.rb', line 14

def self.call(repository: Rugged::Repository.discover)
  unless (name = repository.config[KEY])
    raise NoMainBranchSetError
  end

  super(repository: repository, name: name)
rescue NoMainBranchSetError
  if repository.head_detached?
    raise Error, "HEAD is detached"
  end

  repository.branches[repository.head.name].then do |branch|
    repository.config[KEY] = branch.name
  end

  retry
end