class Hiiro::Git::Branch

def self.current

def self.current
  name = `git branch --show-current 2>/dev/null`.strip
  return nil if name.empty?
  new(name: name, current: true)
end

def self.from_format_line(line, format: :short)

def self.from_format_line(line, format: :short)
  # Parses output from git branch --format
  new(name: line.strip)
end

def checkout

def checkout
  system('git', 'checkout', name)
end

def current?

def current?
  @current
end

def delete(force: false)

def delete(force: false)
  flag = force ? '-D' : '-d'
  system('git', 'branch', flag, name)
end

def exists?

def exists?
  system('git', 'show-ref', '--verify', '--quiet', ref)
end

def initialize(name:, ref: nil, upstream: nil, head: nil, current: false)

def initialize(name:, ref: nil, upstream: nil, head: nil, current: false)
  @name = name
  @ref = ref || "refs/heads/#{name}"
  @upstream = upstream
  @head = head
  @current = current
end

def local?

def local?
  ref.start_with?('refs/heads/')
end

def remote?

def remote?
  ref.start_with?('refs/remotes/')
end

def to_h

def to_h
  {
    name: name,
    ref: ref,
    upstream: upstream,
    head: head,
    current: current?,
  }.compact
end

def to_s

def to_s
  name
end