Module: RuVim::Git::Branch

Defined in:
lib/ruvim/git/branch.rb

Defined Under Namespace

Modules: HandlerMethods

Class Method Summary collapse

Class Method Details

.parse_branch_name(line) ⇒ Object

Parse branch name from a branch list line. Returns branch name or nil.



30
31
32
33
34
35
36
37
38
39
# File 'lib/ruvim/git/branch.rb', line 30

def parse_branch_name(line)
  stripped = line.to_s.strip
  return nil if stripped.empty?

  # Remove leading "* " marker for current branch
  name = stripped.sub(/\A\*\s*/, "")
  # Branch name is everything before the first tab
  name = name.split("\t", 2).first
  name&.strip
end

.run(file_path) ⇒ Object

Run git branch listing sorted by most recent commit. Returns [lines, root, error_message].



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruvim/git/branch.rb', line 12

def run(file_path)
  root, err = Git.repo_root(file_path)
  return [nil, nil, err] unless root

  out, err, status = Open3.capture3(
    "git", "branch", "-a",
    "--sort=-committerdate",
    "--format=%(if)%(HEAD)%(then)* %(else)  %(end)%(refname:short)\t%(committerdate:short)\t%(subject)",
    chdir: root
  )
  unless status.success?
    return [nil, nil, err.strip]
  end
  [out.lines(chomp: true), root, nil]
end